Changeset 6920 for trunk/reports/inc/class.functions.inc.php
- Timestamp:
- 07/31/12 16:01:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/reports/inc/class.functions.inc.php
r6057 r6920 24 24 'array_invert' => True, 25 25 'Paginate_user' => True, 26 'Paginate_cota' => True, 27 'Paginate_shareAccount' => True, 28 'Paginate_institutionalAccount' => True, 26 29 'Paginate_user_logon' => True, 27 30 'get_list_all' => True, … … 119 122 $result['raw_context'] = $acl[0]['context']; 120 123 121 $all_contexts = preg_split('/%/', $acl[0]['context']);124 $all_contexts = split("%", $acl[0]['context']); 122 125 foreach ($all_contexts as $index=>$context) 123 126 { … … 854 857 } 855 858 859 function get_list_cota_sector($query, $contexts,$sizelimit) 860 { 861 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 862 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 863 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 864 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 865 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 866 ldap_bind($ldap_conn,$dn,$passwd); 867 868 $filter="(|(phpgwAccountType=u)(|(phpgwAccountType=s)))"; 869 $justthese = array("uidnumber", "uid", "cn", "mail","accountstatus","dn","createtimestamp","telephoneNumber"); 870 871 $tmp = array(); 872 873 foreach ($contexts as $index=>$context) 874 { 875 876 $search = ldap_search($ldap_conn, $query, $filter, $justthese, 0, $sizelimit); 877 $info = ldap_get_entries($ldap_conn, $search); 878 879 for ($i=0; $i < $info['count']; $i++) 880 { 881 $tmp[$info[$i]['uid'][0]]['account_id'] = $info[$i]['uidnumber'][0]; 882 $tmp[$info[$i]['uid'][0]]['account_lid'] = $info[$i]['uid'][0]; 883 $tmp[$info[$i]['uid'][0]]['account_cn'] = $info[$i]['cn'][0]; 884 $tmp[$info[$i]['uid'][0]]['account_mail']= $info[$i]['mail'][0]; 885 $tmp[$info[$i]['uid'][0]]['account_phone']= $info[$i]['telephonenumber'][0]; 886 $tmp[$info[$i]['uid'][0]]['account_accountstatus']= $info[$i]['accountstatus'][0]; 887 $tmp[$info[$i]['uid'][0]]['createtimestamp']= $info[$i]['createtimestamp'][0]; 888 $sort[] = $info[$i]['uid'][0]; 889 } 890 } 891 892 ldap_close($ldap_conn); 893 894 if (count($sort)) 895 { 896 natcasesort($sort); 897 foreach ($sort as $user_uid) 898 $return[$user_uid] = $tmp[$user_uid]; 899 } 900 901 return $return; 902 903 } 904 905 906 function get_list_shareAccounts_sector($query, $contexts,$sizelimit) 907 { 908 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 909 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 910 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 911 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 912 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 913 ldap_bind($ldap_conn,$dn,$passwd); 914 915 $filter="(phpgwAccountType=s)"; 916 $justthese = array("uid", "cn", "mail","accountstatus"); 917 918 $tmp = array(); 919 920 foreach ($contexts as $index=>$context) 921 { 922 923 $search = ldap_search($ldap_conn, $query, $filter, $justthese, 0, $sizelimit); 924 $info = ldap_get_entries($ldap_conn, $search); 925 926 for ($i=0; $i < $info['count']; $i++) 927 { 928 $tmp[$info[$i]['uid'][0]]['account_lid'] = $info[$i]['uid'][0]; 929 $tmp[$info[$i]['uid'][0]]['account_cn'] = $info[$i]['cn'][0]; 930 $tmp[$info[$i]['uid'][0]]['account_mail']= $info[$i]['mail'][0]; 931 $tmp[$info[$i]['uid'][0]]['account_accountstatus']= $info[$i]['accountstatus'][0]; 932 $sort[] = $info[$i]['uid'][0]; 933 } 934 } 935 936 ldap_close($ldap_conn); 937 938 if (count($sort)) 939 { 940 natcasesort($sort); 941 foreach ($sort as $user_uid) 942 $return[$user_uid] = $tmp[$user_uid]; 943 } 944 945 return $return; 946 } 947 948 function get_list_institutionalAccounts_sector($query, $contexts,$sizelimit) 949 { 950 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 951 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 952 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 953 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 954 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 955 ldap_bind($ldap_conn,$dn,$passwd); 956 957 $filter="(phpgwAccountType=i)"; 958 $justthese = array("uid", "cn", "mail","accountstatus","mailForwardingAddress"); 959 960 $tmp = array(); 961 962 foreach ($contexts as $index=>$context) 963 { 964 965 $search = ldap_search($ldap_conn, $query, $filter, $justthese, 0, $sizelimit); 966 $info = ldap_get_entries($ldap_conn, $search); 967 968 for ($i=0; $i < $info['count']; $i++) 969 { 970 $tmp[$info[$i]['uid'][0]]['account_cn'] = $info[$i]['cn'][0]; 971 $tmp[$info[$i]['uid'][0]]['account_mail']= $info[$i]['mail'][0]; 972 $tmp[$info[$i]['uid'][0]]['account_accountstatus']= $info[$i]['accountstatus'][0]; 973 $tmp[$info[$i]['uid'][0]]['account_mailforwardingaddress']= $info[$i]['mailforwardingaddress']; 974 $sort[] = $info[$i]['uid'][0]; 975 } 976 } 977 978 ldap_close($ldap_conn); 979 980 if (count($sort)) 981 { 982 natcasesort($sort); 983 foreach ($sort as $user_uid) 984 $return[$user_uid] = $tmp[$user_uid]; 985 } 986 987 return $return; 988 } 989 856 990 function get_count_user_sector($query, $contexts,$sizelimit) 857 991 { … … 871 1005 $entries = ldap_get_entries($ldap_conn, $search); 872 1006 $contexts = array(); 873 for ($i=0; $i< $entries['count']; $i++){874 $contexts[] = $entries[$i]['dn'];875 1007 } 876 1008 } 1009 1010 $filter="(phpgwAccountType=u)"; 1011 $justthese = array("dn"); 1012 $search = ldap_search($ldap_conn, $context, $filter, $justthese, 0, $sizelimit); 1013 $entries = ldap_get_entries($ldap_conn, $search); 1014 $total_count = $entries["count"]; 1015 1016 ldap_close($ldap_conn); 1017 1018 return $total_count; 877 1019 } 878 $filter="(&(phpgwAccountType=u)(|(uid=*)))"; 879 $justthese = array("uidnumber"); 880 $total_count = 0; 881 1020 1021 function get_count_cota_sector($query, $contexts,$sizelimit) 1022 { 1023 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1024 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1025 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1026 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1027 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1028 ldap_bind($ldap_conn,$dn,$passwd); 1029 // counting users by sector. 882 1030 foreach ($contexts as $index=>$context) { 1031 if($context == $GLOBALS['phpgw_info']['server'] ["ldap_context"]) { 1032 $contexts[$index] = null; 1033 $justthese = array("dn"); 1034 $filter="(objectClass=OrganizationalUnit)"; 1035 $search = ldap_list($ldap_conn, $context, $filter, $justthese); 1036 $entries = ldap_get_entries($ldap_conn, $search); 1037 $contexts = array(); 1038 } 1039 } 1040 1041 $filter="(|(phpgwAccountType=u)(|(phpgwAccountType=s)))"; 1042 $justthese = array("dn"); 883 1043 $search = ldap_search($ldap_conn, $context, $filter, $justthese, 0, $sizelimit); 884 $total_count += ldap_count_entries($ldap_conn, $search); 885 } 1044 $entries = ldap_get_entries($ldap_conn, $search); 1045 $total_count = $entries["count"]; 1046 1047 ldap_close($ldap_conn); 1048 1049 return $total_count; 1050 } 1051 1052 function get_count_shareAccount_sector($query, $contexts,$sizelimit) 1053 { 1054 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1055 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1056 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1057 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1058 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1059 ldap_bind($ldap_conn,$dn,$passwd); 1060 // counting users by sector. 1061 foreach ($contexts as $index=>$context) { 1062 if($context == $GLOBALS['phpgw_info']['server'] ["ldap_context"]) { 1063 $contexts[$index] = null; 1064 $justthese = array("dn"); 1065 $filter="(objectClass=OrganizationalUnit)"; 1066 $search = ldap_list($ldap_conn, $context, $filter, $justthese); 1067 $entries = ldap_get_entries($ldap_conn, $search); 1068 $contexts = array(); 1069 } 1070 } 1071 1072 $filter="(phpgwAccountType=s)"; 1073 $justthese = array("dn"); 1074 $search = ldap_search($ldap_conn, $context, $filter, $justthese, 0, $sizelimit); 1075 $entries = ldap_get_entries($ldap_conn, $search); 1076 $total_count = $entries["count"]; 1077 1078 ldap_close($ldap_conn); 1079 1080 return $total_count; 1081 } 1082 1083 function get_count_institutionalAccount_sector($query, $contexts,$sizelimit) 1084 { 1085 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1086 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1087 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1088 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1089 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1090 ldap_bind($ldap_conn,$dn,$passwd); 1091 // counting users by sector. 1092 foreach ($contexts as $index=>$context) { 1093 if($context == $GLOBALS['phpgw_info']['server'] ["ldap_context"]) { 1094 $contexts[$index] = null; 1095 $justthese = array("dn"); 1096 $filter="(objectClass=OrganizationalUnit)"; 1097 $search = ldap_list($ldap_conn, $context, $filter, $justthese); 1098 $entries = ldap_get_entries($ldap_conn, $search); 1099 $contexts = array(); 1100 } 1101 } 1102 1103 $filter="(phpgwAccountType=i)"; 1104 $justthese = array("dn"); 1105 $search = ldap_search($ldap_conn, $context, $filter, $justthese, 0, $sizelimit); 1106 $entries = ldap_get_entries($ldap_conn, $search); 1107 $total_count = $entries["count"]; 1108 886 1109 ldap_close($ldap_conn); 1110 887 1111 return $total_count; 888 1112 } 889 890 function get_list_user_sector_logon($query, $contexts,$sizelimit,$numacesso) 891 { 1113 1114 function get_num_users_sector($query, $contexts) { 892 1115 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 893 1116 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; … … 896 1119 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 897 1120 ldap_bind($ldap_conn,$dn,$passwd); 898 899 $filter="(&(phpgwAccountType=u)(|(uid=*)))"; 1121 1122 $filter="(phpgwAccountType=u)"; 1123 $justthese = array("uidnumber"); 1124 $count = 0; 1125 foreach ($contexts as $index=>$context) { 1126 $search = ldap_search($ldap_conn, $query, $filter, $justthese); 1127 $count+=ldap_count_entries($ldap_conn, $search); 1128 } 1129 return $count; 1130 } 1131 1132 function get_list_user_sector_logon($query, $contexts,$sizelimit,$numacesso) 1133 { 1134 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1135 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1136 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1137 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1138 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1139 ldap_bind($ldap_conn,$dn,$passwd); 1140 1141 $filter="(phpgwAccountType=u)"; 900 1142 $justthese = array("uidnumber", "uid", "cn", "mail","accountstatus","dn","createtimestamp"); 901 1143 … … 1071 1313 function make_lang($ram_lang) 1072 1314 { 1073 $a_lang = preg_split('/_/', $ram_lang);1315 $a_lang = split("_", $ram_lang); 1074 1316 $a_lang_reverse = array_reverse ( $a_lang, true ); 1075 1317 array_pop ( $a_lang_reverse ); … … 1254 1496 ldap_bind($ldap_conn,$dn,$passwd); 1255 1497 1256 $filter="(&(phpgwAccountType=u) (|(uid=*)))";1498 $filter="(&(phpgwAccountType=u))"; 1257 1499 $justthese = array("uidnumber", "uid", "cn", "mail","accountstatus","dn","createtimestamp","telephoneNumber"); 1258 1500 … … 1318 1560 return $sOrder === "desc" ? array_reverse( $aList ) : $aList; 1319 1561 } 1562 1563 function Paginate_cota($type, $query, $contexts, $Field, $Order = 'asc', $Page = null, $PerPage = null ) 1564 { 1565 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1566 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1567 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1568 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1569 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1570 ldap_bind($ldap_conn,$dn,$passwd); 1571 1572 $filter="(|(phpgwAccountType=u)(|(phpgwAccountType=s)))"; 1573 $justthese = array("uidnumber", "uid", "cn", "mail","accountstatus","dn","createtimestamp","telephoneNumber"); 1574 1575 foreach ($contexts as $index=>$context) 1576 { 1577 $search=ldap_search($ldap_conn, $query, $filter, $justthese); 1578 1579 $rConnection = $ldap_conn; 1580 $rSearch = $search; 1581 $sOrder = $Order; 1582 $iPage = $Page; 1583 $iPerPage = $PerPage; 1584 $sField = $Field; 1585 1586 $iTotalEntries = ldap_count_entries( $rConnection, $rSearch ); 1587 1588 if ( $iPage === null || $iPerPage === null ) 1589 { 1590 # fetch all in one page 1591 $iStart = 0; 1592 $iEnd = $iTotalEntries - 1; 1593 } 1594 else 1595 { 1596 # calculate range of page 1597 $iFimPage = ( ceil( $iTotalEntries / $iPerPage ) - 1 ) * $iPage; 1598 1599 $iStart = ( ceil( ($iPage -1) * $iPerPage )); 1600 $iEnd = $iPage * $iPerPage; 1601 1602 1603 if ( $sOrder === "desc" ) 1604 { 1605 # revert range 1606 $iStart = $iTotalEntries - 1 - $iEnd; 1607 $iEnd = $iStart + $iPerPage - 1; 1608 } 1609 } 1610 1611 /********* Importante Mostra o resultado da paginação ********** 1612 var_dump( $iStart . " " . $iEnd ); 1613 ****************** Só descomentar ******************************/ 1614 1615 # fetch entries 1616 ldap_sort( $rConnection, $rSearch, $sField ); 1617 1618 $aList = array(); 1619 for ( 1620 $iCurrent = 0, $rEntry = ldap_first_entry( $rConnection, $rSearch ); 1621 $iCurrent <= $iEnd && is_resource( $rEntry ); 1622 $iCurrent++, $rEntry = ldap_next_entry( $rConnection, $rEntry ) 1623 ) 1624 { 1625 if ( $iCurrent >= $iStart ) 1626 { 1627 array_push( $aList, ldap_get_attributes( $rConnection, $rEntry )); 1628 } 1629 } 1630 } 1631 1632 ldap_close($ldap_conn); 1633 1634 # if order is desc revert page's entries 1635 return $sOrder === "desc" ? array_reverse( $aList ) : $aList; 1636 } 1637 1638 function Paginate_shareAccount($type, $query, $contexts, $Field, $Order = 'asc', $Page = null, $PerPage = null ) 1639 1640 { 1641 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1642 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1643 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1644 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1645 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1646 ldap_bind($ldap_conn,$dn,$passwd); 1647 1648 $filter="(phpgwAccountType=s)"; 1649 $justthese = array("uid", "cn", "mail","accountstatus"); 1650 1651 foreach ($contexts as $index=>$context) 1652 { 1653 $search=ldap_search($ldap_conn, $query, $filter, $justthese); 1654 1655 $rConnection = $ldap_conn; 1656 $rSearch = $search; 1657 $sOrder = $Order; 1658 $iPage = $Page; 1659 $iPerPage = $PerPage; 1660 $sField = $Field; 1661 1662 $iTotalEntries = ldap_count_entries( $rConnection, $rSearch ); 1663 1664 if ( $iPage === null || $iPerPage === null ) 1665 { 1666 # fetch all in one page 1667 $iStart = 0; 1668 $iEnd = $iTotalEntries - 1; 1669 } 1670 else 1671 { 1672 # calculate range of page 1673 $iFimPage = ( ceil( $iTotalEntries / $iPerPage ) - 1 ) * $iPage; 1674 1675 $iStart = ( ceil( ($iPage -1) * $iPerPage )); 1676 $iEnd = $iPage * $iPerPage; 1677 1678 if ( $sOrder === "desc" ) 1679 { 1680 # revert range 1681 $iStart = $iTotalEntries - 1 - $iEnd; 1682 $iEnd = $iStart + $iPerPage - 1; 1683 } 1684 } 1685 1686 # fetch entries 1687 ldap_sort( $rConnection, $rSearch, $sField ); 1688 1689 $aList = array(); 1690 for ( 1691 $iCurrent = 0, $rEntry = ldap_first_entry( $rConnection, $rSearch ); 1692 $iCurrent <= $iEnd && is_resource( $rEntry ); 1693 $iCurrent++, $rEntry = ldap_next_entry( $rConnection, $rEntry ) 1694 ) 1695 { 1696 if ( $iCurrent >= $iStart ) 1697 { 1698 array_push( $aList, ldap_get_attributes( $rConnection, $rEntry )); 1699 } 1700 } 1701 } 1702 1703 ldap_close($ldap_conn); 1704 1705 # if order is desc revert page's entries 1706 return $sOrder === "desc" ? array_reverse( $aList ) : $aList; 1707 } 1708 1709 function Paginate_institutionalAccount($type, $query, $contexts, $Field, $Order = 'asc', $Page = null, $PerPage = null ) 1710 { 1711 $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; 1712 $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; 1713 $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); 1714 ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); 1715 ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); 1716 ldap_bind($ldap_conn,$dn,$passwd); 1717 1718 $filter="(phpgwAccountType=i)"; 1719 $justthese = array("uid", "cn", "mail","accountstatus","mailforwardingaddress"); 1720 1721 foreach ($contexts as $index=>$context) 1722 { 1723 $search=ldap_search($ldap_conn, $query, $filter, $justthese); 1724 1725 $rConnection = $ldap_conn; 1726 $rSearch = $search; 1727 $sOrder = $Order; 1728 $iPage = $Page; 1729 $iPerPage = $PerPage; 1730 $sField = $Field; 1731 1732 $iTotalEntries = ldap_count_entries( $rConnection, $rSearch ); 1733 1734 if ( $iPage === null || $iPerPage === null ) 1735 { 1736 # fetch all in one page 1737 $iStart = 0; 1738 $iEnd = $iTotalEntries - 1; 1739 } 1740 else 1741 { 1742 # calculate range of page 1743 $iFimPage = ( ceil( $iTotalEntries / $iPerPage ) - 1 ) * $iPage; 1744 1745 $iStart = ( ceil( ($iPage -1) * $iPerPage )); 1746 $iEnd = $iPage * $iPerPage; 1747 1748 if ( $sOrder === "desc" ) 1749 { 1750 # revert range 1751 $iStart = $iTotalEntries - 1 - $iEnd; 1752 $iEnd = $iStart + $iPerPage - 1; 1753 } 1754 } 1755 1756 # fetch entries 1757 ldap_sort( $rConnection, $rSearch, $sField ); 1758 1759 $aList = array(); 1760 for ( 1761 $iCurrent = 0, $rEntry = ldap_first_entry( $rConnection, $rSearch ); 1762 $iCurrent <= $iEnd && is_resource( $rEntry ); 1763 $iCurrent++, $rEntry = ldap_next_entry( $rConnection, $rEntry ) 1764 ) 1765 { 1766 if ( $iCurrent >= $iStart ) 1767 { 1768 array_push( $aList, ldap_get_attributes( $rConnection, $rEntry )); 1769 } 1770 } 1771 } 1772 1773 ldap_close($ldap_conn); 1774 1775 # if order is desc revert page's entries 1776 return $sOrder === "desc" ? array_reverse( $aList ) : $aList; 1777 } 1778 1320 1779 1321 1780 function get_list_ou_user_logon($query,$contexts,$sizelimit)
Note: See TracChangeset
for help on using the changeset viewer.