1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
|
<?php
function helpLink($link){
global $gfx_icn_path_help;
if(isset($gfx_icn_path_help)){
$helpimg_src = $gfx_icn_path_help;
}else{
$helpimg_src = "gfx/help.png";
}
$out = "<a target=\"_blank\" href=\"http://dtcsupport.gplhost.com/$link\"><img border=\"0\" src=\"$helpimg_src\"></a>";
return $out;
}
function submitButtonStart(){
return "<div class=\"input_btn_container\" onMouseOver=\"this.className='input_btn_container-hover';\"
onMouseOut=\"this.className='input_btn_container';\">
<div class=\"input_btn_left\"></div>
<div class=\"input_btn_mid\"><input class=\"input_btn\" type=\"submit\" value=\"";
}
function submitButtonEnd(){
return "\"></div>
<div class=\"input_btn_right\"></div></div>";
}
function dtcFormTableAttrs(){
$out = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
return $out;
}
function dtcFormLineDraw($text,$control,$alternate_color=1,$help_text=""){
global $gfx_form_entry_label_background;
global $gfx_form_entry_label_control_background;
global $gfx_form_entry_label_alt_background;
global $gfx_form_entry_label_alt_control_background;
if($alternate_color == 1){
if(isset($gfx_form_entry_label_background)){
$bgcolor = $gfx_form_entry_label_background;
}else{
$bgcolor = " bgcolor=\"#AAAAFF\" class=\"box_formtable_libelle\" ";
}
if(isset($gfx_form_entry_label_control_background)){
$incolor = $gfx_form_entry_label_control_background;
}else{
$incolor = " bgcolor=\"#FFFFFF\" class=\"box_formtable_inputz\" ";
}
}else{
if(isset($gfx_form_entry_label_alt_background)){
$bgcolor = $gfx_form_entry_label_alt_background;
}else{
$bgcolor = " ";
}
if(isset($gfx_form_entry_label_alt_control_background)){
$incolor = $gfx_form_entry_label_alt_control_background;
}else{
$incolor = " ";
}
}
if($help_text != ""){
$jshelp = " onmouseover=\"Tip('". addslashes($help_text) ."',STICKY,true,CLICKCLOSE,true,FADEIN,600)\" ";
}else{
$jshelp = "";
}
$out = "
<tr>
<th $bgcolor $jshelp style=\"text-align:right;white-space:nowrap;\">$text</th>
<td $bgcolor>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\" height=\"100%\">
<tr>
<td $incolor style=\"white-space:nowrap;vertical-valign:bottom;\" height=\"100%\">$control</td>
</tr>
</table>
</td>
</tr>";
return $out;
}
function dtcApplyButton(){
global $gfx_icn_path_ok;
if(isset($gfx_icn_path_ok)){
$apply = "<div class=\"btn_p_container\" onMouseOver=\"this.className='btn_p_container-hover';\" onMouseOut=\"this.className='btn_p_container';\">
<input type=\"image\" src=\"".$gfx_icn_path_ok."\"></div>";
// <img src=\"".$gfx_icn_path_ok."\"></div>";
}else{
$apply = "<input type=\"image\" src=\"gfx/stock_apply_20.png\">";
}
return $apply;
}
function dtcDeleteButton(){
global $gfx_icn_path_delete;
global $conf_use_javascript;
if(isset($gfx_icn_path_delete)){
if ( $conf_use_javascript == "yes" ) {
$click_confirm = " onClick=\"return confirm('Are you sure to delete?')\"";
} else { $click_confirm = NULL; }
$delete = "<div class=\"btn_p_container\" onMouseOver=\"this.className='btn_p_container-hover';\" onMouseOut=\"this.className='btn_p_container';\"><input type=\"image\" src=\"".$gfx_icn_path_delete."\"".$click_confirm."></div>";
}else{
$delete = "<input type=\"image\" src=\"gfx/stock_trash_24.png\">";
}
return $delete;
}
function dtcAddButton(){
global $gfx_icn_path_add;
if(isset($gfx_icn_path_add)){
$delete = "<div class=\"btn_p_container\" onMouseOver=\"this.className='btn_p_container-hover';\" onMouseOut=\"this.className='btn_p_container';\"><input type=\"image\" src=\"".$gfx_icn_path_add."\"></div>";
}else{
$delete = "<input type=\"image\" src=\"gfx/stock_add_24.png\">";
}
return $delete;
}
function dtcEditButton(){
global $gfx_icn_path_editme;
if(isset($gfx_icn_path_editme)){
$delete = "<div class=\"btn_p_container\" onMouseOver=\"this.className='btn_p_container-hover';\" onMouseOut=\"this.className='btn_p_container';\"><input type=\"image\" src=\"".$gfx_icn_path_editme."\"></div>";
}else{
$delete = "<input type=\"image\" src=\"gfx/stock_add_24.png\">";
}
return $delete;
}
function dtcArchiveButton(){
global $gfx_icn_path_compress;
if(isset($gfx_icn_path_compress)){
$delete = "<div class=\"btn_p_container\" onMouseOver=\"this.className='btn_p_container-hover';\" onMouseOut=\"this.className='btn_p_container';\"><input type=\"image\" src=\"".$gfx_icn_path_compress."\"></div>";
}else{
$delete = "<input type=\"image\" src=\"gfx/stock_add_24.png\">";
}
return $delete;
}
function dtcFromOkDraw($delete_form=""){
$out = "<tr><td> </td><td>".dtcApplyButton()."$delete_form</td></tr>";
return $out;
}
// Properties for this grid_display stuff is an object of that kind:
// array(
// table_name => "$pro_mysql_blabla_table" -> Name of the SQL table to edit
// title => "The editor for this" -> Name of the title to display
// action => "domain_prop_editor" -> name of the sql function forwarded in the form for doing the submit job (anything is ok, but don't have twice the same stuff)
// forward => array(var1,var2...) -> names of the variables to forward
// [skip_deletion] => "yes" -> Do not display the deletion option
// [skip_creation] => "yes" -> Do not display the new item line
// [update_check_callback] => Callback to accept or deny the update of a record.
// [insert_check_callback] => callback to accept or deny the insert of a record
// [where_condition] => "blabla='hop' AND titi='toto'" -> Condition of the display of the table
// [order_by] => "fldname_1" -> Condition pour le order by
// cols => array(
// "field0" => array( -> Note this will be use as a WHERE blabla='titi' for the UPDATE statement
// type => "id",
// display => yes|no,
// legend => "Text to display"),
// "field1" => array(
// type => "text",
// legend => "Text to display"),
// "field2" => array(
// type => "radio", -> works the same way if "popup"
// values => array("red","green","blue"),
// legend => "Text to display"),
// [display_replace] => array("mega-cool) -> Used for popup only. List of display text for each of the "values". This list can be smaller than the "values" list, then it wont be replaced.
// "field3" => array(
// type => "checkbox",
// values => array("yes","no"), -> First value means checked!
// "field4" => array(
// type => "textarea",
// legend => "Text to display"),
// [cols] => 40 -> Number of cols
// [rows] => 9 -> Number of rows
// "field5" => array(
// type => "hyperlink"
// text => "text to the link"
// "field6" => array(
// type => "info" -> used to only display a field that can not be edited
// legend => "Text to display"
// ... -> names of the sql feilds to edit
// table_name => "name"
// Note: this function has no field validation checks, do not use for the user panel, only for the root one !!!
function dtcDatagrid($dsc){
global $adm_pass;
global $txt_action;
global $lang;
global $action_error_txt;
global $gfx_form_entry_label_background;
global $conf_enforce_adm_encryption;
global $conf_post_or_get;
global $idn;
$nbr_forwards = sizeof($dsc["forward"]);
$keys_fw = array_keys($dsc["forward"]);
// Process the "forward" parameter of the grid widget, so that $rub and $sousrub and so on are forwarded
$fw = "";
$fw_link = "?";
for($i=0;$i<$nbr_forwards;$i++){
if($dsc["forward"][$i] == "adm_pass"){
$fw .= "<input type=\"hidden\" name=\"".$dsc["forward"][$i]."\" value=\"".$adm_pass."\">";
}else{
$fw .= "<input type=\"hidden\" name=\"".$dsc["forward"][$i]."\" value=\"".$_REQUEST[ $dsc["forward"][$i] ]."\">";
}
if($i != 0){
$fw_link .= "&";
}
if($dsc["forward"][$i] == "adm_pass"){
$fw_link .= $dsc["forward"][$i]."=$adm_pass";
}else{
$fw_link .= $dsc["forward"][$i]."=".$_REQUEST[ $dsc["forward"][$i] ];
}
}
// Get a list of fields in sql and build a "field1, field2" string
$nbr_fld = sizeof($dsc["cols"]);
$flds = "";
$keys = array_keys($dsc["cols"]);
for($i=0;$i<$nbr_fld;$i++){
if($i != 0){
$flds .= ", ";
}
$flds .= $keys[$i];
}
// Start of performing actions (new, update, delete)
$action_error_txt = "";
if(isset($_REQUEST["action"])){
$added_one = "no";
switch($_REQUEST["action"]){
case $dsc["action"]."_new":
$vals = "";
$qflds = "";
for($i=0;$i<$nbr_fld;$i++){
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "text":
case "radio":
case "popup":
case "textarea":
case "password":
if($added_one == "yes"){
$vals .= ", ";
$qflds .= ", ";
}
$qflds .= $keys[$i];
if(isset($dsc["cols"][ $keys[$i] ]["happen_domain"])){
$happen = $dsc["cols"][ $keys[$i] ]["happen_domain"];
}else{
$happen = "";
}
if( $dsc["cols"][ $keys[$i] ]["type"] == "password" && isset($dsc["cols"][ $keys[$i] ]["encrypt"]) && $dsc["cols"][ $keys[$i] ]["encrypt"] == "yes" && $conf_enforce_adm_encryption == "yes"){
$vals .= "SHA1('".mysql_real_escape_string($_REQUEST[ $keys[$i] ]).$happen."')";
}else{
$vals .= "'".mysql_real_escape_string($_REQUEST[ $keys[$i] ]).$happen."'";
}
$added_one = "yes";
break;
case "checkbox":
if($added_one == "yes"){
$vals .= ", ";
$qflds .= ", ";
}
if( isset($_REQUEST[ $keys[$i] ]) ){
$index_val = 0;
}else{
$index_val = 1;
}
$qflds .= $keys[$i];
$vals .= "'".$dsc["cols"][ $keys[$i] ]["values"][$index_val]."'";
$added_one = "yes";
break;
case "custom_fld":
//
break;
default:
break;
}
}
// Make sure we have the where_condition field filled with the correct value
if( isset($dsc["where_condition"]) ){
$exploded = explode("=",$dsc["where_condition"]);
$qflds .= ", ".$exploded[0];
$vals .= ", ".$exploded[1];
}
if( isset($dsc["insert_check_callback"]) ){
if ( $dsc["insert_check_callback"]() ){
$q = "INSERT INTO ".$dsc["table_name"]." ($qflds) VALUES($vals);";
}else{
$q = "";
}
}else{
$q = "INSERT INTO ".$dsc["table_name"]." ($qflds) VALUES($vals);";
}
break;
case $dsc["action"]."_edit":
$vals = "";
for($i=0;$i<$nbr_fld;$i++){
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "id":
$id = $_REQUEST[ $keys[$i] ];
$id_name = $keys[$i];
break;
case "info":
case "hyperlink":
break;
case "checkbox":
if( isset($_REQUEST[ $keys[$i] ]) ){
$index_val = 0;
}else{
$index_val = 1;
}
if($added_one == "yes"){
$vals .= ", ";
}
$vals .= " ".$keys[$i]."='".$dsc["cols"][ $keys[$i] ]["values"][$index_val]."' ";
$added_one = "yes";
break;
case "password":
if($added_one == "yes"){
$vals .= ", ";
}
if( isset($dsc["cols"][ $keys[$i] ]["encrypt"]) && $dsc["cols"][ $keys[$i] ]["encrypt"] == "yes" && $conf_enforce_adm_encryption){
$vals .= " ".$keys[$i]."=SHA1('".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."') ";
}else{
$vals .= " ".$keys[$i]."='".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."' ";
}
$added_one = "yes";
// if the crypt field is set, then we use this as the SQL field to populate the crypted password into
if(isset($dsc["cols"][ $keys[$i] ]["cryptfield"])){
if($added_one == "yes"){
$vals .= ", ";
}
$vals .= " ".$dsc["cols"][ $keys[$i] ]["cryptfield"]."='".crypt($_REQUEST[ $keys[$i] ], dtc_makesalt())."' ";
}
break;
case "custom_fld":
if($added_one == "yes"){
$vals .= ", ";
}
$arr_request = array();
foreach ($_REQUEST[ $keys[$i] ] as $req_field => $req_value){
$arr_request[] = $req_field.":".$req_value;
}
$txt_request = join("|",$arr_request);
$vals .= " ".$keys[$i]."='".mysql_real_escape_string($txt_request)."' ";
$added_one = "yes";
break;
default:
if($added_one == "yes"){
$vals .= ", ";
}
$vals .= " ".$keys[$i]."='".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."' ";
$added_one = "yes";
break;
}
}
if( isset($dsc["update_check_callback"]) ){
if ( $dsc["update_check_callback"]() ){
$q = "UPDATE ".$dsc["table_name"]." SET $vals WHERE $id_name='$id';";
}else{
$q = "";
}
}else{
$q = "UPDATE ".$dsc["table_name"]." SET $vals WHERE $id_name='$id';";
}
break;
case $dsc["action"]."_delete":
for($i=0;$i<$nbr_fld;$i++){
if($dsc["cols"][ $keys[$i] ]["type"] == "id"){
$id = $_REQUEST[ $keys[$i] ];
$id_name = $keys[$i];
}
}
$q = "DELETE FROM ".$dsc["table_name"]." WHERE $id_name='$id';";
break;
default:
$q = "";
break;
}
if($q != ""){
$r = mysql_query($q)or die("Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
}
}
$out = "<h3>".$dsc["title"]."</h3>";
if( $action_error_txt != ""){
$out .= "<font color=\"red\">" . $action_error_txt . "</font><br>";
}
// Display of all the titles of the table
$out .= "<table class=\"dtcDatagrid_table_props\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
$out .= "<tr>";
for($i=0;$i<$nbr_fld;$i++){
if($dsc["cols"][ $keys[$i] ]["type"] == "id"){
if($dsc["cols"][ $keys[$i] ]["display"] == "no"){
$do_display = "no";
}else{
$do_display = "yes";
}
}else{
$do_display = "yes";
}
if($do_display == "yes"){
if( isset($dsc["cols"][ $keys[$i] ]["help"]) ){
$jshelp = " onmouseover=\"Tip('". addslashes($dsc["cols"][ $keys[$i] ]["help"]) ."',STICKY,true,CLICKCLOSE,true,FADEIN,600)\" ";
}else{
$jshelp = "";
}
if (!isset($dsc["cols"][ $keys[$i] ]["legend"])){
$dsc["cols"][ $keys[$i] ]["legend"] = "";
}
$out .= "<td $jshelp class=\"dtcDatagrid_table_titles\">".$dsc["cols"][ $keys[$i] ]["legend"]."</td>";
}
}
$out .= "<td class=\"dtcDatagrid_table_titles\" colspan=\"2\"><b>".$txt_action[$lang]."</b></td>";
$out .= "</tr>";
// Display the existing entries of the table (edition and deletion)
$added_one = "no";
$sql_fld_list = "";
for($i=0;$i<$nbr_fld;$i++){
if($dsc["cols"][ $keys[$i] ]["type"] != "hyperlink"){
if($added_one == "yes"){
$sql_fld_list .= ", ";
}
$sql_fld_list .= $keys[$i];
$added_one = "yes";
}
}
// Display of all the values already in the table
if(isset($dsc["where_condition"])){
$where = " WHERE ".$dsc["where_condition"]." ";
}else{
if( isset($dsc["print_where_condition"]) ){
$where = " WHERE ".$dsc["print_where_condition"];
}else{
$where = "";
}
}
if(isset($dsc["order_by"])){
$order_by = " ORDER BY ".$dsc["order_by"]." ";
}else{
$order_by = "";
}
$q = "SELECT $sql_fld_list FROM ".$dsc["table_name"]." $where $order_by;";
$r = mysql_query($q)or die("Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$n = mysql_num_rows($r);
for($i=0;$i<$n;$i++){
$a = mysql_fetch_array($r);
$out .= "<tr><form name=\"".$dsc["action"]."_edit_frm_$i\" action=\"?\" method=\"$conf_post_or_get\">$fw<input type=\"hidden\" name=\"action\" value=\"".$dsc["action"]."_edit\">";
if(($i % 2) == 1 && isset($gfx_form_entry_label_background)){
$tdclass = "dtcDatagrid_table_flds_alt";
$input_class = "dtcDatagrid_input_alt_color";
}else{
$tdclass = "dtcDatagrid_table_flds";
$input_class = "dtcDatagrid_input_color";
}
// Get the primary key of the table raw before anything else.
for($j=0;$j<$nbr_fld;$j++){
if($dsc["cols"][ $keys[$j] ]["type"] == "id"){
$id = $a[ $keys[$j] ];
}
}
for($j=0;$j<$nbr_fld;$j++){
$the_name = $keys[$j];
$the_fld = $dsc["cols"][$the_name];
if($the_fld["type"] == "double_forkey"){
unset($dbl_forkey_link);
$fk_found = 0;
$the_type = $the_fld["forkey_type"];
// Query the 1st indirection table
$qrent = "SELECT ".$the_fld["searchkey_1st_ind"]." FROM ".$the_fld["table_1st_ind"]." WHERE ".$the_fld["fldwhere_1st_ind"]."='".$a[ $the_fld["fldwhere_1st_ind_orig"] ]."';";
$rrent = mysql_query($qrent)or die("Cannot query $qrent in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$nrent = mysql_num_rows($rrent);
if($nrent == 1){
$arent = mysql_fetch_array($rrent);
$cid = $arent[ $the_fld["searchkey_1st_ind"] ];
$qcli = "SELECT ".$the_fld["display_flds_2nd_ind"]." FROM ".$the_fld["table_2nd_ind"]." WHERE ".$the_fld["fldwhere_1st_ind_orig"]."='$cid';";
$rcli = mysql_query($qcli)or die("Cannot query $qcli in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$ncli = mysql_num_rows($rrent);
if($ncli == 1){
$acli = mysql_fetch_array($rcli);
$db_value = $acli[ $the_fld["display_flds_2nd_ind"] ];
$fk_found = 1;
$fk_link_more = $cid;
$dbl_forkey_link = $the_fld["link_start"].$cid;
}else{
$db_value = "Not found";
}
}else{
$qnrent = "SELECT ".$the_fld["display_flds_back"]." FROM ".$the_fld["table_back"]." WHERE ".$the_fld["fldwhere_back"]."='".$a[ $the_fld["fldwhere_back_orig"] ]."';";
$rnrent = mysql_query($qnrent)or die("Cannot query $qnrent in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$nnrent = mysql_num_rows($rnrent);
if($nnrent == 1){
$ancli = mysql_fetch_array($rnrent);
$db_value = $ancli[ $the_fld["display_flds_back"] ];
$fk_found = 1;
$dbl_forkey_link = $the_fld["link_start"].$a[ $the_fld["fldwhere_back_orig"] ];
}else{
$db_value = "Not found";
}
}
}else if($the_fld["type"] == "forkey"){
$fk_found = 0;
$the_type = $the_fld["forkey_type"];
$forkey_table = $the_fld["table"];
$forkey_other_table_fld = $the_fld["other_table_fld"];
$forkey_other_table_key = $the_fld["other_table_key"];
$forkey_this_table_field = $the_fld["this_table_field"];
$qfk = "SELECT $forkey_other_table_fld AS dtcfkfld FROM $forkey_table WHERE $forkey_other_table_key='". $a[ $forkey_this_table_field ] ."';";
$rfk = mysql_query($qfk)or die("Cannot query $qfk in ".__FILE__." line ".__LINE__." sql said: ".mysql_error()." when getting foreign key $forkey_fld value in table ".$the_fld["table"]);
$nfk = mysql_num_rows($rfk);
if($nfk == 1){
// afk means array foreign key, not away from keyboard... :)
$afk = mysql_fetch_array($rfk);
$db_value = $afk["dtcfkfld"];
$fk_found = 1;
}else{
if( isset($the_fld["bk_table"]) && isset($the_fld["bk_other_table_fld"]) && isset($the_fld["bk_other_table_key"]) && isset($the_fld["bk_this_table_field"]) ){
$forkey_table = $the_fld["bk_table"];
$forkey_other_table_fld = $the_fld["bk_other_table_fld"];
$forkey_other_table_key = $the_fld["bk_other_table_key"];
$forkey_this_table_field = $the_fld["bk_this_table_field"];
$qfk = "SELECT $forkey_other_table_fld AS dtcfkfld FROM $forkey_table WHERE $forkey_other_table_key='". $a[ $forkey_this_table_field ] ."';";
$rfk = mysql_query($qfk)or die("Cannot query $qfk in ".__FILE__." line ".__LINE__." sql said: ".mysql_error()." when getting foreign key $forkey_fld value in table ".$the_fld["table"]);
$nfk = mysql_num_rows($rfk);
}else{
$nfk = 0;
}
if($nfk == 1){
$afk = mysql_fetch_array($rfk);
$db_value = $afk["dtcfkfld"];
$fk_found = 2;
}else{
$db_value = "Foreign key N/A";
}
}
}else{
$the_type = $the_fld["type"];
if($the_type != "hyperlink"){
if (isset($a[ $the_name ])){
$db_value = $a[ $the_name ];
}else{
$db_value = "";
}
}
}
switch($the_type){
case "text":
if( isset($the_fld["size"])){
$size = " size=\"".$the_fld["size"]."\" ";
}else{
$size = "";
}
$out .= "<td class=\"$tdclass\">";
$out .= "<input class=\"$input_class\" type=\"text\" $size name=\"".$the_name."\" value=\"".$db_value."\">";
$out .= "</td>";
break;
case "password":
if( isset($the_fld["size"])){
$size = " size=\"".$the_fld["size"]."\" ";
}else{
$size = "";
}
$out .= "<td class=\"$tdclass\" style=\"white-space:nowrap;\">";
$genpass = autoGeneratePassButton($dsc["action"]."_edit_frm_$i",$the_name);
$out .= "<input class=\"$input_class\" autocomplete=\"off\" type=\"password\" $size name=\"".$the_name."\" value=\"".$db_value."\">$genpass";
$out .= "</td>";
break;
case "radio":
$out .= "<td class=\"$tdclass\">";
$nbr_choices = sizeof( $the_fld["values"] );
for($x=0;$x<$nbr_choices;$x++){
if($db_value == $the_fld["values"][$x]){
$selected = " checked ";
}else{
$selected = "";
}
$out .= " <input class=\"$input_class\" type=\"radio\" name=\"".$the_name."\" value=\"".$the_fld["values"][$x]."\" $selected> ";
if( isset($the_fld["display_replace"][$x]) ){
$out .= $the_fld["display_replace"][$x];
}else{
$out .= $the_fld["values"][$x];
}
}
$out .= "</td>";
break;
case "checkbox":
$out .= "<td class=\"$tdclass\">";
if($db_value == $the_fld["values"][0]){
$selected = " checked ";
}else{
$selected = "";
}
$out .= " <input class=\"$input_class\" type=\"checkbox\" name=\"".$the_name."\" value=\"".$the_fld["values"][0]."\" $selected> ";
$out .= "</td>";
break;
case "textarea":
if( isset($the_fld["cols"])){
$cols = " cols=\"".$the_fld["cols"]."\" ";
}else{
$cols = "";
}
if( isset($the_fld["rows"])){
$rows = " rows=\"".$the_fld["rows"]."\" ";
}else{
$rows = "";
}
$out .= "<td class=\"$tdclass\">";
$out .= "<textarea $cols $rows name=\"".$the_name."\">".$db_value."</textarea>";
$out .= "</td>";
break;
case "hyperlink":
$out .= "<td class=\"$tdclass\">";
$out .= "<a href=\"$fw_link&".$the_name."=".$id."\">";
$out .= $the_fld["text"]."</a>";
$out .= "</td>";
break;
case "info":
$out .= "<td class=\"$tdclass\">";
if($the_fld["type"] == "forkey" && isset($the_fld["link"]) && $fk_found == 1){
$out .= "<a href=\"".$the_fld["link"]. $a[ $the_name ] ."\" style=\"white-space:nowrap;\">".$db_value."</a>";
}else if($the_fld["type"] == "double_forkey" && $fk_found == 1){
$out .= "<a href=\"".$dbl_forkey_link."\" target=\"_blank\" style=\"white-space:nowrap;\">".$db_value."</a>";
}else{
$out .= "<span style=\"white-space:nowrap;\">".$db_value."</span>";
}
$out .= "</td>";
break;
case "popup":
$out .= "<td class=\"$tdclass\">";
$out .= "<select class=\"$input_class\" name=\"".$the_name."\">";
$nbr_values = sizeof($the_fld["values"]);
for($x=0;$x<$nbr_values;$x++){
if($the_fld["values"][$x] == $db_value){
$selected = " selected ";
}else{
$selected = "";
}
if( isset($the_fld["display_replace"][$x]) ){
$display_value_popup = $the_fld["display_replace"][$x];
}else{
$display_value_popup = $the_fld["values"][$x];
}
$out .= "<option value=\"".$the_fld["values"][$x]."\" $selected>".$display_value_popup."</option>";
}
$out .= "</select>";
$out .= "</td>";
break;
case "id":
$id_hidden = "<input type=\"hidden\" name=\"".$the_name."\" value=\"".$db_value."\">";
if($dsc["cols"][ $the_name ]["display"] == "yes"){
$out .= "<td class=\"$tdclass\">";
$out .= $id_hidden;
if ($the_name == 'name') {
$out .= $idn->decode($db_value);
} else {
$out .= $db_value;
}
$out .= "</td>";
}else{
$out .= $id_hidden;
}
break;
case "custom_fld":
$out .= "<td class=\"$tdclass\">";
// Manage the output of custom fields.
$customer_custom_fields = array();
$explo_row = explode("|", htmlspecialchars(stripcslashes($db_value)));
$n_custf = sizeof($explo_row);
for($ix=0;$ix<$n_custf;$ix++){
$one_fld = $explo_row[$ix];
$pos_data = strpos($one_fld,":");
if($pos_data === false){
continue;
}
$varname = substr($one_fld,0,$pos_data);
$value = substr($one_fld,$pos_data+1);
$customer_custom_fields[ $varname ] = $value;
}
$qa = "SELECT ".$the_fld["main_table"].".* FROM ".$the_fld["main_table"]." INNER JOIN ".$the_fld["second_table"]." ON ".$the_fld["main_join_clause"]." INNER JOIN ".$the_fld["third_table"]." ON ".$the_fld["second_join_clause"]." WHERE ".$the_fld["where_field"]." = $id ORDER BY ".$the_fld["order_field"].";";
//echo " | ".$qa." ";
$ra = mysql_query($qa)or die("Cannot query $q line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());
$na = mysql_num_rows($ra);
$init_alt = 1;
for($iz=0;$iz<$na;$iz++){
$aa = mysql_fetch_array($ra);
if(isset($customer_custom_fields[ $aa["varname"] ])){
$val = $customer_custom_fields[ $aa["varname"] ];
}else{
$val = "";
}
switch($aa["widgettype"]){
case "radio":
$explo_popup = explode("|",$aa["widgetvalues"]);
$explo_popup2 = explode("|",$aa["widgetdisplay"]);
$n_val = sizeof($explo_popup);
$widget = "";
for($jz=0;$jz<$n_val;$jz++){
if($val == $the_name[$explo_popup[$jz]]){
$sel = " checked ";
}else{
$sel = " ";
}
$widget .= "<input type=\"radio\" name=\"".$the_name."[".$aa["varname"]."]\" value=\"".$explo_popup[$jz]."\" $sel > ".$explo_popup2[$jz];
}
break;
case "popup":
$explo_popup = explode("|",$aa["widgetvalues"]);
$explo_popup2 = explode("|",$aa["widgetdisplay"]);
$n_val = sizeof($explo_popup);
$widget = "<select name=\"".$the_name."[".$aa["varname"]."]\">";
for($jz=0;$jz<$n_val;$jz++){
if($val == $the_name[$explo_popup[$jz]]){
$sel = " selected ";
}else{
$sel = " ";
}
$widget .= "<option value=\"".$explo_popup[$jz]."\" $sel >".$explo_popup2[$jz]."</option>";
}
$widget .= "</select>";
break;
case "textarea":
$widget = "<textarea name=\"".$the_name."[".$aa["varname"]."]\">".htmlspecialchars($val)."</textarea>";
break;
case "text":
default:
$widget = "<input size=\"40\" type=\"text\" name=\"".$the_name."[".$aa["varname"]."]\" value=\"".htmlspecialchars($val)."\">";
break;
}
$out .= $aa["question"].": ".$widget; //,$init_alt);
}
$out .= "</td>";
break;
}
}
$out .= "<td class=\"$tdclass\">".dtcApplyButton()."</form></td>";
if(isset($dsc["skip_deletion"]) && $dsc["skip_deletion"] == "yes"){
$out .= "<td class=\"$tdclass\"> </td></tr>";
}else{
$out .= "<td class=\"$tdclass\"><form method=\"$conf_post_or_get\" action=\"?\">$fw$id_hidden
<input type=\"hidden\" name=\"action\" value=\"".$dsc["action"]."_delete\">".dtcDeleteButton()."</form></td>";
$out .= "</form></tr>";
}
}
if(!isset($dsc["skip_creation"]) || $dsc["skip_deletion"] != "yes"){
if(($i % 2) == 1 && isset($gfx_form_entry_label_background)){
$tdclass = "dtcDatagrid_table_flds_alt";
$input_class = "dtcDatagrid_input_alt_color";
}else{
$tdclass = "dtcDatagrid_table_flds";
$input_class = "dtcDatagrid_input_color";
}
// Write the NEW stuff...
$out .= "<tr><form method=\"$conf_post_or_get\" name=\"".$dsc["action"]."_new_frm\" id=\"".$dsc["action"]."_new_frm\" action=\"?\">$fw<input type=\"hidden\" name=\"action\" value=\"".$dsc["action"]."_new\">";
for($j=0;$j<$nbr_fld;$j++){
$the_fld = $dsc["cols"][ $keys[$j] ];
switch($the_fld["type"]){
case "text":
if( isset($dsc["cols"][ $keys[$j] ]["size"])){
$size = " size=\"".$dsc["cols"][ $keys[$j] ]["size"]."\" ";
}else{
$size = "";
}
$out .= "<td class=\"$tdclass\">";
$out .= "<input class=\"$input_class\" type=\"text\" $size name=\"".$keys[$j]."\" value=\"\">";
$out .= "</td>";
break;
case "password":
if( isset($dsc["cols"][ $keys[$j] ]["size"])){
$size = " size=\"".$dsc["cols"][ $keys[$j] ]["size"]."\" ";
}else{
$size = "";
}
$out .= "<td class=\"$tdclass\" style=\"white-space:nowrap;\">";
$genpass = autoGeneratePassButton($dsc["action"]."_new_frm",$keys[$j]);
$out .= "<input class=\"$input_class\" autocomplete=\"off\" type=\"password\" $size name=\"".$keys[$j]."\" value=\"\">$genpass";
$out .= "</td>";
break;
case "radio":
$out .= "<td class=\"$tdclass\">";
$nbr_choices = sizeof( $dsc["cols"][ $keys[$j] ]["values"] );
for($x=0;$x<$nbr_choices;$x++){
if( isset($dsc["cols"][ $keys[$j] ]["default"]) ){
if($dsc["cols"][ $keys[$j] ]["values"][$x] == $dsc["cols"][ $keys[$j] ]["default"]){
$selected = " checked ";
}else{
$selected = "";
}
}else{
if($x == 0){
$selected = " checked ";
}else{
$selected = "";
}
}
$out .= "<input class=\"$input_class\" type=\"radio\" name=\"".$keys[$j]."\" value=\"".$dsc["cols"][ $keys[$j] ]["values"][$x]."\" $selected> ";
if( isset($dsc["cols"][ $keys[$j] ]["display_replace"][$x]) ){
$out .= $dsc["cols"][ $keys[$j] ]["display_replace"][$x];
}else{
$out .= $dsc["cols"][ $keys[$j] ]["values"][$x];
}
}
$out .= "</td>";
break;
case "checkbox":
$out .= "<td class=\"$tdclass\">";
$out .= " <input class=\"$input_class\" type=\"checkbox\" name=\"".$keys[$j]."\" value=\"".$dsc["cols"][ $keys[$j] ]["values"][0]."\" selected> ";
$out .= "</td>";
break;
case "textarea":
break;
case "hyperlink":
$out .= "<td class=\"$tdclass\"> </td>";
break;
case "popup":
$out .= "<td class=\"$tdclass\">";
$out .= "<select class=\"$input_class\" name=\"".$keys[$j]."\">";
$nbr_values = sizeof($dsc["cols"][ $keys[$j] ]["values"]);
for($x=0;$x<$nbr_values;$x++){
if( isset($dsc["cols"][ $keys[$j] ]["display_replace"][$x]) ){
$display_value_popup = $dsc["cols"][ $keys[$j] ]["display_replace"][$x];
}else{
$display_value_popup = $dsc["cols"][ $keys[$j] ]["values"][$x];
}
$out .= "<option value=\"".$dsc["cols"][ $keys[$j] ]["values"][$x]."\">".$display_value_popup."</option>";
}
$out .= "</select>";
$out .= "</td>";
break;
case "id":
// $id = $a[ $keys[$j] ];
if($dsc["cols"][ $keys[$j] ]["display"] == "yes"){
$out .= "<td class=\"tdclass\">";
$out .= "<input type=\"hidden\" name=\"".$keys[$j]."\" value=\"\">";
// $out .= $a[ $keys[$j] ];
$out .= "</td>";
}else{
$out .= "<input type=\"hidden\" name=\"".$keys[$j]."\" value=\"\">";
}
break;
}
}
$out .= "<td class=\"$tdclass\" colspan=\"2\">".dtcAddButton()."</form></td></tr>";
}
$out .= "</table>";
return $out;
}
// Properties of the $dsc parameter for this function:
// title => $txt_subdom_list[$lang] -> Main title to display for this list
// new_item_title => $txt_subdom_create[$lang] -> Title to display when a new item is in edition
// new_item_link => $txt_subdom_new[$lang] -> Text for the link for new items
// edit_item_title => $txt_subdom_edit_one[$lang] -> Text to display when an existing item is in edition
// table_name => $pro_mysql_subdomain_table -> Name of the SQL table involved in this editor
// action => "subdomain_editor" -> Prefix of the hidden action of all forms and the form name prefix as well
// forward => array("adm_login","adm_pass","addrlink") -> List of variables to forward in hidden <input>
// id_fld => "id" -> Column to use as a autoincrement_id in the SQL
// list_fld_show => "subdomain_name" -> Column holding the variable to display in the list of items
// [max_item] => $max_subdomain, -> Max number of items to display in this list, if number is bigger, creation not allowed
// [num_item_txt] => $txt_number_of_active_subdomains[$lang] -> Text to display for the number of items
// [create_item_callback] => "subdomainCreateDirsCallBack", -> Name of the callback function called after a creation of an item
// [delete_item_callback] => "subdomainDeleteDirsCallBack" -> Name of the callback function called after a deletion of an item
// [where_list] => array("domain_name" => $domain["name"]) -> List of field => value to set in all the WHERE of all SQL (listing and submit)
// cols => "field1"
// "field2"
// ...
// Properties of each fields:
// "type" => "id" -> This is the auto_increment ID of the table
// "display" => "no" -> Display it or not in the list (currently only "no" is working, and is used only when type=id)
// "legend" => "id" -> Text to display in the left side of the field
//
// "type" => "text" -> The HTML control is a TEXT field
// "type" => "readonly" -> The HTML control is a READONLY TEXT field
// "type" => "password" -> The HTML control is a PASSWORD field with the random pass generation button
// Both types text, password and readonly understands the following (not mandatory) fields:
// [disable_edit] => "yes" -> Can be used to disable the edition of a field in the edit mode (will still be editable in creation of items)
// [hide_create] => "yes" -> Can be used to hide a field in creation mode, it will only be displayed in edit mode
// [check] => "subdomain", -> Check against the format of the field content before allowing creation or edition
// Currently can have the follwing values: subdomain, subdomain_or_ip, domain_or_ip, dtc_login, dtc_pass
// [can_be_empty] => "yes" -> Allow the field to be empty even with a check value
// [empty_makes_sql_null] => "yes" -> Makes a SQL query with NULL as parametter wheneger a field is empty
// [callback] -> this routine will be called to get further data it will need to display. The id (autoinc) will be passed to the routine and it is expected that an array will be returned:
// array(
// "value" => $value,
// "happen" => $happen);
// "type" => "radio" -> The control is a radio button
// "type" => "checkbox" -> The control is a checkbox. Checkboxes have only 2 values (the possible ones in the db) and is not implemented yet
// "values" => array("yes","no") -> Values of the radio buttons (in display order)
// [default] => "no" -> default value of the radio button for creation of an item
// "type" => "popup" -> The control is a popup
// "values" => array("yes","no") -> Values of the popup (in display order)
// [display_replace] => array(... -> Values to replace in the display (can be smaller than the values array)
// "max_value_positive" => INT -> Check against an INT max value for a field
// This function is to be used for the user panel, it has field content check & validations plus addslashes
function dtcListItemsEdit($dsc){
global $adm_pass;
global $conf_post_or_get;
$out = "<h3>".$dsc["title"]."</u></b></h3>";
// Calculate the forwards parameters for links and forms
$nbr_forwards = sizeof($dsc["forward"]);
$keys_fw = array_keys($dsc["forward"]);
$fw = "";
$fw_link = "?";
for($i=0;$i<$nbr_forwards;$i++){
if($dsc["forward"][$i] == "adm_pass"){
$fw .= "<input type=\"hidden\" name=\"".$dsc["forward"][$i]."\" value=\"".$adm_pass."\">";
}else{
$fw .= "<input type=\"hidden\" name=\"".$dsc["forward"][$i]."\" value=\"".$_REQUEST[ $dsc["forward"][$i] ]."\">";
}
if($i != 0){
$fw_link .= "&";
}
if($dsc["forward"][$i] == "adm_pass"){
$fw_link .= $dsc["forward"][$i]."=$adm_pass";
}else{
$fw_link .= $dsc["forward"][$i]."=".$_REQUEST[ $dsc["forward"][$i] ];
}
}
// Condition to add to each queries
$where = "WHERE 1";
if( isset($dsc["order_by"])){
$order_by = " ORDER BY ". $dsc["order_by"];
}else{
$order_by = "";
}
$added_insert_names = "";
$added_insert_values = "";
if(isset($dsc["where_list"])){
$nbr_where = sizeof($dsc["where_list"]);
$where_keys = array_keys($dsc["where_list"]);
for($i=0;$i<$nbr_where;$i++){
if($i != 0){
$added_insert_names .= ",";
$added_insert_values .= ",";
}
$added_insert_names .= $where_keys[$i];
$added_insert_values .= "'".$dsc["where_list"][ $where_keys[$i] ]."'";
$where .= " AND ".$where_keys[$i]."='".$dsc["where_list"][ $where_keys[$i] ]."'";
}
// As there will be other fields, we need that one
$added_insert_names .= ",";
$added_insert_values .= ",";
}
// Number of fields that we are about to manage here and theire names
$nbr_fld = sizeof($dsc["cols"]);
$keys = array_keys($dsc["cols"]);
// We need the current number of items now to check against the max number for addition
$q = "SELECT ".$dsc["id_fld"].",".$dsc["list_fld_show"]." FROM ".$dsc["table_name"]." $where;";
$r_item_list = mysql_query($q)or die("Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$current_num_items = mysql_num_rows($r_item_list);
// SQL submit stuffs
if( isset($_REQUEST["action"]) && $_REQUEST["action"] == $dsc["action"]."_new_item" ){
// Todo: do the fields checkings
$commit_flag = "yes";
$commit_err = "";
for($i=0;$i<$nbr_fld;$i++){
// assign a "fixup" function to sanitize/alter the value, eg. 'strtolower'
if( isset($dsc["cols"][ $keys[$i] ]["fixup"]) ){
if( function_exists($dsc["cols"][ $keys[$i] ]["fixup"]) ){
$_REQUEST[ $keys[$i] ] = $dsc["cols"][ $keys[$i] ]["fixup"]( $_REQUEST[ $keys[$i] ] );
}
}
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "popup":
case "radio":
$nbr_choices = sizeof($dsc["cols"][ $keys[$i] ]["values"]);
$is_one_of_them = "no";
for($j=0;$j<$nbr_choices;$j++){
if($dsc["cols"][ $keys[$i] ]["values"][$j] == $_REQUEST[ $keys[$i] ]){
$is_one_of_them = "yes";
}
}
if($is_one_of_them == "no"){
$commit_flag = "no";
$commit_err = "the variable ".$keys[$i]." is not one of the allowed values<br>";
}
break;
default:
break;
}
if( isset($dsc["cols"][ $keys[$i] ]["check"])){
switch($dsc["cols"][ $keys[$i] ]["check"]){
case "subdomain":
if( !checkSubdomainFormat($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a subdomain<br>";
}
}
break;
case "list_of_ip":
if( isset($dsc["cols"][ $keys[$i] ]["can_be_empty"]) &&
$dsc["cols"][ $keys[$i] ]["can_be_empty"] == "yes" &&
$_REQUEST[ $keys[$i] ] == ""){
break;
}
$mylist_of_ip = explode("|",$_REQUEST[ $keys[$i] ]);
$number_of_ip = sizeof($mylist_of_ip);
for($g=0;$g<$number_of_ip;$g++){
if( !isIP($mylist_of_ip[$g]) ){
$commit_flag = "no";
$commit_err .= $keys[$i].": invalid IP list<br>";
}
}
break;
case "subdomain_or_ip":
if( !checkSubdomainFormat($_REQUEST[ $keys[$i] ]) && !isIP($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a subdomain or IP addresse<br>";
}
}
break;
case "ip6":
if( !isIP6($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
if ( !isset($dsc["cols"][ $keys[$i] ]["empty_makes_default"])
|| $dsc["cols"][ $keys[$i] ]["empty_makes_default"] != "yes"
|| $_REQUEST[ $keys[$i] ] != "default"){
$commit_flag = "no";
$commit_err .= $keys[$i].": not an IPv6 address<br>";
}
}
}
break;
case "page_url":
if( !isPageURL($_REQUEST[ $keys[$i] ]) ){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a page URL")."<br>";
}
break;
case "ip_addr":
if( !isIP($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not an IP address<br>";
}
}
break;
case "domain_or_ip":
if( !isIP($_REQUEST[ $keys[$i] ]) && !isHostname($_REQUEST[ $keys[$i] ])){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a domain or IP addresse<br>";
}
}
break;
case "dtc_login":
if( !isFtpLogin($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a correct login format.<br>";
}
}
break;
case "dtc_login_or_email":
if( !isFtpLogin($_REQUEST[ $keys[$i] ]) && !isValidEmail($_REQUEST[ $keys[$i] ])){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a correct login format.<br>";
}
}
break;
case "mail_alias_group":
$mail_alias_group_raw = trim($_REQUEST[ $keys[$i] ],"\r\n");
$mail_alias_nocr = str_replace("\r", "", $mail_alias_group_raw);
$mail_alias_array = preg_split("/\n/", $mail_alias_nocr);
for($x=0;$x<count($mail_alias_array);$x++)
{
if ( ! isValidEmail($mail_alias_array[$x]) )
{
$commit_flag = "no";
$commit_err .= $mail_alias_array[$x].": not a valid email format.<br>";
}
}
break;
case "dtc_pass":
if( !isDTCPassword($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a correct password format<br>";
}
}
if( FALSE != check_password($_REQUEST[ $keys[$i] ])){
$commit_flag = "no";
$commit_err .= $keys[$i].": "._("This password is one of the 500 most used passwords on the internet. Please choose a stronger one.");
}
break;
case "email":
if( !isValidEmail($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a correct email format<br>";
}
}
break;
case "number":
if( !isRandomNum($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a correct number format<br>";
}
}
break;
case "max_value_2096":
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
if( !isRandomNum($_REQUEST[ $keys[$i] ]) ){
$commit_flag = "no";
$commit_err .= $keys[$i].": not a correct number format<br>";
}
if($_REQUEST[ $keys[$i] ] >= 2096){
$commit_flag = "no";
$commit_err .= $keys[$i].": is greater or equal than the max value 2096<br>";
}
}
break;
default:
$commit_flag = "no";
$commit_err .= $keys[$i].": unknown field checking type (".$dsc["cols"][ $keys[$i] ]["check"].").<br>";
break;
}
}
}
if(isset($dsc["max_item"]) && $current_num_items >= $dsc["max_item"]){
$commit_flag = "no";
$commit_err = "Max number of items reached!";
}
if(isset($dsc["check_unique"])){
$nbr_unique_check = sizeof($dsc["check_unique"]);
$where_clause = "";
for($i=0;$i<$nbr_unique_check;$i++){
if($i != 0){
$where_clause .= " AND ";
}
if( isset ($dsc["cols"][ $dsc["check_unique"][$i] ]["happen_domain"]) ){
$where_clause .= $dsc["check_unique"][$i] . "='".$_REQUEST[ $dsc["check_unique"][$i] ] . $dsc["cols"][ $dsc["check_unique"][$i] ]["happen_domain"]."' ";
}else{
$where_clause .= $dsc["check_unique"][$i] . "='".$_REQUEST[ $dsc["check_unique"][$i] ]."' ";
}
}
if( !isset($dsc["check_unique_use_where_list"]) || $dsc["check_unique_use_where_list"] == "yes"){
$nbr_where_list_fld = sizeof($dsc["where_list"]);
$where_list_keys_fld = array_keys($dsc["where_list"]);
for($i=0;$i<$nbr_where_list_fld;$i++){
$where_clause .= " AND ".$where_list_keys_fld[$i]."='".$dsc["where_list"][ $where_list_keys_fld[$i] ]."'";
}
}
$q = "SELECT * FROM ".$dsc["table_name"]." WHERE $where_clause ";
$r = mysql_query($q)or die("Cannot query \"$q\" line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());
$n = mysql_num_rows($r);
if($n > 0){
$commit_flag = "no";
$commit_err = $dsc["check_unique_msg"];
}
}
// Build the request
$fld_names = "";
$values = "";
$added_one = "no";
for($i=0;$i<$nbr_fld;$i++){
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "password":
if($added_one == "yes"){
$fld_names .= ",";
$values .= ",";
}
$fld_names .= $keys[$i];
if( isset($dsc["cols"][ $keys[$i] ]["empty_makes_sql_null"]) && $dsc["cols"][ $keys[$i] ]["empty_makes_sql_null"] == "yes" && $_REQUEST[ $keys[$i] ] == ""){
$values .= "NULL";
}else if( isset($dsc["cols"][ $keys[$i] ]["empty_makes_default"]) && $dsc["cols"][ $keys[$i] ]["empty_makes_default"] == "yes" && $_REQUEST[ $keys[$i] ] == ""){
$values .= "'default'";
}else{
if(isset($dsc["cols"][ $keys[$i] ]["happen_domain"])){
$values .= "'".mysql_real_escape_string($_REQUEST[ $keys[$i] ]).$dsc["cols"][ $keys[$i] ]["happen_domain"]."'";
}else{
$values .= "'".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."'";
}
// if the crypt field is set, then we use this as the SQL field to populate the crypted password into
if(isset($dsc["cols"][ $keys[$i] ]["cryptfield"])){
if($added_one == "yes"){
$fld_names .= ",";
$values .= ",";
}
$fld_names .= $dsc["cols"][ $keys[$i] ]["cryptfield"];
$values .= "'".crypt($_REQUEST[ $keys[$i] ], dtc_makesalt())."'";
}
}
$added_one = "yes";
break;
case "text":
case "textarea":
if($added_one == "yes"){
$fld_names .= ",";
$values .= ",";
}
$fld_names .= $keys[$i];
if( isset($dsc["cols"][ $keys[$i] ]["empty_makes_sql_null"]) && $dsc["cols"][ $keys[$i] ]["empty_makes_sql_null"] == "yes" && $_REQUEST[ $keys[$i] ] == ""){
$values .= "NULL";
}else if( isset($dsc["cols"][ $keys[$i] ]["empty_makes_default"]) && $dsc["cols"][ $keys[$i] ]["empty_makes_default"] == "yes" && $_REQUEST[ $keys[$i] ] == ""){
$values .= "'default'";
}else{
if(isset($dsc["cols"][ $keys[$i] ]["happen_domain"])){
$values .= "'".mysql_real_escape_string($_REQUEST[ $keys[$i] ]).$dsc["cols"][ $keys[$i] ]["happen_domain"]."'";
}else{
$values .= "'".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."'";
}
}
$added_one = "yes";
break;
case "checkbox":
if($added_one == "yes"){
$fld_names .= ",";
$values .= ",";
}
$added_one = "yes";
$fld_names .= $keys[$i];
if (isset($_REQUEST[ $keys[$i] ])) {
$values .= "'".$dsc["cols"][ $keys[$i] ]["values"][0]."'";
}else{
$values .= "'".$dsc["cols"][ $keys[$i] ]["values"][1]."'";
}
break;
case "popup":
case "radio":
if($added_one == "yes"){
$fld_names .= ",";
$values .= ",";
}
$fld_names .= $keys[$i];
$values .= "'".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."'";
$added_one = "yes";
break;
}
}
if($commit_flag == "yes"){
$q = "INSERT INTO ".$dsc["table_name"]." ($added_insert_names $fld_names) VALUES ($added_insert_values $values);";
$success = "yes";
$r = mysql_query($q)or $success = "no";
if($success == "yes"){
$insert_id = mysql_insert_id();
if( isset($dsc["create_item_callback"]) ){
$out .= $dsc["create_item_callback"]($insert_id);
}
}else{
$out .= "<font color=\"red\">Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error()."</font>";
}
}else{
$out .= "<font color=\"red\">"._("Could not commit the changes because of an error in field format: ")."<br>$commit_err</font><br>";
}
}else if( isset($_REQUEST["action"]) && $_REQUEST["action"] == $dsc["action"]."_save_item" ){
// Todo: do the fields checkings
$commit_flag = "yes";
$commit_err = "";
for($i=0;$i<$nbr_fld;$i++){
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "checkbox":
break;
case "popup":
case "radio":
case "checkbox":
$nbr_choices = sizeof($dsc["cols"][ $keys[$i] ]["values"]);
$is_one_of_them = "no";
for($j=0;$j<$nbr_choices;$j++){
if($dsc["cols"][ $keys[$i] ]["values"][$j] == $_REQUEST[ $keys[$i] ]){
$is_one_of_them = "yes";
}
}
if($is_one_of_them == "no"){
$commit_flag = "no";
$commit_err = "the variable ".$keys[$i]._(" is not one of the allowed values")."<br>";
}
break;
default:
break;
}
if( isset($dsc["cols"][ $keys[$i] ]["check"]) && (!isset($dsc["cols"][ $keys[$i] ]["disable_edit"]) || $dsc["cols"][ $keys[$i] ]["disable_edit"] != "yes") ){
switch($dsc["cols"][ $keys[$i] ]["check"]){
case "subdomain":
if( !checkSubdomainFormat($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a subdomain")."<br>";
}
}
break;
case "list_of_ip":
if( isset($dsc["cols"][ $keys[$i] ]["can_be_empty"]) &&
$dsc["cols"][ $keys[$i] ]["can_be_empty"] == "yes" &&
$_REQUEST[ $keys[$i] ] == ""){
break;
}
$mylist_of_ip = explode("|",$_REQUEST[ $keys[$i] ]);
$number_of_ip = sizeof($mylist_of_ip);
for($g=0;$g<$number_of_ip;$g++){
if( !isIP($mylist_of_ip[$g]) ){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": invalid IP list")."<br>";
}
}
break;
case "subdomain_or_ip":
if( !checkSubdomainFormat($_REQUEST[ $keys[$i] ]) && !isIP($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a subdomain or IP addresse")."<br>";
}
}
break;
case "ip6":
if( !isIP6($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
if ( !isset($dsc["cols"][ $keys[$i] ]["empty_makes_default"])
|| $dsc["cols"][ $keys[$i] ]["empty_makes_default"] != "yes"
|| $_REQUEST[ $keys[$i] ] != "default"){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not an IPv6 address")."<br>";
}
}
}
break;
case "page_url":
if( !isPageURL($_REQUEST[ $keys[$i] ]) ){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a page URL")."<br>";
}
break;
case "ip_addr":
if( !isIP($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not an IP address")."<br>";
}
}
break;
case "domain_or_ip":
if( !isIP($_REQUEST[ $keys[$i] ]) && !isHostname($_REQUEST[ $keys[$i] ])){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a domain or IP addresse")."<br>";
}
}
break;
case "dtc_login":
if( !isFtpLogin($_REQUEST[ $keys[$i] ])){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a correct login format")."<br>";
}
}
break;
case "dtc_login_or_email":
if( !isFtpLogin($_REQUEST[ $keys[$i] ]) && !isValidEmail($_REQUEST[ $keys[$i] ])){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a correct login format")."<br>";
}
}
break;
case "mail_alias_group":
$mail_alias_group_raw = trim($_REQUEST[ $keys[$i] ],"\r\n");
$mail_alias_nocr = str_replace("\r", "", $mail_alias_group_raw);
$mail_alias_array = preg_split("/\n/", $mail_alias_nocr);
for($x=0;$x<count($mail_alias_array);$x++)
{
if ( ! isValidEmail($mail_alias_array[$x]) )
{
$commit_flag = "no";
$commit_err .= $mail_alias_array[$x]._(": not a valid email format")."<br>";
}
}
break;
case "dtc_pass":
if( !isDTCPassword($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a correct password format")."<br>";
}
}
if( FALSE != check_password($_REQUEST[ $keys[$i] ]) ){
$commit_flag = "no";
$commit_err .= $keys[$i].": "._("This password is one of the 500 most used passwords on the internet. Please choose a stronger one.");
}
break;
case "email":
if( !isValidEmail($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a correct email format")."<br>";
}
}
break;
case "number":
if( !isRandomNum($_REQUEST[ $keys[$i] ]) ){
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a correct number format")."<br>";
}
}
break;
case "max_value_2096":
if( !isset($dsc["cols"][ $keys[$i] ]["can_be_empty"])
|| $dsc["cols"][ $keys[$i] ]["can_be_empty"] != "yes"
|| $_REQUEST[ $keys[$i] ] != ""){
if( !isRandomNum($_REQUEST[ $keys[$i] ]) ){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": not a correct number format")."<br>";
}
if($_REQUEST[ $keys[$i] ] >= 2096){
$commit_flag = "no";
$commit_err .= $keys[$i]._(": is greater or equal than the max value 2096")."<br>";
}
}
break;
default:
$commit_flag = "no";
$commit_err .= $keys[$i]._(": unknown field checking type")." (".$dsc["cols"][ $keys[$i] ]["check"].").<br>";
break;
}
}
}
// Build the request
$added_one = "no";
$reqs = "";
for($i=0;$i<$nbr_fld;$i++){
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "id":
$id_fldname = $keys[$i];
$id_fld_value = mysql_real_escape_string($_REQUEST[ $keys[$i] ]);
break;
case "readonly":
break;
case "text":
case "textarea":
case "password":
if( !isset($dsc["cols"][ $keys[$i] ]["disable_edit"]) || $dsc["cols"][ $keys[$i] ]["disable_edit"] != "yes"){
if($added_one == "yes"){
$reqs .= ",";
}
if( isset($dsc["cols"][ $keys[$i] ]["happen_domain"])){
$happen = $dsc["cols"][ $keys[$i] ]["happen_domain"];
}else{
$happen = "";
}
if( isset($dsc["cols"][ $keys[$i] ]["empty_makes_sql_null"]) && $dsc["cols"][ $keys[$i] ]["empty_makes_sql_null"] == "yes" && $_REQUEST[ $keys[$i] ] == ""){
$reqs .= $keys[$i]."=NULL";
}else if( isset($dsc["cols"][ $keys[$i] ]["empty_makes_default"]) && $dsc["cols"][ $keys[$i] ]["empty_makes_default"] == "yes" && $_REQUEST[ $keys[$i] ] == ""){
$reqs .= $keys[$i]."='default'";
}else{
$reqs .= $keys[$i]."='".mysql_real_escape_string($_REQUEST[ $keys[$i] ]).$happen."'";
// if the crypt field is set, then we use this as the SQL field to populate the crypted password into
if(isset($dsc["cols"][ $keys[$i] ]["cryptfield"])){
if($added_one == "yes"){
$reqs .= ", ";
}
$reqs .= " ".$dsc["cols"][ $keys[$i] ]["cryptfield"]."='".crypt($_REQUEST[ $keys[$i] ], dtc_makesalt())."' ";
}
}
$added_one = "yes";
}
break;
case "popup":
case "radio":
if($added_one == "yes"){
$reqs .= ",";
}
$reqs .= $keys[$i]."='".mysql_real_escape_string($_REQUEST[ $keys[$i] ])."'";
$added_one = "yes";
break;
case "checkbox":
if($added_one == "yes"){
$reqs .= ",";
}
if( isset($_REQUEST[ $keys[$i] ])){
$reqs .= $keys[$i]."='".$dsc["cols"][ $keys[$i] ]["values"][0]."'";
}else{
$reqs .= $keys[$i]."='".$dsc["cols"][ $keys[$i] ]["values"][1]."'";
}
break;
default:
die($dsc["cols"][ $keys[$i] ]["type"].": Not implemented yet line ".__LINE__." file ".__FILE__);
break;
}
}
if($commit_flag != "yes"){
$out .= "<font color=\"red\">Could not commit the changes because of an error in field format: [todo: error desc]<br>$commit_err</font>";
}else if(!isset($id_fldname) || !isset($id_fld_value)){
$out .= "<font color=\"red\">Could not commit the changes because the id is not set!</font>";
}else{
$q = "UPDATE ".$dsc["table_name"]." SET $reqs $where AND $id_fldname='$id_fld_value';";
$r = mysql_query($q)or $out .= "<font color=\"red\">Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error()."</font>";
if(isset($dsc["edit_item_callback"])){
$dsc["edit_item_callback"]($id_fld_value);
}
}
}else if( isset($_REQUEST["action"]) && $_REQUEST["action"] == $dsc["action"]."_delete_item" ){
for($i=0;$i<$nbr_fld;$i++){
if($dsc["cols"][ $keys[$i] ]["type"] == "id"){
$id_fldname = $keys[$i];
$id_fld_value = mysql_real_escape_string($_REQUEST[ $keys[$i] ]);
}
}
if( isset($id_fldname) && isset($id_fld_value) ){
if( isset($dsc["delete_item_callback"]) ){
$dsc["delete_item_callback"]($id_fld_value);
}
$q = "DELETE FROM ".$dsc["table_name"]." $where AND $id_fldname='".$id_fld_value."';";
$r = mysql_query($q)or $out .= "<font color=\"red\">Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error()."</font>";
}else{
$out .= "<font color=\"red\">Could not commit the deletion because the id field could not be found.</font>";
}
}
// We have to query it again, in case an insert or a delete has occured!
$q = "SELECT ".$dsc["id_fld"].",".$dsc["list_fld_show"]." FROM ".$dsc["table_name"]." $where $order_by;";
$r_item_list = mysql_query($q)or die("Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$current_num_items = mysql_num_rows($r_item_list);
if(isset($dsc["max_item"])){
if($current_num_items >= $dsc["max_item"]){
$out .= "<font color=\"red\">";
}
$out .= $dsc["num_item_txt"].$current_num_items."/".$dsc["max_item"];
if($current_num_items >= $dsc["max_item"]){
$out .= "</font>";
}
$out .= "<br><br>";
}
// First display a list of items
for($i=0;$i<$current_num_items;$i++){
$a = mysql_fetch_array($r_item_list);
if($i!=0){
$out .= " - ";
}
if( isset($_REQUEST["subaction"]) && $_REQUEST["subaction"] == $dsc["action"]."_edit_item" && $_REQUEST["item"] == $a[ $dsc["id_fld"] ]){
$out .= $a[ $dsc["list_fld_show"] ];
}else{
$out .= "<a href=\"$fw_link&subaction=".$dsc["action"]."_edit_item&item=".$a[ $dsc["id_fld"] ]."\">".$a[ $dsc["list_fld_show"] ]."</a>";
}
}
$out .= "<br><br>";
// Creation of new items
if( !isset($_REQUEST["subaction"]) || $_REQUEST["subaction"] != $dsc["action"]."_edit_item"){
$out .= $dsc["new_item_link"]."<br><br>";
$out .= "<h3>".$dsc["new_item_title"]."</h3><br>";
if(isset($dsc["max_item"]) && $current_num_items >= $dsc["max_item"]){
$out .= "<font color=\"red\">". _("Maximum number reached") ."!</font><br>";
}else{
$out .= "<form method=\"$conf_post_or_get\" name=\"".$dsc["action"]."_new_item_frm\" action=\"?\">$fw
<input type=\"hidden\" name=\"action\" value=\"".$dsc["action"]."_new_item\">".dtcFormTableAttrs();
for($i=0;$i<$nbr_fld;$i++){
if( isset($dsc["cols"][ $keys[$i] ]["help"])){
$help = $dsc["cols"][ $keys[$i] ]["help"];
}else{
$help = "";
}
switch($dsc["cols"][ $keys[$i] ]["type"]){
case "id":
$out .= "<input type=\"hidden\" name=\"".$keys[$i]."\" value=\"\">";
break;
case "password":
$genpass = autoGeneratePassButton($dsc["action"]."_new_item_frm",$keys[$i]);
$ctrl = "<input type=\"password\" autocomplete=\"off\" name=\"".$keys[$i]."\" value=\"\">$genpass";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
case "text":
case "readonly":
if (isset($dsc["cols"][ $keys[$i] ]["hide_create"]) && $dsc["cols"][ $keys[$i] ]["hide_create"]=="yes")
{ break; }
if( isset($dsc["cols"][ $keys[$i] ]["happen_domain"]) ){
$happen = $dsc["cols"][ $keys[$i] ]["happen_domain"];
}else{
$happen = "";
}
if( isset($dsc["cols"][ $keys[$i] ]["happen"]) ){
$happen .= $dsc["cols"][ $keys[$i] ]["happen"];
}
if( isset($dsc["cols"][ $keys[$i] ]["default"]) ){
$ctrl_value = $dsc["cols"][ $keys[$i] ]["default"];
}else{
$ctrl_value = "";
}
if ($dsc["cols"][ $keys[$i] ]["type"]=="readonly")
{
$ctrl = "<input type=\"text\" name=\"".$keys[$i]."\" value=\"$ctrl_value\" READONLY>$happen";
}
else
{
$ctrl = "<input type=\"text\" name=\"".$keys[$i]."\" value=\"$ctrl_value\">$happen";
}
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
case "textarea":
if( isset($dsc["cols"][ $keys[$i] ]["cols"]) ){
$ctrl_cols = " cols=\"".$dsc["cols"][ $keys[$i] ]["cols"]."\" ";
}else{
$ctrl_cols = "";
}
if( isset($dsc["cols"][ $keys[$i] ]["rows"]) ){
$ctrl_rows = " rows=\"".$dsc["cols"][ $keys[$i] ]["rows"]."\" ";
}else{
$ctrl_rows = "";
}
$ctrl = "<textarea $ctrl_cols $ctrl_rows name=\"".$keys[$i]."\"></textarea>";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
case "radio":
$nbr_choices = sizeof( $dsc["cols"][ $keys[$i] ]["values"] );
$ctrl = "";
for($x=0;$x<$nbr_choices;$x++){
if( isset($dsc["cols"][ $keys[$i] ]["default"]) ){
if($dsc["cols"][ $keys[$i] ]["values"][$x] == $dsc["cols"][ $keys[$i] ]["default"]){
$selected = " checked ";
}else{
$selected = "";
}
}else{
if($x == 0){
$selected = " checked ";
}else{
$selected = "";
}
}
if( isset($dsc["cols"][ $keys[$i] ]["display_replace"][$x]) ){
$display_val = $dsc["cols"][ $keys[$i] ]["display_replace"][$x];
}else{
$display_val = $dsc["cols"][ $keys[$i] ]["values"][$x];
}
$ctrl .= "<input type=\"radio\" name=\"".$keys[$i]."\" value=\"".$dsc["cols"][ $keys[$i] ]["values"][$x]."\" $selected> ";
$ctrl .= $display_val;
}
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
case "checkbox":
if( !isset($dsc["cols"][ $keys[$i] ]["default"]) ){
$checked = " checked ";
}else{
$checked = " ";
}
$ctrl = "<input type=\"checkbox\" name=\"".$keys[$i]."\" value=\"yes\" $checked>";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
case "popup":
$nbr_choices = sizeof( $dsc["cols"][ $keys[$i] ]["values"] );
$ctrl = "<select name=\"".$keys[$i]."\">";
for($x=0;$x<$nbr_choices;$x++){
$selected = "";
if( isset($dsc["cols"][ $keys[$i] ]["default"]) ){
if($dsc["cols"][ $keys[$i] ]["values"][$x] == $dsc["cols"][ $keys[$i] ]["default"]){
$selected = " selected ";
}else{
$selected = "";
}
}
if( isset($dsc["cols"][ $keys[$i] ]["display_replace"][$x]) ){
$display_val = $dsc["cols"][ $keys[$i] ]["display_replace"][$x];
}else{
$display_val = $dsc["cols"][ $keys[$i] ]["values"][$x];
}
$ctrl .= " <option value=\"".$dsc["cols"][ $keys[$i] ]["values"][$x]."\" $selected>$display_val</option>";
}
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
default:
$ctrl = "Not implemented yet!!!";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$i] ]["legend"],$ctrl,$i%2,$help);
break;
}
}
$out .= dtcFromOkDraw();
$out .= "</table></form>";
}
// Edition of existing items
}else{
$out .= "<a href=\"$fw_link&subaction=".$dsc["action"]."_new_item\">".$dsc["new_item_link"]."</a><br><br>";
$out .= "<h3>".$dsc["edit_item_title"]."</h3><br>";
$q = "SELECT * FROM ".$dsc["table_name"]." $where AND ".$dsc["id_fld"]."='".mysql_real_escape_string($_REQUEST["item"])."';";
$r = mysql_query($q)or die("Cannot query $q in ".__FILE__." line ".__LINE__." sql said: ".mysql_error());
$n = mysql_num_rows($r);
if($n == 1){
$a = mysql_fetch_array($r);
$out .= "<form method=\"$conf_post_or_get\" name=\"".$dsc["action"]."_save_item_frm\" action=\"?\">$fw";
$out .= "<input type=\"hidden\" name=\"action\" value=\"".$dsc["action"]."_save_item\">";
$out .= "<input type=\"hidden\" name=\"subaction\" value=\"".$dsc["action"]."_edit_item\">";
$out .= "<input type=\"hidden\" name=\"item\" value=\"".$a[ $dsc["id_fld"] ]."\">";
$out .= dtcFormTableAttrs();
for($j=0;$j<$nbr_fld;$j++){
$the_fld = $dsc["cols"][ $keys[$j] ];
if( isset($dsc["cols"][ $keys[$j] ]["help"])){
$help = $dsc["cols"][ $keys[$j] ]["help"];
}else{
$help = "";
}
switch($the_fld["type"]){
case "id":
$out .= "<input type=\"hidden\" name=\"".$keys[$j]."\" value=\"".$a[ $keys[$j] ]."\">";
$id_fldname = $keys[$j];
$id_fld_value = $a[ $keys[$j] ];
break;
case "textarea":
if( isset($dsc["cols"][ $keys[$j] ]["cols"]) ){
$ctrl_cols = " cols=\"".$dsc["cols"][ $keys[$j] ]["cols"]."\" ";
}else{
$ctrl_cols = "";
}
if( isset($dsc["cols"][ $keys[$j] ]["rows"]) ){
$ctrl_rows = " rows=\"".$dsc["cols"][ $keys[$j] ]["rows"]."\" ";
}else{
$ctrl_rows = "";
}
$ctrl = "<textarea $ctrl_cols $ctrl_rows name=\"".$keys[$j]."\">".stripslashes($a[ $keys[$j] ])."</textarea>";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$j] ]["legend"],$ctrl,$j%2,$help);
break;
case "password":
case "text":
case "readonly":
if( isset($dsc["cols"][ $keys[$j] ]["disable_edit"]) && $dsc["cols"][ $keys[$j] ]["disable_edit"] == "yes"){
$disabled = " disabled ";
}else{
$disabled = " ";
}
if( isset($dsc["cols"][ $keys[$j] ]["size"])){
$size = " size=\"".$dsc["cols"][ $keys[$j] ]["size"]."\" ";
}else{
$size = "";
}
if( isset($dsc["cols"][ $keys[$j] ]["happen_domain"]) && preg_match("/".$dsc["cols"][ $keys[$j] ]["happen_domain"]."\$/",$a[ $keys[$j] ])){
$input_disp_value = substr($a[ $keys[$j] ],0,strlen($a[ $keys[$j] ]) - strlen($dsc["cols"][ $keys[$j] ]["happen_domain"]));
$happen = $dsc["cols"][ $keys[$j] ]["happen_domain"];
}else{
if ($dsc["cols"][ $keys[$j] ]["type"]!="readonly")
{
$input_disp_value = $a[ $keys[$j] ];
}
$happen = "";
}
if( isset($dsc["cols"][ $keys[$j] ]["happen"]) ){
$happen .= $dsc["cols"][ $keys[$j] ]["happen"];
}
if($the_fld["type"] == "password"){
$genpass = autoGeneratePassButton($dsc["action"]."_save_item_frm",$keys[$j]);
$input_disp_type = "password";
}else{
$genpass = "";
$input_disp_type = "text";
}
// Do this only for readonly
if ($dsc["cols"][ $keys[$j] ]["type"]=="readonly")
{
$disabled = " READONLY";
isset($dsc["cols"][ $keys[$j] ]["default"]) ? $input_disp_value = $dsc["cols"][ $keys[$j] ]["default"] : $input_disp_value ='';
isset($dsc["cols"][ $keys[$j] ]["happen"]) ? $happen = $dsc["cols"][ $keys[$j] ]["happen"] : $happen = '';;
}
if (isset($dsc["cols"][ $keys[$j] ]["callback"]))
{
$retArray=$dsc["cols"][ $keys[$j] ]["callback"]($id_fld_value);
$input_disp_value = $retArray["value"];
$happen = $retArray["happen"];
}
$ctrl = "<input type=\"$input_disp_type\" $size name=\"".$keys[$j]."\" value=\"".stripslashes($input_disp_value)."\" $disabled>$genpass$happen";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$j] ]["legend"],$ctrl,$j%2,$help);
break;
case "radio":
$nbr_choices = sizeof( $dsc["cols"][ $keys[$j] ]["values"] );
$ctrl = "";
for($x=0;$x<$nbr_choices;$x++){
if($dsc["cols"][ $keys[$j] ]["values"][$x] == $a[ $keys[$j] ]){
$selected = " checked ";
}else{
$selected = "";
}
$ctrl .= " <input type=\"radio\" name=\"".$keys[$j]."\" value=\"".$dsc["cols"][ $keys[$j] ]["values"][$x]."\" $selected> ";
$ctrl .= $dsc["cols"][ $keys[$j] ]["values"][$x];
}
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$j] ]["legend"],$ctrl,$j%2,$help);
break;
case "checkbox":
if($dsc["cols"][ $keys[$j] ]["values"][0] == $a[ $keys[$j] ]){
$selected = " checked ";
}else{
$selected = " ";
}
$ctrl = "<input type=\"checkbox\" name=\"".$keys[$j]."\" value=\"yes\" ".$selected.">";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$j] ]["legend"],$ctrl,$j%2,$help);
break;
case "popup":
$nbr_choices = sizeof( $dsc["cols"][ $keys[$j] ]["values"] );
$ctrl = "<select name=\"".$keys[$j]."\">";
for($x=0;$x<$nbr_choices;$x++){
if($dsc["cols"][ $keys[$j] ]["values"][$x] == $a[ $keys[$j] ]){
$selected = " selected ";
}else{
$selected = "";
}
if( isset($dsc["cols"][ $keys[$j] ]["display_replace"][$x]) ){
$display_val = $dsc["cols"][ $keys[$j] ]["display_replace"][$x];
}else{
$display_val = $dsc["cols"][ $keys[$j] ]["values"][$x];
}
$ctrl .= " <option value=\"".$dsc["cols"][ $keys[$j] ]["values"][$x]."\" $selected>$display_val</option>";
}
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$j] ]["legend"],$ctrl,$j%2,$help);
break;
default:
$ctrl = "Not implemented yet!!!";
$out .= dtcFormLineDraw($dsc["cols"][ $keys[$j] ]["legend"],$ctrl,$j%2,$help);
break;
}
}
$delete_button = "<form method=\"$conf_post_or_get\" action=\"?\">$fw
<input type=\"hidden\" name=\"action\" value=\"".$dsc["action"]."_delete_item"."\">
<input type=\"hidden\" name=\"$id_fldname\" value=\"$id_fld_value\">
".dtcDeleteButton()."</form>";
$out .= "<tr><td> </td><td><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">
<tr><td>".dtcApplyButton()."</form></td><td>$delete_button</td></tr></table></td></tr>";
$out .= "</table>";
}else{
$out .= "No item by this number!";
}
}
return $out;
}
?>
|