<?php

require_once 'common.inc.php';
use smtech\StMarksColors as sm;
use Battis\BootstrapSmarty\NotificationMessage;
$toolbox->cache_pushKey(basename(__FILE__, '.php'));
define('STEP_INSTRUCTIONS', 1);
define('STEP_RESULT', 2);
$step = empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step'];
switch ($step) {
    case STEP_RESULT:
        /* make a list of colors */
        $colors = implode('|', sm::all());
        $account = empty($_REQUEST['account']) ? 1 : $_REQUEST['account'];
        if (empty($_REQUEST['account'])) {
            $toolbox->smarty_addMessage('No Account', 'Defaulting to the main account. (This may make things a bit slower.)', NotificationMessage::WARNING);
        }
        if (empty($_REQUEST['term'])) {
            $toolbox->smarty_addMessage('No Term', 'Please select a term for which color blocks should be assigned.', NotificationMessage::ERROR);
            $step = STEP_INSTRUCTIONS;
        } else {
            $affected = array();
            $unaffected = array();
            $parentCourses = $toolbox->cache_get('parent courses');
            if (!$parentCourses) {
                $parentCourses = [];
            }
            $colorAssignments = $toolbox->cache_get('color assignments');
            if (!$colorAssignments) {
                $colorAssignments = [];
            }