connection.php
2 years ago
fapiMemberLoginPage.php
2 years ago
index.php
2 years ago
levelSelection.php
2 years ago
memberList.php
2 years ago
settingsContentAdd.php
2 years ago
settingsContentRemove.php
2 years ago
settingsContentSelect.php
2 years ago
settingsElements.php
2 years ago
settingsEmails.php
2 years ago
settingsLevelNew.php
2 years ago
settingsPages.php
2 years ago
settingsSectionNew.php
2 years ago
settingsSettings.php
2 years ago
settingsUnlocking.php
2 years ago
test.php
2 years ago
memberList.php
142 lines
| 1 | <?php |
| 2 | |
| 3 | global $FapiPlugin; |
| 4 | |
| 5 | use FapiMember\Deprecated\FapiMemberTools; |
| 6 | use FapiMember\Deprecated\FapiLevels; |
| 7 | |
| 8 | $section = get_term($_GET['sectionID']); |
| 9 | ?> |
| 10 | <?php |
| 11 | $user_ids = get_users(['fields' => 'ID']); |
| 12 | $out_ids = []; |
| 13 | foreach ($user_ids as $user_id) { |
| 14 | $metas = get_user_meta($user_id, 'fapi_user_memberships', true); |
| 15 | if (is_array($metas)) { |
| 16 | foreach ($metas as $meta) { |
| 17 | if (isset($meta['level']) && $meta['level'] == $section->term_id) { |
| 18 | $out_ids[] = $user_id; |
| 19 | break; |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | if (!$out_ids) { |
| 26 | echo __('Tato sekce nemá žádné členy', 'fapi-member'); |
| 27 | } else { |
| 28 | if (!class_exists('WP_List_Table')) { |
| 29 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 30 | } |
| 31 | |
| 32 | class Member_Table extends WP_List_Table |
| 33 | { |
| 34 | public $user_ids; |
| 35 | |
| 36 | public function export_csv() |
| 37 | { |
| 38 | $data = array(); |
| 39 | $user_data = array(); |
| 40 | |
| 41 | foreach ($this->user_ids as $user_id) { |
| 42 | $user_data[] = get_userdata($user_id); |
| 43 | } |
| 44 | |
| 45 | foreach ($user_data as $user) { |
| 46 | $data[] = array( |
| 47 | __('Uživatelské jméno', 'fapi-member') => $user->user_login, |
| 48 | __('Jméno a příjmení', 'fapi-member') => $user->first_name . ' ' . $user->last_name, |
| 49 | __('Email', 'fapi-member') => $user->user_email, |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | $output = fopen('php://output', 'w'); |
| 54 | fputcsv($output, array_keys($data[0])); |
| 55 | foreach ($data as $row) { |
| 56 | fputcsv($output, $row); |
| 57 | } |
| 58 | fclose($output); |
| 59 | exit; |
| 60 | } |
| 61 | |
| 62 | public function get_columns() |
| 63 | { |
| 64 | $columns = array( |
| 65 | 'username' => __('Uživatelské jméno', 'fapi-member'), |
| 66 | 'name' => __('Jméno a přijmení', 'fapi-member'), |
| 67 | 'email' => __('Email', 'fapi-member'), |
| 68 | ); |
| 69 | return $columns; |
| 70 | } |
| 71 | |
| 72 | public function prepare_items() |
| 73 | { |
| 74 | |
| 75 | $user_data = array(); |
| 76 | |
| 77 | foreach ($this->user_ids as $user_id) { |
| 78 | $user_data[] = get_userdata($user_id); |
| 79 | } |
| 80 | |
| 81 | $columns = $this->get_columns(); |
| 82 | $pagination = 100; |
| 83 | $this->_column_headers = array($columns); |
| 84 | $this->items = $user_data; |
| 85 | $this->set_pagination_args(array( |
| 86 | 'total_items' => count($user_data), |
| 87 | 'per_page' => $pagination, |
| 88 | )); |
| 89 | |
| 90 | $this->items = array_slice($user_data, ($this->get_pagenum() - 1) * $pagination, $pagination); |
| 91 | } |
| 92 | |
| 93 | public function display_rows() |
| 94 | { |
| 95 | foreach ($this->items as $user) { |
| 96 | echo '<tr>'; |
| 97 | echo '<td>' . $user->user_login . '</td>'; |
| 98 | echo '<td>' . $user->first_name . ' ' . $user->last_name . '</td>'; |
| 99 | echo '<td>'. $user->user_email . '</td>'; |
| 100 | echo '</tr>'; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | public function extra_tablenav($which) |
| 105 | { |
| 106 | if ($which == 'bottom') { |
| 107 | echo '<a class="btn outline" href="' . esc_url(add_query_arg(array('export' => 'csv','noheader'=>'1'))) .'">' . __('Exportovat do CSV', 'fapi-member') . '</a>'; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | $table = new Member_Table(); |
| 112 | $table->user_ids = $out_ids; |
| 113 | $table->prepare_items(); |
| 114 | if (isset($_GET['export']) && $_GET['export'] == 'csv') { |
| 115 | header('Content-Type: text/csv'); |
| 116 | header('Content-Disposition: attachment; filename='.$section->name.'_members.csv'); |
| 117 | header('Pragma: no-cache'); |
| 118 | header('Expires: 0'); |
| 119 | $table->export_csv(); |
| 120 | } |
| 121 | |
| 122 | echo FapiMemberTools::heading(); |
| 123 | |
| 124 | ?> |
| 125 | <div class="page smallerPadding"> |
| 126 | <h3> |
| 127 | <?php |
| 128 | if (empty(get_term_children($section->term_id, FapiLevels::TAXONOMY))) { |
| 129 | echo __('Seznam členů úrovně "' . $section->name . '"', 'fapi-member'); |
| 130 | } else { |
| 131 | echo __('Seznam členů sekce "' . $section->name . '"', 'fapi-member'); |
| 132 | } |
| 133 | ?> |
| 134 | </h3> |
| 135 | <?php |
| 136 | |
| 137 | $table->display(); |
| 138 | } |
| 139 | ?> |
| 140 | </div> |
| 141 | <?php echo FapiMemberTools::help() ?> |
| 142 |