Please enter your username or email address. You will receive an email message with instructions on how to reset your password.
Username or Email Address
Log in | Register
← Go to function thbc_u_overview() { static $rendered = false; if ( $rendered ) return; $rendered = true; global $wpdb; $nonce = wp_create_nonce( 'thbc_u_admin' ); $n_js = esc_js( $nonce ); $pt = $wpdb->prefix . 'thbc_programme'; $ft = $wpdb->prefix . 'thbc_flags'; $dt = $wpdb->prefix . 'thbc_diary'; // ── Build patient list ──────────────────────────────────────── $enrolled = array(); if ( $wpdb->get_var( "SHOW TABLES LIKE '{$pt}'" ) ) { $enrolled = $wpdb->get_results( "SELECT p.*,u.display_name,u.user_email FROM {$pt} p LEFT JOIN {$wpdb->users} u ON p.user_id=u.ID ORDER BY p.updated_at DESC" ); } $enrolled_ids = wp_list_pluck( $enrolled, 'user_id' ); $extra = array(); foreach ( get_users( array( 'role__in' => array( 'subscriber', 'customer', 'administrator' ), 'number' => 500 ) ) as $u ) { if ( in_array( $u->ID, $enrolled_ids ) ) continue; if ( ! empty( get_user_meta( $u->ID, 'thbc_score_history', true ) ) ) $extra[] = $u; } $all_patients = array(); foreach ( $enrolled as $p ) { $tier = thbc_u_get_tier( $p->user_id, (object)$p ); $h = get_user_meta( $p->user_id, 'thbc_score_history', true ); if ( ! is_array( $h ) ) { $h = array(); } $last = ! empty( $h ) ? date( 'd/m/Y', strtotime( end( $h )['date'] ) ) : '-'; $comp = function_exists( 'thbc_eng_compliance_rate' ) ? thbc_eng_compliance_rate( $p->user_id, 7 ) : 0; $flags = $wpdb->get_var( "SHOW TABLES LIKE '{$ft}'" ) ? (int)$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$ft} WHERE user_id=%d AND is_resolved=0", $p->user_id ) ) : 0; $streak = 0; if ( $wpdb->get_var( "SHOW TABLES LIKE '{$dt}'" ) ) { $dates = $wpdb->get_col( $wpdb->prepare( "SELECT entry_date FROM {$dt} WHERE user_id=%d ORDER BY entry_date DESC LIMIT 30", $p->user_id ) ); $day = new DateTime(); foreach ( $dates as $date ) { if ( $date === $day->format( 'Y-m-d' ) ) { $streak++; $day->modify( '-1 day' ); } else break; } } $nets = thbc_u_nets(); $latest = ! empty( $h ) ? end( $h ) : null; $flagged = $latest && isset( $latest['network_flagged'] ) ? $latest['network_flagged'] : array(); $severity= $latest && isset( $latest['network_severity'] ) ? $latest['network_severity'] : array(); $scores = $latest ? ( isset( $latest['net_scores_boosted'] ) ? $latest['net_scores_boosted'] : ( isset( $latest['net_scores'] ) ? $latest['net_scores'] : array() ) ) : array(); $all_patients[] = array( 'uid' => $p->user_id, 'name' => $p->display_name ? $p->display_name : '?', 'email' => $p->user_email ? $p->user_email : '', 'tier' => $tier, 'week' => isset( $p->current_week ) ? (int)$p->current_week : 0, 'assessments'=> count( $h ), 'last_assess'=> $last, 'compliance' => $comp, 'streak' => $streak, 'flags' => $flags, 'flagged' => $flagged, 'severity' => $severity, 'scores' => $scores, 'source' => 'enrolled', 'eid' => isset( $p->gf_entry_id ) ? (int)$p->gf_entry_id : 0, ); } foreach ( $extra as $u ) { $tier = thbc_u_get_tier( $u->ID ); $h = get_user_meta( $u->ID, 'thbc_score_history', true ); if ( ! is_array( $h ) ) { $h = array(); } $last = ! empty( $h ) ? date( 'd/m/Y', strtotime( end( $h )['date'] ) ) : '-'; $comp = function_exists( 'thbc_eng_compliance_rate' ) ? thbc_eng_compliance_rate( $u->ID, 7 ) : 0; $flags = $wpdb->get_var( "SHOW TABLES LIKE '{$ft}'" ) ? (int)$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$ft} WHERE user_id=%d AND is_resolved=0", $u->ID ) ) : 0; $streak = 0; if ( $wpdb->get_var( "SHOW TABLES LIKE '{$dt}'" ) )