/usr/share/knowledgeroot/include/class-knowledgeroot.php is in knowledgeroot 0.9.9.5-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 | <?php
/**
* This Class inherits functions for easier work
*
* @package Knowledgeroot
* @author Frank Habermann
* @version $Id: class-knowledgeroot.php 684 2009-04-03 22:08:42Z lordlamer $
*/
class knowledgeroot {
/**
* @param array $CLASS reference to global CLASS var
*/
var $CLASS;
/**
* @param array $tree_right_cache cache for rights in tree
*/
var $tree_right_cache = array();
/**
* @param array $content_right_cache cache for rigths in content
*/
var $content_right_cache = array();
/**
* @param array $user_right_cache cache for rights in user
*/
var $user_right_cache = array();
/**
* @param array $user_group_cache cache for rights in group
*/
var $user_group_cache = array();
/**
* @param array $group_cache cache for group
*/
var $group_cache = array();
/**
* @param array $groups_cache cache for groups
*/
var $groups_cache = array();
/**
* @param array $recursiv_page_perm_cache cache for recursiv page rights
*/
var $recursiv_page_perm_cache = array();
/**
* @param array $inerhitpagerights_cache cache for interhitpagerights
*/
var $inerhitpagerights_cache = array();
/**
* @param array $userdropdowncache cache for userdropdown
*/
var $userdropdowncache = null;
/**
* @param array $groupdropdowncache cache for groupdropdown
*/
var $groupdropdowncache = null;
/**
* init/start class
* @param array &$CLASS reference to global CLASS var
*/
function start(&$CLASS) {
$this->CLASS =& $CLASS;
}
/**
* FROM Typo3
* AddSlash array
* This function traverses a multidimentional array and adds slashes to the values.
* NOTE that the input array is and argument by reference.!!
* Twin-function to stripSlashesOnArray
* Usage: 8
*
* @param array Multidimensional input array, (REFERENCE!)
* @return array
*/
function addSlashesOnArray(&$theArray) {
if(get_magic_quotes_gpc() == 0) {
if (is_array($theArray)) {
reset($theArray);
while(list($Akey,$AVal)=each($theArray)) {
if (is_array($AVal)) {
$this->addSlashesOnArray($theArray[$Akey]);
} else {
$theArray[$Akey] = addslashes($AVal);
}
}
reset($theArray);
}
}
}
/**
* return rightpanel for new content or page
* @param integer $userid
* @return string return rightpanel as html
*/
function rightpanel($userid = "") {
// check if user have rights to set rights
if(empty($userid)) {
// user have no rights to see the panel
return "";
}
$res = $this->CLASS['db']->squery("SELECT u.id as uid, g.id as gid, u.name as user,g.name as ".$this->CLASS['db']->quoteIdentifier("group").", u.defaultrights as rights, u.rightedit as rightedit FROM users u, groups g WHERE g.id=u.defaultgroup AND u.id=%d",$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
if($row['rightedit'] == 0) {
return "";
}
}
// get user dropdowns
$users = $this->userSelectDropDown("user",$row['uid']);
$musers = $this->userSelectDropDown("users[{ID}]");
// get group dropdowns
$groups = $this->groupSelectDropDown("group",$row['gid']);
$mgroups = $this->groupSelectDropDown("groups[{ID}]");
if(strlen($row['rights']) == 3) {
$userright = substr($row['rights'],0,1);
$groupright = substr($row['rights'],1,1);
$otherright = substr($row['rights'],2,1);
// Userrechte Dropdown
$userrights = $this->rightDropDown("userrights",$userright);
$muserrights = $this->rightDropDown("muserrights[{ID}]");
// Gruppenrechte Dropdown
$grouprights = $this->rightDropDown("grouprights",$groupright);
$mgrouprights = $this->rightDropDown("mgrouprights[{ID}]");
// Otherrechte Dropdown
$otherrights = $this->rightDropDown("otherrights",$otherright);
}
$userrightsline = "<tr id=\"multiplerights_{ID}\"><td>".T_('user')."</td><td style=\"padding:2px 2px 2px 2px;\">".$musers."</td><td>".T_('userrights')."</td><td>".$muserrights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"rights.delRightLine({ID})\" /></td></tr>";
$grouprightsline = "<tr id=\"multiplerights_{ID}\"><td>".T_('group')."</td><td style=\"padding:2px 2px 2px 2px;\">".$mgroups."</td><td>".T_('grouprights')."</td><td>".$mgrouprights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"rights.delRightLine({ID})\" /></td></tr>";
$userrightsline = str_replace("\n","", $userrightsline);
$grouprightsline = str_replace("\n","", $grouprightsline);
$out = "";
$out .= '
<script language="javascript" type="text/javascript">
var rights = {
counter: 0,
addUserRightLine: function () {
var line = '."'".$userrightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("rightpaneladdmultiplerights", line);
},
addGroupRightLine: function () {
var line = '."'".$grouprightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("rightpaneladdmultiplerights", line);
},
delRightLine: function(id) {
removeElement("multiplerights_"+id);
}
}
</script>
';
$out .= "<div class=\"rightpanel\" style=\"padding:10px 0px 0px 0px;\">\n";
$out .= '
<table style="border: 1px solid #000000;" border="0" cellspacing="1" cellpadding="1" width="600">
<tr><td>'.T_('user').':</td><td style="padding:2px 2px 2px 2px;">' . $users . '</td><td>'.T_('userrights').':</td><td>' . $userrights . '</td></tr>
<tr><td>'.T_('group').':</td><td>' . $groups . '</td><td>'.T_('grouprights').':</td><td>' . $grouprights . '</td></tr>
<tr><td colspan="2"> </td><td>'.T_('otherrights').':</td><td>' . $otherrights . '</td></tr>
<tr id="rightpaneladdmultiplerights"><td colspan="4" align="center"><input class="button" onclick="rights.addUserRightLine();" type="button" name="adduserrights" value="'.T_('Add Userrights').'" /> <input class="button" onclick="rights.addGroupRightLine();" type="button" name="addgrouprights" value="'.T_('Add Grouprights').'" /></td></tr>
</table>
';
$out .= "</div>\n";
return $out;
}
/**
* show rightpanel with subinherit rights
* @param integer $userid id of user
* @return string return html
*/
function rightpanelsubinherit($userid = "") {
// check if user have rights to set rights
if(empty($userid)) {
// user have no rights to see the panel
return "";
} else {
$res = $this->CLASS['db']->squery("SELECT u.id as uid, g.id as gid, u.name as user,g.name as ".$this->CLASS['db']->quoteIdentifier("group").", u.defaultrights as rights, u.rightedit as rightedit FROM users u, groups g WHERE g.id=u.defaultgroup AND u.id=%d",$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
if($row['rightedit'] == 0) {
return "";
}
}
}
// get user dropdowns
$users = $this->userSelectDropDown("subinherituser",$row['uid']);
$musers = $this->userSelectDropDown("subinheritusers[{ID}]");
// get group dropdowns
$groups = $this->groupSelectDropDown("subinheritgroup",$row['gid']);
$mgroups = $this->groupSelectDropDown("subinheritgroups[{ID}]");
if(strlen($row['rights']) == 3) {
$userright = substr($row['rights'],0,1);
$groupright = substr($row['rights'],1,1);
$otherright = substr($row['rights'],2,1);
// Userrechte Dropdown
$userrights = $this->rightDropDown("subinherituserrights",$userright);
$muserrights = $this->rightDropDown("subinheritmuserrights[{ID}]");
// Gruppenrechte Dropdown
$grouprights = $this->rightDropDown("subinheritgrouprights",$groupright);
$mgrouprights = $this->rightDropDown("subinheritmgrouprights[{ID}]");
// Otherrechte Dropdown
$otherrights = $this->rightDropDown("subinheritotherrights",$otherright);
}
$userrightsline = "<tr id=\"subinheritmultiplerights_{ID}\"><td>".T_('user')."</td><td style=\"padding:2px 2px 2px 2px;\">".$musers."</td><td>".T_('userrights')."</td><td>".$muserrights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"subinheritrightsjs.delRightLine({ID})\" /></td></tr>";
$grouprightsline = "<tr id=\"subinheritmultiplerights_{ID}\"><td>".T_('group')."</td><td style=\"padding:2px 2px 2px 2px;\">".$mgroups."</td><td>".T_('grouprights')."</td><td>".$mgrouprights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"subinheritrightsjs.delRightLine({ID})\" /></td></tr>";
$userrightsline = str_replace("\n","", $userrightsline);
$grouprightsline = str_replace("\n","", $grouprightsline);
$out = "";
$out .= '
<script language="javascript" type="text/javascript">
var subinheritrightsjs = {
counter: 0,
addUserRightLine: function () {
var line = '."'".$userrightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("subinheritrightpaneladdmultiplerights", line);
},
addGroupRightLine: function () {
var line = '."'".$grouprightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("subinheritrightpaneladdmultiplerights", line);
},
delRightLine: function(id) {
removeElement("subinheritmultiplerights_"+id);
}
}
</script>
';
$out .= "<input type=\"checkbox\" name=\"subinheritrights\" value=\"1\" />".T_('enable inherit rights for subpages and contents')."<br />\n";
$out .= "<input type=\"checkbox\" name=\"subinheritrightseditable\" value=\"1\" />".T_('enable edit of rights for these pages and contents')."<br />\n";
$out .= "<input type=\"checkbox\" name=\"subinheritrightsdisable\" value=\"1\" />".T_('disable inherit rights for subpages and contents')."<br />\n";
$out .= "<div class=\"rightpanel\" style=\"padding:10px 0px 0px 0px;\">\n";
$out .= '
<table style="border: 1px solid #000000;" border="0" cellspacing="1" cellpadding="1" width="600">
<tr><td>'.T_('user').':</td><td style="padding:2px 2px 2px 2px;">' . $users . '</td><td>'.T_('userrights').':</td><td>' . $userrights . '</td></tr>
<tr><td>'.T_('group').':</td><td>' . $groups . '</td><td>'.T_('grouprights').':</td><td>' . $grouprights . '</td></tr>
<tr><td colspan="2"> </td><td>'.T_('otherrights').':</td><td>' . $otherrights . '</td></tr>
<tr id="subinheritrightpaneladdmultiplerights"><td colspan="4" align="center"><input class="button" onclick="subinheritrightsjs.addUserRightLine();" type="button" name="subinheritadduserrights" value="'.T_('Add Userrights').'" /> <input class="button" onclick="subinheritrightsjs.addGroupRightLine();" type="button" name="subinheritaddgrouprights" value="'.T_('Add Grouprights').'" /></td></tr>
</table>
';
$out .= "</div>\n";
return $out;
}
/**
* return panel with dropdowns to set rights
* @param string $table tablename
* @param integer $belongsto
* @param integer $userid
* @param integer $groupid
* @param integer $rights
* @param integer $recursiv
* @return string return rightpanel as html
*/
function editRightPanel($table,$belongsto,$userid,$groupid,$rights,$recursiv = 0) {
//if(empty($userid)) {
if($userid == "") {
// you have no rights
return "";
}
$res = $this->CLASS['db']->squery("SELECT rightedit FROM users WHERE id=%d",$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
}
if($_SESSION['rightedit'] != 1 && $_SESSION['admin'] == 0) {
//you have no rights
return "";
}
//user
$users = $this->userSelectDropDown("user",$userid);
$musers = $this->userSelectDropDown("users[{ID}]");
//group
$groups = $this->groupSelectDropDown("group",$groupid);
$mgroups = $this->groupSelectDropDown("groups[{ID}]");
//userrights
$userrights = $this->rightDropDown("userrights",substr($rights,0,1));
//grouprights
$grouprights = $this->rightDropDown("grouprights",substr($rights,1,1));
//otherrights
$otherrights = $this->rightDropDown("otherrights",substr($rights,2,1));
$muserrights = $this->rightDropDown("muserrights[{ID}]");
$mgrouprights = $this->rightDropDown("mgrouprights[{ID}]");
$recursivhtml = '';
if($recursiv == 1) {
$recursivhtml = "<tr><td colspan=\"4\">".T_('set recursiv')."? \n";
$recursivhtml .= "<select name=\"recursiv\">\n";
$recursivhtml .= "\t<option value=\"\">".T_('no')."</option>\n";
$recursivhtml .= "\t<option value=\"1\">".T_('yes')."</option>\n";
$recursivhtml .= "</select>\n";
$recursivhtml .= "</td></tr>\n";
}
$multiplerights = "";
$multiplerightsid = 0;
$userrightsline = "<tr id=\"multiplerights_{ID}\"><td>".T_('user')."</td><td style=\"padding:2px 2px 2px 2px;\">".$musers."</td><td>".T_('userrights')."</td><td>".$muserrights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"rights.delRightLine({ID})\" /></td></tr>";
$grouprightsline = "<tr id=\"multiplerights_{ID}\"><td>".T_('group')."</td><td style=\"padding:2px 2px 2px 2px;\">".$mgroups."</td><td>".T_('grouprights')."</td><td>".$mgrouprights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"rights.delRightLine({ID})\" /></td></tr>";
$userrightsline = str_replace("\n","", $userrightsline);
$grouprightsline = str_replace("\n","", $grouprightsline);
// get multiple rights
$mrightsout = "";
$counterid = 0;
$mrights = $this->getMultipleRights($table,$belongsto);
if(is_array($mrights)) {
foreach($mrights as $key => $value) {
// check if right is for user
if($value['owner_group'] == "o") {
$mrightsout .= "<tr id=\"multiplerights_".$counterid."\"><td>".T_('user')."</td><td style=\"padding:2px 2px 2px 2px;\">".$this->userSelectDropDown("users[".$counterid."]",$value['owner_group_id'])."</td><td>".T_('userrights')."</td><td>".$this->rightDropDown("muserrights[".$counterid."]",$value['rights'])." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"rights.delRightLine(".$counterid.")\" /></td></tr>\n";
}
// check if right is for group
if($value['owner_group'] == "g") {
$mrightsout .= "<tr id=\"multiplerights_".$counterid."\"><td>".T_('group')."</td><td style=\"padding:2px 2px 2px 2px;\">".$this->groupSelectDropDown("groups[".$counterid."]",$value['owner_group_id'])."</td><td>".T_('grouprights')."</td><td>".$this->rightDropDown("mgrouprights[".$counterid."]",$value['rights'])." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"rights.delRightLine(".$counterid.")\" /></td></tr>\n";
}
// inc counterid
$counterid++;
}
}
$out = "";
$out .= '
<script language="javascript" type="text/javascript">
var rights = {
counter: '.$counterid.',
addUserRightLine: function () {
var line = '."'".$userrightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("rightpaneladdmultiplerights", line);
},
addGroupRightLine: function () {
var line = '."'".$grouprightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("rightpaneladdmultiplerights", line);
},
delRightLine: function(id) {
removeElement("multiplerights_"+id);
}
}
</script>
';
$out .= "<div class=\"rightpanel\" style=\"padding:10px 0px 0px 0px;\">\n";
$out .= '
<table style="border: 1px solid #000000;" border="0" cellspacing="1" cellpadding="1" width="600">
<tr><td>'.T_('user').':</td><td style="padding:2px 2px 2px 2px;">' . $users . '</td><td>'.T_('userrights').':</td><td>' . $userrights . '</td></tr>
<tr><td>'.T_('group').':</td><td>' . $groups . '</td><td>'.T_('grouprights').':</td><td>' . $grouprights . '</td></tr>
<tr><td colspan="2"> </td><td>'.T_('otherrights').':</td><td>' . $otherrights . '</td></tr>
'.$mrightsout.'
<tr id="rightpaneladdmultiplerights"><td colspan="4" align="center"><input class="button" onclick="rights.addUserRightLine();" type="button" name="adduserrights" value="'.T_('Add Userrights').'" /> <input class="button" onclick="rights.addGroupRightLine();" type="button" name="addgrouprights" value="'.T_('Add Grouprights').'" /></td></tr>
'.$recursivhtml.'
</table>
';
$out .= "</div>\n";
return $out;
}
/**
* return panel with dropdowns to set rights
* @param string $table
* @param integer $belongsto
* @param integer $subinheritrights
* @param integer $subinheritsrightsenable
* @param integer $subinheritsrightsdisable
* @param integer $userid
* @param integer $groupid
* @param integer $subuserrights
* @param integer $subgrouprights
* @param integer $subotherrights
* @return string return rightpanel as html
*/
function editRightPanelSubInherit($table,$belongsto,$subinheritrights,$subinheritsrightsenable,$subinheritsrightsdisable,$userid,$groupid,$subuserrights,$subgrouprights,$subotherrights) {
//if(empty($userid)) {
if((isset($_SESSION['admin']) && $_SESSION['admin'] != 1) || $userid == "") {
// you have no rights
return "";
}
$res = $this->CLASS['db']->squery("SELECT rightedit FROM users WHERE id=%d",$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
}
if($_SESSION['rightedit'] != 1 && $_SESSION['admin'] == 0) {
//you have no rights
return "";
}
//user
$users = $this->userSelectDropDown("subinherituser",$userid);
$musers = $this->userSelectDropDown("subinheritusers[{ID}]");
//group
$groups = $this->groupSelectDropDown("subinheritgroup",$groupid);
$mgroups = $this->groupSelectDropDown("subinheritgroups[{ID}]");
//userrights
$userrights = $this->rightDropDown("subinherituserrights",$subuserrights);
//grouprights
$grouprights = $this->rightDropDown("subinheritgrouprights",$subgrouprights);
//otherrights
$otherrights = $this->rightDropDown("subinheritotherrights",$subotherrights);
$muserrights = $this->rightDropDown("subinheritmuserrights[{ID}]");
$mgrouprights = $this->rightDropDown("subinheritmgrouprights[{ID}]");
if($subinheritrights == 1) $subinheritscheck = "checked=\"checked\" ";
else $subinheritscheck = "";
if($subinheritsrightsenable == 1) $subinheritsenablecheck = "checked=\"checked\" ";
else $subinheritsenablecheck = "";
if($subinheritsrightsdisable == 1) $subinheritsdisablecheck = "checked=\"checked\" ";
else $subinheritsdisablecheck = "";
$multiplerights = "";
$multiplerightsid = 0;
$userrightsline = "<tr id=\"subinheritmultiplerights_{ID}\"><td>".T_('user')."</td><td style=\"padding:2px 2px 2px 2px;\">".$musers."</td><td>".T_('userrights')."</td><td>".$muserrights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"subinheritrights.delRightLine({ID})\" /></td></tr>";
$grouprightsline = "<tr id=\"subinheritmultiplerights_{ID}\"><td>".T_('group')."</td><td style=\"padding:2px 2px 2px 2px;\">".$mgroups."</td><td>".T_('grouprights')."</td><td>".$mgrouprights." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"subinheritrights.delRightLine({ID})\" /></td></tr>";
$userrightsline = str_replace("\n","", $userrightsline);
$grouprightsline = str_replace("\n","", $grouprightsline);
// get multiple rights
$mrightsout = "";
$counterid = 0;
$mrights = $this->getMultipleRights($table,$belongsto);
if(is_array($mrights)) {
foreach($mrights as $key => $value) {
// check if right is for user
if($value['owner_group'] == "so") {
$mrightsout .= "<tr id=\"subinheritmultiplerights_".$counterid."\"><td>".T_('user')."</td><td style=\"padding:2px 2px 2px 2px;\">".$this->userSelectDropDown("subinheritusers[".$counterid."]",$value['owner_group_id'])."</td><td>".T_('userrights')."</td><td>".$this->rightDropDown("subinheritmuserrights[".$counterid."]",$value['rights'])." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"subinheritrightsjs.delRightLine(".$counterid.")\" /></td></tr>\n";
}
// check if right is for group
if($value['owner_group'] == "sg") {
$mrightsout .= "<tr id=\"subinheritmultiplerights_".$counterid."\"><td>".T_('group')."</td><td style=\"padding:2px 2px 2px 2px;\">".$this->groupSelectDropDown("subinheritgroups[".$counterid."]",$value['owner_group_id'])."</td><td>".T_('grouprights')."</td><td>".$this->rightDropDown("subinheritmgrouprights[".$counterid."]",$value['rights'])." <img style=\"cursor:pointer\" src=\"images/delete.gif\" alt=\"\" onclick=\"subinheritrightsjs.delRightLine(".$counterid.")\" /></td></tr>\n";
}
// inc counterid
$counterid++;
}
}
$out = "";
$out .= '
<script language="javascript" type="text/javascript">
var subinheritrightsjs = {
counter: '.$counterid.',
addUserRightLine: function () {
var line = '."'".$userrightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("subinheritrightpaneladdmultiplerights", line);
},
addGroupRightLine: function () {
var line = '."'".$grouprightsline."'".';
line = line.replace(/\{ID\}/g, this.counter);
this.counter++;
new Insertion.Before("subinheritrightpaneladdmultiplerights", line);
},
delRightLine: function(id) {
removeElement("subinheritmultiplerights_"+id);
}
}
</script>
';
$out .= "<input type=\"checkbox\" name=\"subinheritrights\" value=\"1\" ".$subinheritscheck."/>".T_('enable inherit rights for subpages and contents')."<br />\n";
$out .= "<input type=\"checkbox\" name=\"subinheritrightseditable\" value=\"1\" ".$subinheritsenablecheck."/>".T_('enable edit of rights for these pages and contents')."<br />\n";
$out .= "<input type=\"checkbox\" name=\"subinheritrightsdisable\" value=\"1\" ".$subinheritsdisablecheck."/>".T_('disable inherit rights for subpages and contents')."<br />\n";
$out .= "<div class=\"rightpanel\" style=\"padding:10px 0px 0px 0px;\">\n";
$out .= '
<table style="border: 1px solid #000000;" border="0" cellspacing="1" cellpadding="1" width="600">
<tr><td>'.T_('user').':</td><td style="padding:2px 2px 2px 2px;">' . $users . '</td><td>'.T_('userrights').':</td><td>' . $userrights . '</td></tr>
<tr><td>'.T_('group').':</td><td>' . $groups . '</td><td>'.T_('grouprights').':</td><td>' . $grouprights . '</td></tr>
<tr><td colspan="2"> </td><td>'.T_('otherrights').':</td><td>' . $otherrights . '</td></tr>
'.$mrightsout.'
<tr id="subinheritrightpaneladdmultiplerights"><td colspan="4" align="center"><input class="button" onclick="subinheritrightsjs.addUserRightLine();" type="button" name="subinheritadduserrights" value="'.T_('Add Userrights').'" /> <input class="button" onclick="subinheritrightsjs.addGroupRightLine();" type="button" name="subinheritaddgrouprights" value="'.T_('Add Grouprights').'" /></td></tr>
</table>
';
$out .= "</div>\n";
return $out;
}
/**
* new function that check page rights with multiple rights
* @param integer $pageid
* @param integer $userid
* @return integer return rights of object
*/
function getPageRights($pageid, $userid) {
$pagerights = $this->_getPageRights($pageid, $userid);
// check if pagerights are already full then return
if($pagerights == 2) return 2;
$mrights = $this->checkMultipleRights($userid, "tree", $pageid);
if($mrights > $pagerights) {
return $mrights;
} else {
return $pagerights;
}
}
/**
* return rights on a page by userid
* @param integer $pageid
* @param integer $userid
* @return integer return rights of object
*/
function _getPageRights($pageid, $userid) {
if(!isset($pageid) || !isset($userid)) {
return 0;
}
// get userrights
if(!isset($this->user_cache_rights[$userid])) {
$res = $this->CLASS['db']->squery("SELECT * FROM users WHERE id=%d AND deleted=0",$userid);
$anz = $this->CLASS['db']->num_rows($res);
// check if user exists, if not - no rights
if($anz == 0 && $userid != 0) {
return 0;
}
// userrow
$rowuser = $this->CLASS['db']->fetch_assoc($res);
// set cache
$this->user_cache_rights[$userid] = $rowuser;
} else {
// get from cache
$rowuser = $this->user_cache_rights[$userid];
}
// check if user is admin, if yes then give full rights
if($rowuser['admin'] == 1) {
return 2;
}
// get pagerights
if(!isset($this->tree_cache_rights[$pageid])) {
$res = $this->CLASS['db']->squery("SELECT * FROM tree WHERE id=%d AND deleted=0",$pageid);
$anz = $this->CLASS['db']->num_rows($res);
// check if page exists, if not - no rights
if($anz == 0) {
return 0;
}
// pagerow
$rowpage = $this->CLASS['db']->fetch_assoc($res);
// set cache
$this->tree_cache_rights[$pageid] = $rowpage;
} else {
// get from cache
$rowpage = $this->tree_cache_rights[$pageid];
}
if($rowpage['owner'] == $rowuser['id']) {
return $rowpage['userrights'];
}
if($rowpage['group'] == $rowuser['defaultgroup']) {
return $rowpage['grouprights'];
}
// check for caching
if(!isset($this->user_group_cache[$userid])) {
$this->user_group_cache[$userid] = array();
$found = 0;
$res = $this->CLASS['db']->squery("SELECT groupid FROM user_group WHERE userid=%d",$userid);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
if($row['groupid'] == $rowpage['group']) {
$found = 1;
}
// set cache
$this->user_group_cache[$userid][] = $row;
}
if($found == 1) return $rowpage['grouprights'];
} else {
if(is_array($this->user_group_cache[$userid])) {
// get from cache
foreach($this->user_group_cache[$userid] as $key => $value) {
if($this->user_group_cache[$userid][$key]['groupid'] == $rowpage['group']) {
return $rowpage['grouprights'];
}
}
}
}
return $rowpage['otherrights'];
}
/**
* new function that check content rights with multiple rights
* @param integer $contentid
* @param integer $userid
* @return integer return rights of object
*/
function getContentRights($contentid, $userid) {
$contentrights = $this->_getContentRights($contentid, $userid);
// check if pagerights are already full then return
if($contentrights == 2) return 2;
$mrights = $this->checkMultipleRights($userid, "content", $contentid);
if($mrights > $contentrights) {
return $mrights;
} else {
return $contentrights;
}
}
/**
* return rights on a content by userid
* @param integer $contentid
* @param integer $userid
* @return integer return rights of object
*/
function _getContentRights($contentid, $userid) {
if(!isset($contentid) || !isset($userid)) {
return 0;
}
// get userrights
if(!isset($this->user_cache_rights[$userid])) {
$res = $this->CLASS['db']->squery("SELECT * FROM users WHERE id=%d AND deleted=0",$userid);
$anz = $this->CLASS['db']->num_rows($res);
// check if user exists, if not - no rights
if($anz == 0 && $userid != 0) {
return 0;
}
// userrow
$rowuser = $this->CLASS['db']->fetch_assoc($res);
// set cache
$this->user_cache_rights[$userid] = $rowuser;
} else {
// get from cache
$rowuser = $this->user_cache_rights[$userid];
}
// check if user is admin, if yes then give full rights
if($rowuser['admin'] == 1) {
return 2;
}
// get contentrights
if(!isset($this->content_cache_rights[$contentid])) {
$res = $this->CLASS['db']->squery("SELECT * FROM content WHERE id=%d AND deleted=0",$contentid);
$anz = $this->CLASS['db']->num_rows($res);
// check if content exists, if not - no rights
if($anz == 0) {
return 0;
}
// pagerow
$rowcontent = $this->CLASS['db']->fetch_assoc($res);
// set cache
$this->content_cache_rights[$contentid] = $rowcontent;
} else {
// get from cache
$rowcontent = $this->content_cache_rights[$contentid];
}
if($rowcontent['owner'] == $rowuser['id']) {
return $rowcontent['userrights'];
}
if($rowcontent['group'] == $rowuser['defaultgroup']) {
return $rowcontent['grouprights'];
}
// check for caching
if(!isset($this->user_group_cache[$userid])) {
$this->user_group_cache[$userid] = array();
$found = 0;
$res = $this->CLASS['db']->squery("SELECT groupid FROM user_group WHERE userid=%d",$userid);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
if($row['groupid'] == $rowcontent['group']) {
$found = 1;
}
// set cache
$this->user_group_cache[$userid][] = $row;
}
if($found == 1) return $rowcontent['grouprights'];
} else {
if(is_array($this->user_group_cache[$userid])) {
// get from cache
foreach($this->user_group_cache[$userid] as $key => $value) {
if($this->user_group_cache[$userid][$key]['groupid'] == $rowcontent['group']) {
return $rowcontent['grouprights'];
}
}
}
}
return $rowcontent['otherrights'];
}
/**
* return yes or no
* @param integer $value
* @return string return yes or no
*/
function yesno($value) {
if($value == "1" || $value == true) {
return T_('yes');
}
return T_('no');
}
/**
* return a yes/no dropdown
* @param string $name name of dropdown
* @param integer $default if yes or no is selected by default
* @return string return html dropdown
*/
function yesnodropdown($name, $default = 0) {
$defaultno = ($default==0) ? " selected" : "";
$defaultyes = ($default==1) ? " selected" : "";
$out = "<select name=\"".$name."\">\n";
$out .= "\t<option value=\"0\"" . $defaultno . ">".T_('no')."</option>\n";
$out .= "\t<option value=\"1\"" . $defaultyes . ">".T_('yes')."</option>\n";
$out .= "</select>\n";
return $out;
}
/**
* return groupname
* @param integer $id id of group
* @return string return name of group
*/
function getGroup($id) {
if($id == "") {
return "";
}
if(!isset($this->group_cache[$id])) {
$res = $this->CLASS['db']->squery("SELECT name FROM groups WHERE id=%d",$id);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
$this->group_cache[$id] = $row;
}
} else {
$row = $this->group_cache[$id];
}
if(!isset($row['name'])) $row['name'] = "";
return $row['name'];
}
/**
* return id of groupname
* @param string $name name of group
* @return integer return id of groupname
*/
function getGroupID($name) {
if($name == "") {
return 0;
}
if(!isset($this->groups_cache[$name])) {
$res = $this->CLASS['db']->squery("SELECT id FROM groups WHERE name='%s'",$name);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
$this->groups_cache[$name] = $row;
return $row['id'];
}
} else {
return $this->groups_cache[$name]['id'];
}
return 0;
}
/**
* returns name of userid
* @param integer $id id of user
* @return string return name of user
*/
function getOwner($id) {
if($id == "") {
return "";
}
$res = $this->CLASS['db']->squery("SELECT name FROM users WHERE id=%d",$id);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
return $row['name'];
}
return "";
}
/**
* returns a dropdown of grouprights
* @param string $name name of dropdown
* @param integer $default id of default group
* @param bool $multiple dropdown is multiple
* @param array $defaultgroups array with defaultgroups that are selected
* @return string return html dropdown
*/
function groupDropDown($name, $default = "", $multiple = false, $defaultgroups = array()) {
if($multiple == true) {
$out = "<select name=\"".$name."\" multiple=\"multiple\" size=\"5\">\"";
} else {
$out = "<select name=\"".$name."\">\"";
}
$res = $this->CLASS['db']->query("SELECT id,name FROM groups");
while($row = $this->CLASS['db']->fetch_assoc($res)) {
if($default == $row['id'] || $this->foundIDinArray($row['id'],$defaultgroups)) {
$out .= "<option value=\"".$row['id']."\" selected>".$row['name']."</option>";
} else {
$out .= "<option value=\"".$row['id']."\">".$row['name']."</option>";
}
}
$out .= "</select>\n";
return $out;
}
/**
* search for id in array
* @param integer $id id that should be found
* @param array $arr array with elements
* @return bool
*/
function foundIDinArray($id,$arr) {
if(!is_array($arr)) {
$arr = array();
}
foreach($arr as $key => $value) {
if($value == $id) {
return true;
}
}
return false;
}
/**
* returns a dropdown with rights
* @param string $name name of dropdown
* @param integer $default rights that are selected
* @return string return html dropdown with rights
*/
function rightDropDown($name,$default = "") {
$out = "<select name=\"".$name."\">\n";
$selected1 = $default == 2 ? "selected" : "";
$selected2 = $default == 1 ? "selected" : "";
$selected3 = $default == 0 ? "selected" : "";
$out .= "\t<option value=\"2\" ".$selected1.">".T_('read+write')."</option>\n";
$out .= "\t<option value=\"1\" ".$selected2.">".T_('read')."</option>\n";
$out .= "\t<option value=\"0\" ".$selected3.">".T_('no rights')."</option>\n";
$out .= "</select>\n";
return $out;
}
/**
* check if a user have recursiv permissions on pageid
* @param integer $pageid id of page
* @param integer $userid id of user
* @return integer return rights (0,1,2)
*/
function checkRecursivPerm($pageid, $userid) {
if($userid == "") {
$userid = 0;
}
if(strlen($pageid) > 0 && strlen($userid) > 0) {
if(!isset($this->recursiv_page_perm_cache[$pageid])) {
$res = $this->CLASS['db']->squery("SELECT id,belongs_to FROM tree WHERE id=%d and deleted=0",$pageid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
$this->recursiv_page_perm_cache[$pageid] = $row;
} else {
return 0;
}
} else {
$row = $this->recursiv_page_perm_cache[$pageid];
}
if($row['belongs_to'] == 0) {
return $this->getPageRights($row['id'],$userid);
} else {
$rights = $this->getPageRights($row['id'],$userid);
if($rights == 0) {
return 0;
} else {
return $this->checkRecursivPerm($row['belongs_to'],$userid);
}
}
}
return 0;
}
/**
* set rights recursiv on pages and content
* @param integer $pageid id of page
* @param integer $userid id of user
* @param integer $user id of user that will be set
* @param integer $group id of group that will be set
* @param integer $rights rights
* @param array $mrights array with multiple rights
* @return bool
*/
function setRightsRecursiv($pageid,$userid,$user,$group,$rights,$mrights = null) {
$userrights = substr($rights,0,1);
$grouprights = substr($rights,1,1);
$otherrights = substr($rights,2,1);
// get multiplerights
if(!is_array($mrights)) {
$mrights = $this->getMultipleRights("tree", $pageid);
}
// set rights for contents
$res = $this->CLASS['db']->squery("SELECT id FROM content WHERE belongs_to=%d AND deleted=0",$pageid);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
if($this->getContentRights($row['id'],$userid) == 2) {
$ressub = $this->CLASS['db']->squery("UPDATE content SET owner=%d, ".$this->CLASS['db']->quoteIdentifier("group")."=%d, userrights=%d, grouprights=%d, otherrights=%d WHERE id=%d",$user,$group,$userrights,$grouprights,$otherrights,$row['id']);
// delete all existing multiple rights on this element
$this->deleteMultipleRightsAll("content", $row['id']);
// set multiple rights on content
foreach($mrights as $key => $value) {
if($value['owner_group'] == "o" || $value['owner_group'] == "g") {
$this->saveMultipleRights("content", $row['id'], $value['owner_group'], $value['owner_group_id'], $value['rights']);
}
}
}
}
// set rights for subpages
$res = $this->CLASS['db']->squery("SELECT id FROM tree WHERE belongs_to=%d AND deleted=0",$pageid);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
if($this->getPageRights($row['id'],$userid) == 2) {
$ressub = $this->CLASS['db']->squery("UPDATE tree SET owner=%d, ".$this->CLASS['db']->quoteIdentifier("group")."=%d, userrights=%d, grouprights=%d, otherrights=%d WHERE id=%d",$user,$group,$userrights,$grouprights,$otherrights,$row['id']);
// delete all existing multiple rights on this element
$this->deleteMultipleRightsAll("tree", $row['id']);
// set multiple rights on content
foreach($mrights as $key => $value) {
$this->saveMultipleRights("tree", $row['id'], $value['owner_group'], $value['owner_group_id'], $value['rights']);
}
$this->setRightsRecursiv($row['id'],$userid,$user,$group,$rights, $mrights);
}
}
return true;
}
/**
* replace values from $arr1 with the values in arr2
* @param array $arr1
* @param array $arr2
* @return array
*/
function replace_array($arr1, $arr2) {
foreach($arr2 as $key => $value) {
if(is_array($arr2[$key])) {
if(isset($arr1[$key])) $arr1[$key] = $this->replace_array($arr1[$key],$arr2[$key]);
else $arr1[$key] = $this->replace_array("",$arr2[$key]);
} else {
$arr1[$key] = $value;
}
}
return $arr1;
}
/**
* IMPORTET FROM TYPO3
* Wrapping a string.
* Implements the TypoScript "wrap" property.
* Example: $content = "HELLO WORLD" and $wrap = "<b> | </b>", result: "<b>HELLO WORLD</b>"
*
* @param string The content to wrap
* @param string The wrap value, eg. "<b> | </b>"
* @param string The char used to split the wrapping value, default is "|"
* @return string Wrapped input string
* @see noTrimWrap()
*/
function setWrap($content = "",$wrap = "",$char = "|") {
if ($wrap) {
// fix for || replacings
$wrap = str_replace('||', '[NOT_TO_BE_REPLACED]', $wrap);
$wrapArr = explode($char, $wrap);
$content = $wrapArr[0].$content.$wrapArr[1];
$content = str_replace('[NOT_TO_BE_REPLACED]', '||', $content);
return $content;
} else return $content;
}
/**
* check for alias and returns a good alias
* @param string $alias
* @return string
*/
function checkAlias($alias) {
// replace all chars that are not a-z A-Z 0-9
$alias = preg_replace("/[^a-zA-Z0-9]*/s","",$alias);
$res = $this->CLASS['db']->squery("SELECT count(*) AS anz FROM tree WHERE alias='%s' AND deleted=0",$alias);
$row = $this->CLASS['db']->fetch_assoc($res);
$x = 0;
while($row['anz'] >= 1) {
$x++;
$alias_new = $alias . $x;
$res = $this->CLASS['db']->squery("SELECT count(*) AS anz FROM tree WHERE alias='%s' AND deleted=0",$alias_new);
$row = $this->CLASS['db']->fetch_assoc($res);
}
if($x == 0) {
return $alias;
} else {
return $alias_new;
}
}
/**
* create array from path and set value
* @param array &$arr
* @param string $path
* @param string $value
*/
function createArr(&$arr, $path, $value) {
$p =& $arr;
$path_arr = explode(".",$path);
foreach($path_arr as $key) {
$key = trim($key);
if(!isset($p[$key])) {
$p[$key] = array();
}
$p =& $p[$key];
}
$p = trim($value);
unset($p);
}
/**
* save config value with a path
* @param string $path
* @param string $value
*/
function setConfig($path,$value) {
$path_arr = explode(".", $path);
if($path_arr[0] == "db") {
return "";
}
$res = $this->CLASS['db']->squery("SELECT id FROM settings WHERE name='%s'",$path);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$res = $this->CLASS['db']->squery("UPDATE settings SET name='%s', value='%s' WHERE name='%s'",$path,$value,$path);
} else {
$res = $this->CLASS['db']->squery("INSERT INTO settings (name, value) VALUES ('%s', '%s')",$path,$value);
}
}
/**
* get configvalue from a path
* @param string $path
* @return string
*/
function getConfig($path) {
$res = $this->CLASS['db']->squery("SELECT value FROM settings WHERE name='%s'",$path);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
return $row['value'];
} else {
return "";
}
}
/**
* save array to config
* @param array $arr
* @param string $path
*/
function setConfigArr($arr, $path = "") {
$path = $path == "" ? "" : $path . ".";
foreach($arr as $key => $value) {
// db should not be converted
if($key == "db" && $path == "") {
continue;
}
if(is_array($arr[$key])) {
$this->setConfigArr($arr[$key], $path.$key);
} else {
$name = $path . $key;
$this->setConfig($name, $value);
}
}
}
/**
* get config as array with path
* @param string $path
* @return array
*/
function getConfigArr($path = "") {
$CONFIG = array();
$res = $this->CLASS['db']->query("SELECT * FROM settings");
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$this->createArr($CONFIG, $row['name'], $row['value']);
}
if($path == "") {
return $CONFIG;
}
$p =& $CONFIG;
$path_arr = explode(".", $path);
foreach($path_arr as $key) {
$key = trim($key);
if(!isset($p[$key])) {
$p[$key] = array();
}
$p =& $p[$key];
}
return $p;
}
/**
* delete a config value with a path
* @param string $path
* @param bool $recursiv
*/
function delConfig($path, $recursiv = false) {
if($recursiv == true) {
$res = $this->CLASS['db']->squery("DELETE FROM settings WHERE name like '%s%%'",$path);
} else {
$res = $this->CLASS['db']->squery("DELETE FROM settings WHERE name='%s'",$path);
}
}
/**
* mark content as opened
* @param integer $contentid
* @param integer $userid
*/
function openContent($contentid, $userid) {
$this->clearOpenContent();
if(strlen($contentid) > 0 && strlen($userid) > 0) {
$time = time();
if(sprintf("%d",$userid) == "0") {
$userid = session_id();
} else {
//echo "##";
}
$res = $this->CLASS['db']->squery("SELECT id FROM content_open WHERE contentid=%d AND userid='%s'",$contentid,$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz != 0) {
$res = $this->CLASS['db']->squery("UPDATE content_open SET opened=%d WHERE contentid=%d and userid='%s'",$time,$contentid,$userid);
} else {
$res = $this->CLASS['db']->squery("INSERT INTO content_open (contentid, userid, opened) VALUES (%d, '%s', %d)",$_GET['eid'],$userid,$time);
}
}
}
/**
* close opened contents
* @param integer $contentid
* @param integer $userid
*/
function closeOpenContent($contentid, $userid) {
$this->clearOpenContent();
if(sprintf("%d",$userid) == "0") {
$userid = session_id();
}
if(strlen($contentid) > 0 && strlen($userid) > 0) {
$res = $this->CLASS['db']->squery("DELETE FROM content_open WHERE contentid=%d AND userid='%s'",$contentid,$userid);
}
}
/**
* clear old opened contents
*/
function clearOpenContent() {
$timeout = 1800;
$time = time() - $timeout;
$res = $this->CLASS['db']->squery("DELETE FROM content_open WHERE opened <= %d",$time);
}
/**
* show if content is already opened by other user
* @param integer $contentid
* @param integer $userid
* @return bool
*/
function isOpenContent($contentid, $userid) {
$this->clearOpenContent();
if(strlen($contentid) > 0 && strlen($userid) > 0) {
if(sprintf("%d",$userid) == "0") {
$userid = session_id();
}
$res = $this->CLASS['db']->squery("SELECT id FROM content_open WHERE contentid=%d AND userid!='%s'",$contentid,$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz > 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* returns an array with rights if the pageid should inherit rights - if not it returns false
* @param integer $pageid
* @return array will return false if no rights are found
*/
function getInheritRights($pageid) {
if($this->isInheritRights($pageid)) {
// check internal cache that was build by function isInheritRights
if(isset($this->inerhitpagerights_cache[$pageid]) && is_array($this->inerhitpagerights_cache[$pageid])) {
$row = $this->inerhitpagerights_cache[$pageid];
if($row['subinheritrights'] == 1) {
return $row;
} elseif($row['subinheritrightsdisable'] == 1) {
return $row;
} else {
return $this->getInheritRights($row['belongs_to']);
}
}
}
return false;
}
/**
* return true or false if the pageid should inherit rights
* @param integer $pageid
* @return bool
*/
function isInheritRights($pageid) {
if(isset($this->inerhitpagerights_cache[$pageid]) && is_array($this->inerhitpagerights_cache[$pageid])) {
$row = $this->inerhitpagerights_cache[$pageid];
if($row['subinheritrights'] == 1) {
return true;
} elseif($row['subinheritrightsdisable'] == 1) {
return false;
} else {
if($pageid != 0) {
return $this->isInheritRights($row['belongs_to']);
}
}
} else {
$res = $this->CLASS['db']->squery("SELECT id, belongs_to, subinheritrights, subinheritrightseditable, subinheritrightsdisable, subinheritowner, subinheritgroup, subinherituserrights, subinheritgrouprights, subinheritotherrights FROM tree WHERE id=%d AND deleted=0",$pageid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
$this->inerhitpagerights_cache[$pageid] = $row;
if($row['subinheritrights'] == 1) {
return true;
} elseif($row['subinheritrightsdisable'] == 1) {
return false;
} else {
if($pageid != 0) {
return $this->isInheritRights($row['belongs_to']);
}
}
}
}
return false;
}
/**
* This function will return environment variables
*
* This function was used from typo3 and was modified
*
* @param string $name name of the environment
* @return string value of this environment
*/
function getEnv($name) {
switch((string)$name) {
case 'SCRIPT_NAME':
return (php_sapi_name()=='cgi'||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) ? ($_SERVER['ORIG_PATH_INFO']?$_SERVER['ORIG_PATH_INFO']:$_SERVER['PATH_INFO']) : ((isset($_SERVER['ORIG_SCRIPT_NAME']) && $_SERVER['ORIG_SCRIPT_NAME'])?$_SERVER['ORIG_SCRIPT_NAME']:$_SERVER['SCRIPT_NAME']);
break;
case 'SCRIPT_FILENAME':
return str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME'])));
break;
case 'REQUEST_URI':
// Typical application of REQUEST_URI is return urls, forms submitting to itself etc. Example: returnUrl='.rawurlencode($this->getIndpEnv('REQUEST_URI'))
if (!$_SERVER['REQUEST_URI']) { // This is for ISS/CGI which does not have the REQUEST_URI available.
return '/'.ereg_replace('^/','',$this->getEnv('SCRIPT_NAME')).
($_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:'');
} else return $_SERVER['REQUEST_URI'];
break;
case 'PATH_INFO':
// $_SERVER['PATH_INFO']!=$_SERVER['SCRIPT_NAME'] is necessary because some servers (Windows/CGI) are seen to set PATH_INFO equal to script_name
// Further, there must be at least one '/' in the path - else the PATH_INFO value does not make sense.
// IF 'PATH_INFO' never works for our purpose in TYPO3 with CGI-servers, then 'php_sapi_name()=='cgi'' might be a better check. Right now strcmp($_SERVER['PATH_INFO'],$this->getIndpEnv('SCRIPT_NAME')) will always return false for CGI-versions, but that is only as long as SCRIPT_NAME is set equal to PATH_INFO because of php_sapi_name()=='cgi' (see above)
// if (strcmp($_SERVER['PATH_INFO'],$this->getIndpEnv('SCRIPT_NAME')) && count(explode('/',$_SERVER['PATH_INFO']))>1) {
if (php_sapi_name()!='cgi'&&php_sapi_name()!='cgi-fcgi') {
return $_SERVER['PATH_INFO'];
} else return '';
break;
// These are let through without modification
case 'REMOTE_ADDR':
case 'REMOTE_HOST':
case 'HTTP_REFERER':
case 'HTTP_HOST':
case 'HTTP_USER_AGENT':
case 'HTTP_ACCEPT_LANGUAGE':
case 'QUERY_STRING':
return $_SERVER[$getEnvName];
break;
case 'DOCUMENT_ROOT':
// Some CGI-versions (LA13CGI) and mod-rewrite rules on MODULE versions will deliver a 'wrong' DOCUMENT_ROOT (according to our description). Further various aliases/mod_rewrite rules can disturb this as well.
// Therefore the DOCUMENT_ROOT is now always calculated as the SCRIPT_FILENAME minus the end part shared with SCRIPT_NAME.
$SFN = $this->getEnv('SCRIPT_FILENAME');
$SN_A = explode('/',strrev($this->getEnv('SCRIPT_NAME')));
$SFN_A = explode('/',strrev($SFN));
$acc = array();
while(list($kk,$vv)=each($SN_A)) {
if (!strcmp($SFN_A[$kk],$vv)) {
$acc[] = $vv;
} else break;
}
$commonEnd=strrev(implode('/',$acc));
if (strcmp($commonEnd,'')) { $DR = substr($SFN,0,-(strlen($commonEnd)+1)); }
return $DR;
break;
case 'HOST_ONLY':
$p = explode(':',$_SERVER['HTTP_HOST']);
return $p[0];
break;
case 'PORT':
$p = explode(':',$_SERVER['HTTP_HOST']);
return $p[1];
break;
case 'REQUEST_HOST':
return ($this->getEnv('SSL') ? 'https://' : 'http://').
$_SERVER['HTTP_HOST'];
break;
case 'REQUEST_URL':
return $this->getEnv('REQUEST_HOST').$this->getEnv('REQUEST_URI');
break;
case 'REQUEST_SCRIPT':
return $this->getEnv('REQUEST_HOST').$this->getEnv('SCRIPT_NAME');
break;
case 'REQUEST_DIR':
return $this->getEnv('REQUEST_HOST').$this->dirname($this->getEnv('SCRIPT_NAME')).'/';
break;
case 'SITE_URL':
if (defined('PATH_thisScript') && defined('PATH_site')) {
$lPath = substr(dirname(PATH_thisScript),strlen(PATH_site)).'/';
$url = $this->getEnv('REQUEST_DIR');
$siteUrl = substr($url,0,-strlen($lPath));
if (substr($siteUrl,-1)!='/') $siteUrl.='/';
return $siteUrl;
} else return '';
break;
case 'SITE_SCRIPT':
return substr($this->getEnv('REQUEST_URL'),strlen($this->getEnv('SITE_URL')));
break;
case 'SSL':
return (isset($_SERVER['SSL_SESSION_ID']) && $_SERVER['SSL_SESSION_ID']) || (isset($_SERVER['HTTPS']) && !strcmp($_SERVER['HTTPS'],'on')) ? TRUE : FALSE;
break;
case '_ALL_':
$out = array();
// Here, list ALL possible keys to this function for debug display.
$envTestVars = explode(',','HTTP_HOST,HOST_ONLY,PORT,PATH_INFO,QUERY_STRING,REQUEST_URI,HTTP_REFERER,REQUEST_HOST,REQUEST_URL,REQUEST_SCRIPT,REQUEST_DIR,SITE_URL,SITE_SCRIPT,SSL,SCRIPT_NAME,DOCUMENT_ROOT,SCRIPT_FILENAME,REMOTE_ADDR,REMOTE_HOST,HTTP_USER_AGENT,HTTP_ACCEPT_LANGUAGE');
foreach($envTestVars as $key => $v) {
$out[trim($v)]=$this->getEnv(trim($v));
}
reset($out);
return $out;
break;
}
}
/**
* FROM TYPO3
* Returns the directory part of a path without trailing slash
* If there is no dir-part, then an empty string is returned.
* Behaviour:
*
* '/dir1/dir2/script.php' => '/dir1/dir2'
* '/dir1/' => '/dir1'
* 'dir1/script.php' => 'dir1'
* 'd/script.php' => 'd'
* '/script.php' => ''
* '' => ''
* Usage: 5
*
* @param string Directory name / path
* @return string Processed input value. See function description.
*/
function dirname($path) {
$p=$this->revExplode('/',$path,2);
return count($p)==2?$p[0]:'';
}
/**
* FROM TYPO3
* Reverse explode which explodes the string counting from behind.
* Thus t3lib_div::revExplode(':','my:words:here',2) will return array('my:words','here')
* Usage: 8
*
* @param string Delimiter string to explode with
* @param string The string to explode
* @param integer Number of array entries
* @return array Exploded values
*/
function revExplode($delim, $string, $count=0) {
$temp = explode($delim,strrev($string),$count);
while(list($key,$val)=each($temp)) {
$temp[$key]=strrev($val);
}
$temp=array_reverse($temp);
reset($temp);
return $temp;
}
/**
* save multiple rights to table access
* @param string $table tablename
* @param integer $belongs_to id to that the rights belongs
* @param string $owner_group owner or group as o or g
* @param integer $owner_group_id id of owner or group
* @param integer $rights rights for that id - could be 0, 1, 2
* @return boolean return bool or resultset of sqlquery
*/
function saveMultipleRights($table_name, $belongs_to, $owner_group, $owner_group_id, $rights) {
// first check if rights for this user/group exists on this id on this table
$res = $this->CLASS['db']->squery("SELECT id,rights FROM access WHERE table_name='%s' AND belongs_to=%d AND owner_group='%s' AND owner_group_id=%d",$table_name, $belongs_to, $owner_group, $owner_group_id);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
// check if rights are different - if not no update is needed
if($row['rights'] != $rights) {
$res = $this->CLASS['db']->squery("UPDATE access SET rights=%d WHERE table_name='%s' AND belongs_to=%d AND owner_group='%s' AND owner_group_id=%d",$rights,$table_name, $belongs_to, $owner_group, $owner_group_id);
return $res;
} else {
return true;
}
} else {
$res = $this->CLASS['db']->squery("INSERT INTO access (table_name, belongs_to, owner_group, owner_group_id, rights) VALUES ('%s', %d, '%s', %d, %d)",$table_name, $belongs_to, $owner_group, $owner_group_id, $rights);
return $res;
}
return false;
}
/**
* save multiple rights to table access with array
*
* array must contain the following elements
* $arr[1] = array(
* 'table_name' => 'name',
* 'belongs_to' => 'id',
* 'owner_group' => 'o',
* 'owner_group_id' => 'id',
* 'rights' => '2',
* );
*
* @param array $arr multiple rights as array
* @return array return bool or result in each array element
*/
function saveMultipleRightsArr($arr) {
if(is_array($arr)) {
$arr_out = array();
foreach($arr as $key => $value) {
if(isset($value['table_name']) && isset($value['belongs_to']) && isset($value['owner_group']) && isset($value['owner_group_id']) && isset($value['rights'])) {
$arr_out[$key] = $this->saveMultipleRights($value['table_name'],$value['belongs_to'],$value['owner_group'],$value['owner_group_id'],$value['rights']);
} else {
$arr_out[$key] = false;
}
}
return $arr_out;
} else {
return false;
}
}
/**
* delete all existing multiple rights for an object
* @param string $table_name name of table
* @param integer $belongsto id of object
* @return resource return resultset of query
*/
function deleteMultipleRightsAll($table_name, $belongs_to) {
// clear old rights
$res = $this->CLASS['db']->squery("DELETE FROM access WHERE table_name='%s' AND belongs_to=%d",$table_name, $belongs_to);
return $res;
}
/**
* delete multiple rights from table access
*/
function deleteMultipleRights($table_name, $belongs_to, $owner_group, $owner_group_id) {
$res = $this->CLASS['db']->squery("DELETE FROM access WHERE table_name='%s' AND belongs_to=%d AND owner_group='%s' AND owner_group_id=%d",$table_name, $belongs_to, $owner_group, $owner_group_id);
return $res;
}
/**
* get all rights for an element
* @param string $table tablename
* @param integer $belongsto id of element
* @return array array with all rights
*/
function getMultipleRights($table, $belongsto) {
$out = array();
$res = $this->CLASS['db']->squery("SELECT * FROM access WHERE table_name='%s' AND belongs_to=%d",$table,$belongsto);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$out[] = $row;
}
return $out;
}
/**
* check rights for an user on element
* @param integer $userid id of user
* @param string $table tablename
* @param integer $belongsto id of element
* @return integer will return rights on element (0,1,2)
*/
function checkMultipleRights($userid, $table, $belongsto) {
// default rights for user - no rights
$rights = 0;
// get rights from element
$element = $this->getMultipleRights($table,$belongsto);
// array with id of groups
$groupids = array();
// get default groupid from user
$res = $this->CLASS['db']->squery("SELECT admin,defaultgroup FROM users WHERE id=%d AND deleted=0",$userid);
$anz = $this->CLASS['db']->num_rows($res);
if($anz == 1) {
$row = $this->CLASS['db']->fetch_assoc($res);
// check if admin then return 2
if($row['admin'] == 1) return 2;
$groupids[$row['defaultgroup']] = $row['defaultgroup'];
}
// get group ids
$res = $this->CLASS['db']->squery("SELECT groupid FROM user_group WHERE userid=%d",$userid);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$groupids[$row['groupid']] = $row['groupid'];
}
// now check the rights
foreach($element as $key => $value) {
// check if rights are for owner or for group
if($value['owner_group'] == "o") {
// check if id of element is id of user
if($value['owner_group_id'] == $userid) {
// rights are for this user
// now set rights if they are not high enough
if($value['rights'] > $rights) {
// set new rights
$rights = $value['rights'];
}
}
} elseif($value['owner_group'] == "g") {
// now we must run for every groupid for this user to check the rights
foreach($groupids as $gkey => $gvalue) {
// check if groupid is the same as the rightid
if($gvalue == $value['owner_group_id']) {
// now set rights if they are not high enough
if($value['rights'] > $rights) {
// set new rights
$rights = $value['rights'];
}
}
}
}
}
return $rights;
}
/**
* return dropdown for users
* @param string $name name of dropdown
* @param integer $userid optional userid that would be selected
* @return string return html dropdown
*/
function userSelectDropDown($name, $userid = "") {
$cache = array();
if(is_array($this->userdropdowncache)) {
$cache = $this->userdropdowncache;
} else {
$res = $this->CLASS['db']->query("SELECT id,name FROM users WHERE deleted=0 ORDER BY name ASC");
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$cache[$row['id']] = $row['name'];
}
$this->userdropdowncache = $cache;
}
$users = "\n<select name=\"".$name."\">\n";
foreach($cache as $key => $value) {
if($userid != "" && $key == $userid) {
$users .= "\t<option value=\"".$key."\" selected>".$value."</option>\n";
} else {
$users .= "\t<option value=\"".$key."\">".$value."</option>\n";
}
}
$users .= "</select>\n";
return $users;
}
/**
* return dropdown for groups
* @param string $name name of dropdown
* @param integer $groupid optional groupid that would be selected
* @return string return html dropdown
*/
function groupSelectDropDown($name, $groupid = "") {
$cache = array();
if(is_array($this->groupdropdowncache)) {
$cache = $this->groupdropdowncache;
} else {
$res = $this->CLASS['db']->query("SELECT id,name FROM groups WHERE deleted=0 ORDER BY name ASC");
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$cache[$row['id']] = $row['name'];
}
$this->groupdropdowncache = $cache;
}
$groups = "\n<select name=\"".$name."\">\n";
foreach($cache as $key => $value) {
if($groupid != "" && $key == $groupid) {
$groups .= "\t<option value=\"".$key."\" selected>".$value."</option>\n";
} else {
$groups .= "\t<option value=\"".$key."\">".$value."</option>\n";
}
}
$groups .= "</select>\n";
return $groups;
}
/**
* save a form with multiple rights that are sended
* @param string $table table name
* @param integer $belongsto id of object
* @param bool $deleteExisting should exisitings rights are deleted
*/
function saveMultipleRightsForm($table, $belongsto, $deleteExisting = false) {
if (isset ($_SESSION['rightedit']) and $_SESSION['rightedit'] == 1) {
// delete existing rights
if($deleteExisting == true) $this->CLASS['knowledgeroot']->deleteMultipleRightsAll($table,$belongsto);
if(isset($_POST['users']) && isset($_POST['muserrights']) && is_array($_POST['users']) && is_array($_POST['muserrights'])) {
$rights = array();
foreach($_POST['users'] as $key => $value) {
$rights[] = array(
'table_name' => $table,
'belongs_to' => $belongsto,
'owner_group' => 'o',
'owner_group_id' => $value,
'rights' => $_POST['muserrights'][$key],
);
}
$res = $this->CLASS['knowledgeroot']->saveMultipleRightsArr($rights);
}
if(isset($_POST['groups']) && isset($_POST['mgrouprights']) && is_array($_POST['groups']) && is_array($_POST['mgrouprights'])) {
$rights = array();
foreach($_POST['groups'] as $key => $value) {
$rights[] = array(
'table_name' => $table,
'belongs_to' => $belongsto,
'owner_group' => 'g',
'owner_group_id' => $value,
'rights' => $_POST['mgrouprights'][$key],
);
}
$res = $this->CLASS['knowledgeroot']->saveMultipleRightsArr($rights);
}
}
}
/**
* save a form with multiple subinheritrights that are sended
* @param string $table table name
* @param integer $belongsto id of object
* @param bool $deleteExisting should exisitings rights are deleted
*/
function saveSubinheritMultipleRightsForm($table, $belongsto, $deleteExisting = false) {
if (isset ($_SESSION['admin']) and $_SESSION['admin'] == 1) {
// delete existing rights
if($deleteExisting == true) $this->CLASS['knowledgeroot']->deleteMultipleRightsAll($table,$belongsto);
if(isset($_POST['subinheritusers']) && isset($_POST['subinheritmuserrights']) && is_array($_POST['subinheritusers']) && is_array($_POST['subinheritmuserrights'])) {
$rights = array();
foreach($_POST['subinheritusers'] as $key => $value) {
$rights[] = array(
'table_name' => $table,
'belongs_to' => $belongsto,
'owner_group' => 'so',
'owner_group_id' => $value,
'rights' => $_POST['subinheritmuserrights'][$key],
);
}
$res = $this->CLASS['knowledgeroot']->saveMultipleRightsArr($rights);
}
if(isset($_POST['subinheritgroups']) && isset($_POST['subinheritmgrouprights']) && is_array($_POST['subinheritgroups']) && is_array($_POST['subinheritmgrouprights'])) {
$rights = array();
foreach($_POST['subinheritgroups'] as $key => $value) {
$rights[] = array(
'table_name' => $table,
'belongs_to' => $belongsto,
'owner_group' => 'sg',
'owner_group_id' => $value,
'rights' => $_POST['subinheritmgrouprights'][$key],
);
}
$res = $this->CLASS['knowledgeroot']->saveMultipleRightsArr($rights);
}
}
}
/**
* get and save multiplerights from a page to another
* @param string $table
* @param integer $sourceId
* @param integer $destinationId
* @param bool $subinherit should also inherit subinheritrights?
*/
function saveInheritMultipleRightsFrom($table, $sourceId, $destinationId, $subinherit = false) {
$sourceArr = array();
// get rights from source
$res = $this->CLASS['db']->squery("SELECT * FROM access WHERE belongs_to=%d", $sourceId);
while($row = $this->CLASS['db']->fetch_assoc($res)) {
$sourceArr[] = $row;
}
// make addslashes
$this->addSlashesOnArray($sourceArr);
foreach($sourceArr as $key => $value) {
if($subinherit == true) {
if($value['owner_group'] == "so") {
$res = $this->CLASS['db']->squery("INSERT INTO access (table_name, belongs_to, owner_group, owner_group_id, rights) VALUES ('%s', %d, '%s', %d, %d)", $table, $destinationId, "o", $value['owner_group_id'], $value['rights']);
} elseif($value['owner_group'] == "sg") {
$res = $this->CLASS['db']->squery("INSERT INTO access (table_name, belongs_to, owner_group, owner_group_id, rights) VALUES ('%s', %d, '%s', %d, %d)", $table, $destinationId, "g", $value['owner_group_id'], $value['rights']);
}
} else {
if($value['owner_group'] == "o" || $value['owner_group'] == "g") {
$res = $this->CLASS['db']->squery("INSERT INTO access (table_name, belongs_to, owner_group, owner_group_id, rights) VALUES ('%s', %d, '%s', %d, %d)", $table, $destinationId, $value['owner_group'], $value['owner_group_id'], $value['rights']);
}
}
}
}
/**
* get and save subinherit multiple rights from the inheritpage to another page
* @param string $table
* @param integer $sourceId
* @param integer $destinationId
* @param bool $subinherit should also inherit subinheritrights?
*/
function saveSubInheritMultipleRightsFrom($table, $sourceId, $destinationId, $subinherit = false) {
$iRights = $this->getInheritRights($sourceId);
if(is_array($iRights) && isset($iRights['id']) && $iRights['id'] != "") {
return $this->saveInheritMultipleRightsFrom($table, $iRights['id'], $destinationId, $subinherit);
} else {
return $this->saveInheritMultipleRightsFrom($table, $sourceId, $destinationId, $subinherit);
}
}
}
?>
|