<?php

/**
 * Result Management System for Institutions
 *
 * Copyright (C) 2025 ASTGD
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/**
 * Help Menu File for Result Management System for Institutions Plugin
 *
 * This file is part of the Result Management System for Institutions plugin and is responsible for
 * displaying the help menu content.
 *
 * @package ResultManagementSystem
 * @subpackage Menu_Files_Help
 * @since 1.0.0
 */

if (! defined('ABSPATH')) {
	exit;
}
/**
 * This file is part of the Result Management System for Institutions plugin.
 *
 * It contains the HTML structure for the help section of the plugin.
 *
 * @package ASTGD_Result_Management
 *
 * @section astgdrmsys-help-section
 * This section contains individual help sections within the main container.
 */

?>
<div class="astgdrmsys-help-container">
    <div class="astgdrmsys-help-section">
        <form id="astgdrmsys-help-nonce-form" method="post">
            <?php wp_nonce_field('astgdrmsys_help_nonce', 'astgdrmsys_help_nonce'); ?>
        </form>
        <h2 class="astgdrmsys-help-title">Help & Guide</h2>

        <!-- Section 1: Getting Started -->
        <div class="astgdrmsys-guide-section">
            <h3>Quick Start: Create Your First Exam Result</h3>
            <p>Follow this recipe the first time you publish results. Each step unlocks the next dropdown so your first exam has all the required IDs.</p>
            <ol class="astgdrmsys-step-list">
                <li><strong>Structure</strong>: Add <em>Classes</em>, then <em>Departments</em> under each class, and <em>Sections</em> under each department.</li>
                <li><strong>Exam Framework</strong>: Create <em>Exam Years</em> (e.g., 2024-2025) and <em>Exam Names</em> (Mid-Term/Final). Pick the correct <em>Assessment Type</em> so mark columns match later.</li>
                <li><strong>Subjects</strong>: Add subjects for each class &amp; department; the subject IDs drive the CSV templates.</li>
                <li><strong>Students</strong>: Go to <strong>Add Student Result</strong> to add students manually or import them in bulk (see CSV steps below). Optional/fourth subjects are captured here.</li>
                <li><strong>Marks</strong>: Enter marks via <strong>Add Mark</strong> (single student) or <strong>Insert Mark</strong> (CSV for many students). Use the partial-update CSV when adjusting scores later.</li>
                <li><strong>Publish</strong>: Place <code>[astgdrmsys_show_result]</code> on any page/post to open the front-end search form, then share the saved Result URL from <strong>Settings &rarr; General</strong>.</li>
            </ol>
        </div>

        <!-- Section 2: CSV Import & Templates -->
        <div class="astgdrmsys-import-section">
            <h3 id="import">CSV Templates, Imports &amp; Updates</h3>
            <p>Use CSV files for fast onboarding and later corrections. Download a template before filling data so the column order matches your assessment type and subject list.</p>

            <h4>Where to Download Templates</h4>
            <ul>
                <li><strong>Add Student Result</strong>: Click <em>Download CSV Format</em> for the full student+marks template used for first-time imports.</li>
                <li><strong>Generate CSV</strong>: Open <em>Generate CSV for Bulk Upload</em> to produce a class/department/exam-specific template, or use <em>Generate CSV for Partial Update</em> when you only need to edit existing marks.</li>
            </ul>

            <h4>Import Student Records (Full CSV)</h4>
            <p>The importer expects the columns below in this exact order:</p>
            
            <h4>CSV Column Structure</h4>
            <p>Your CSV file must be structured in four distinct parts, in this exact sequence:</p>
            <ol class="astgdrmsys-column-order">
                <li><strong>Student Information (12 Columns):</strong> Fixed columns from <code>Roll Number</code> to <code>exam_year_id</code>.</li>
                <li><strong>Optional Subject (1 Column):</strong> A single column for the student's chosen <strong>Optional Subject Code</strong>. Leave blank if the student has no optional subject.</li>
                <li><strong>Custom Field Values (Variable Columns):</strong> One column for each custom field label you have configured in <strong>Settings &rarr; Display Name</strong>.</li>
                <li><strong>Subject Marks (Repeating Columns):</strong> The remaining columns are for subject codes and their marks. The format of this section depends on the Exam's "Assessment Type".</li>
            </ol>
			
			<div class="astgdrmsys-import-section">
				<div class="astgdrmsys-help-image help-info-image" aria-label="Help Info" role="img"></div>
				<ul>

					<li>In the CSV file, you'll find a column named Class Id and multiple Subject & Mark columns</li>
					<li>
						<strong>Example:</strong> If a class has ID 2 and two subjects with IDs 3 & 4,
						these subject IDs (3 & 4) will be under Class ID (2)
					</li>
					<div class="astgdrmsys-help-image help-csv-image" aria-label="CSV Import Example" role="img"></div>
				</ul>
			
				<div class="astgdrmsys-import-notes">
					<h4>Important Notes:</h4>
					<ul>
						<li>The Gender field can only be capital 'MALE', 'FEMALE', or 'OTHERS'</li>
						<li>You can add up to 10 Subjects per Student/Class</li>
					</ul>
				</div>
				
				<div class="astgdrmsys-fourth-subject">
					<h3>Fourth Subject Handling</h3>
					<ul>
						<li>When entering marks manually, use the provided option to choose each student's fourth subject. In the <strong>Add Result</strong> page a checkbox is shown for the current subject, and in the <strong>Add Mark</strong> page a radio button lets you select a single fourth subject.</li>
						<li>For CSV imports or updates, include a single <em>Fourth Subject Code</em> column immediately after the <em>Exam Year</em> (column&nbsp;14) that contains the subject code to treat as the student's fourth subject.</li>
					</ul>
				</div>
			</div>

            <h4>Mark Formats by Assessment Type</h4>
            <p>The structure for the mark columns must match the **Assessment Type** you chose when creating the Exam Name.</p>

            <div class="astgdrmsys-import-notes">
                <h5>Single Assessment (2 columns per subject)</h5>
                <p><code>Subject Code</code>, <code>Mark</code></p>
                <em>Example: ...<code>101, 75, 102, 82,</code>...</em>
            </div>

            <div class="astgdrmsys-import-notes">
                <h5>Two-Part Assessment (3 columns per subject)</h5>
                <p><code>Subject Code</code>, <code>Class Test Mark</code>, <code>Final Mark</code></p>
                <em>Example: ...<code>101, 22, 53, 102, 24, 58,</code>...</em>
            </div>

            <div class="astgdrmsys-import-notes">
                <h5>Three-Part Assessment (4 columns per subject)</h5>
                <p><code>Subject Code</code>, <code>Practical Mark</code>, <code>Class Test Mark</code>, <code>Final Mark</code></p>
                <em>Example: ...<code>101, 20, 15, 40, 102, 24, 18, 35,</code>...</em>
            </div>

            <h4>Advanced CSV Import: Overriding Custom Field Names</h4>
            <p>For advanced use, the CSV importer can also accept name/value pairs for custom fields. This allows you to set unique custom field labels for students in a specific import file, overriding the global settings.</p>
            <ul>
                <li>To use this format, provide **two** columns for each custom field: a **Name** column followed by a **Value** column.</li>
                <li>The importer will automatically detect this format. If a "Name" column is left blank, the system will use the default label from settings.</li>
            </ul>
            <em>Example with 2 custom fields: ...<code>Optional Subject Code, Custom Field 1 Name, Custom Field 1 Value, Custom Field 2 Name, Custom Field 2 Value, Subject 1 Code,</code>...</em>

            <h4>Important Notes</h4>
            <ul>
                <li><strong>Always download a fresh template!</strong> The easiest way to get the correct column structure is to use the <strong>Download CSV Format</strong> button on the <strong>Add Student Result</strong> page.</li>
                <li>You can find all necessary IDs (Class, Department, Section, Exam, Subject Code, etc.) on their respective management pages in the plugin menu.</li>
                <li>The <strong>Gender</strong> field must contain one of these exact, capitalized words: 'MALE', 'FEMALE', or 'OTHERS'.</li>
            </ul>

            <h4>Update Existing Marks via CSV</h4>
            <ol class="astgdrmsys-step-list">
                <li>Open <strong>Generate CSV for Partial Update</strong> and download the template for the specific Class/Department/Exam.</li>
                <li>Fill only the mark columns you need to change; keep headers intact.</li>
                <li>Upload the file under <strong>Update Marks &rarr; Update Using CSV</strong> to apply the changes.</li>
            </ol>
        </div>

        <!-- Section 3: Settings and Support -->
        <div class="astgdrmsys-settings-support">
            <div class="astgdrmsys-grade-settings">
                <h3>Teacher Access &amp; User Imports</h3>
                <ul>
                    <li><strong>Enable mark edits for teachers</strong>: Go to <strong>Settings &rarr; General</strong> and check <em>Enable Teacher Mark Update</em>. Teachers will see the CSV mark update form when the option is on.</li>
                    <li><strong>Import teacher accounts</strong>: Use <strong>Users &rarr; Import Users</strong> and the CSV template. Set the <code>role</code> to <code>teacher</code> and list allowed subject codes in the <code>allowed_subjects</code> column to limit their updates.</li>
                </ul>
            </div>

            <div class="astgdrmsys-grade-settings">
                <h3>Grade Settings</h3>
                <p>Go to <strong>Settings &rarr; Grade System</strong> to define the mark ranges for each letter grade (e.g., A+: 80-100). This is essential for calculating GPA and final results.</p>
            </div>

            <div class="astgdrmsys-grade-settings">
                <h3>Display Names &amp; Custom Fields</h3>
                <p>Under <strong>Settings &rarr; Display Name</strong> you can rename labels such as Class, Department, Exam Name, and the mark column headers. You can also add up to five default student custom fields; these labels become the column names in CSV templates when no per-row override is supplied.</p>
            </div>

            <div class="astgdrmsys-grade-settings">
                <h3>Shortcode &amp; Result URL</h3>
                <p>Use <code>[astgdrmsys_show_result]</code> on any page or post to display the search form. In <strong>Settings &rarr; General</strong> you can store the public result page URL and copy it with the provided button for quick sharing.</p>
            </div>

            <div class="astgdrmsys-support-section">
                <h3>Support</h3>
                <p>If you need assistance or have a feature request, please contact us:</p>
                <ul>
                    <li>Email: <strong><a href="mailto:info@astgd.com">info@astgd.com</a></strong></li>
                </ul>
            </div>
        </div>

    </div>
</div>