#!/bin/bash

echo "=== Checking Page Templates ==="

ssh roodev@146.190.76.204 << 'ENDSSH'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo "Checking page templates for HVAC pages..."

# Check master dashboard
echo -e "\n--- Master Dashboard ---"
wp db query "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as template FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_wp_page_template' WHERE p.post_name='dashboard' AND p.post_parent=(SELECT ID FROM wp_posts WHERE post_name='master-trainer' AND post_type='page') AND p.post_type='page'"

# Check trainer registration
echo -e "\n--- Trainer Registration ---"
wp db query "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as template FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_wp_page_template' WHERE p.post_name='registration' AND p.post_parent=(SELECT ID FROM wp_posts WHERE post_name='trainer' AND post_type='page') AND p.post_type='page'"

# Check all pages with 'trainer' in the title
echo -e "\n--- All Trainer-Related Pages ---"
wp db query "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as template FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_wp_page_template' WHERE p.post_title LIKE '%trainer%' AND p.post_type='page' ORDER BY p.ID"

echo -e "\n✅ Complete"
ENDSSH