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 '

📱 Agro PWA Tracker v1.6.2

'; echo '
'; echo 'Diagnostik: Installs: '.$count_i.' ('.($exists_i?'table OK':'table MISSING').') · Subs: '.$count_s.' ('.($exists_s?'table OK':'table MISSING').')'; echo '
'; // 🔔 Papar banner backfill di atas SEMUA tab if ($missing > 0){ $bf_url = wp_nonce_url(admin_url('admin-post.php?action=agro_pwa_backfill_installs'), 'agro_pwa_backfill'); echo '

'; echo 'Terdapat '.$missing.' subscription tanpa install_id. '; echo 'Backfill missing installs'; echo '

'; } 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 '
'; echo ''; echo ''; echo ' '; echo ''; 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 '

Installs

'; echo '
'; echo ''; echo ''; echo ''; echo '

'; echo ''; if ($rows){ foreach($rows as $r){ printf('', $r->id, $r->id, $r->wp_user_id ?: '-', esc_html($r->device_hint ?: '-'), esc_html($r->display_mode ?: '-'), esc_html($r->user_agent ?: ''), esc_html($r->install_time), esc_html($r->last_seen ?: ''), esc_html($r->ip ?: '-') ); } } else { echo ''; } echo '
IDWP UserDeviceDisplay ModeUser AgentInstalledLast SeenIP
%d%s%s%s %s %s%s%s
No records
'; echo '

'; echo '
'; $pages = max(1, ceil($total/$per)); if ($pages>1){ 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 '

Push Subscriptions

'; echo '
'; echo ''; echo ''; echo ''; echo '

'; echo ''; if ($rows){ foreach($rows as $s){ $tokDisp = $s->fcm_token ? esc_html(substr($s->fcm_token,0,48)).'…' : '-'; printf('', $s->id, $s->id, $s->install_id ?: '-', $s->wp_user_id ?: '-', $s->revoked ? 'Yes' : 'No', esc_html($s->endpoint ?: ''), $tokDisp, intval($s->receipt_count ?? 0), esc_html($s->last_received ?? ''), esc_html($s->created_at), esc_html($s->last_active ?? ''), esc_html($s->ip ?: '-'), $s->fcm_token ? '' : '-' ); } } else { echo ''; } echo '
IDInstall IDWP UserRevoked EndpointFCM Token ReceiptsLast Received CreatedLast ActiveIP Action
%d%s%s%s %s %s %d%s %s%s%s %s
No records
'; echo '

'; echo '
'; $pages = max(1, ceil($total/$per)); if ($pages>1){ 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 '
'; } https://www.agroternak.com/post-sitemap.xml 2025-10-05T05:45:49+00:00 https://www.agroternak.com/page-sitemap.xml 2025-11-03T07:16:30+00:00 https://www.agroternak.com/product-sitemap.xml 2025-11-07T12:36:39+00:00 https://www.agroternak.com/category-sitemap.xml 2025-10-05T05:45:49+00:00 https://www.agroternak.com/post_tag-sitemap.xml 2025-10-05T05:45:49+00:00 https://www.agroternak.com/product_brand-sitemap.xml 2025-11-07T12:36:39+00:00 https://www.agroternak.com/product_cat-sitemap.xml 2025-11-07T12:36:39+00:00 https://www.agroternak.com/product_tag-sitemap.xml 2025-11-07T12:36:39+00:00 https://www.agroternak.com/author-sitemap.xml 2025-10-15T15:53:54+00:00