public function render_admin(){ if (!current_user_can('manage_options')) return; global $wpdb; $ti = $this->table(self::DB_INSTALLS); $ts = $this->table(self::DB_SUBS); $exists_i = (bool)$wpdb->get_var("SHOW TABLES LIKE '{$ti}'"); $exists_s = (bool)$wpdb->get_var("SHOW TABLES LIKE '{$ts}'"); $count_i = $exists_i ? (int)$wpdb->get_var("SELECT COUNT(*) FROM {$ti}") : 0; $count_s = $exists_s ? (int)$wpdb->get_var("SELECT COUNT(*) FROM {$ts}") : 0; $missing = $exists_s ? (int)$wpdb->get_var("SELECT COUNT(*) FROM {$ts} WHERE (install_id IS NULL OR install_id=0)") : 0; echo '
'.$count_i.' ('.($exists_i?'table OK':'table MISSING').') · Subs: '.$count_s.' ('.($exists_s?'table OK':'table MISSING').')';
echo '';
echo 'Terdapat '.$missing.' subscription tanpa install_id. ';
echo 'Backfill missing installs';
echo '
Export CSV '; echo 'Settings
'; // Cari & paginate $q = isset($_GET['q']) ? sanitize_text_field($_GET['q']) : ''; $tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'installs'; $page = max(1, intval($_GET['paged'] ?? 1)); $per = 50; $off = ($page-1)*$per; echo ''; $nonce = wp_create_nonce('agro_pwa_bulk_delete'); if ($tab === 'installs'){ $where = '1=1'; $params = []; if ($q) { $where .= " AND (ip LIKE %s OR user_agent LIKE %s OR device_hint LIKE %s)"; $like = '%'.$wpdb->esc_like($q).'%'; $params = [$like,$like,$like]; } $total = $exists_i ? (int)$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$ti} WHERE $where", $params)) : 0; $rows = $exists_i ? $wpdb->get_results($wpdb->prepare("SELECT * FROM {$ti} WHERE $where ORDER BY install_time DESC LIMIT %d OFFSET %d", $per, $off)) : []; echo ''; for ($i=1;$i<=$pages;$i++){ $url = add_query_arg(['page'=>'agro-pwa-users','tab'=>'installs','q'=>$q,'paged'=>$i], admin_url('admin.php')); echo ($i==$page) ? "$i" : "$i"; } echo '
'; } } else { $where = '1=1'; $params = []; if ($q) { $where .= " AND (ip LIKE %s OR endpoint LIKE %s OR fcm_token LIKE %s)"; $like = '%'.$wpdb->esc_like($q).'%'; $params = [$like,$like,$like]; } $total = $exists_s ? (int)$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$ts} WHERE $where", $params)) : 0; $rows = $exists_s ? $wpdb->get_results($wpdb->prepare("SELECT * FROM {$ts} WHERE $where ORDER BY created_at DESC LIMIT %d OFFSET %d", $per, $off)) : []; echo ''; for ($i=1;$i<=$pages;$i++){ $url = add_query_arg(['page'=>'agro-pwa-users','tab'=>'subs','q'=>$q,'paged'=>$i], admin_url('admin.php')); echo ($i==$page) ? "$i" : "$i"; } echo '
'; } $rest_push = esc_url(rest_url(self::NS.'/pwa/push-test')); echo ""; } echo '