/** main entry point for accountmanager (called from admin.php)
 *
 * this routing dispatches the tasks. If a specified task is not
 * recognised, the default task TASK_ACCOUNTS_OVERVIEW is
 * executed. Note that the User Manager and the Group Manager
 * are heavily interconnected. Therefore we use 1 common set
 * of tasks and distinguish between both managers via
 * sets of tasks, e.g. TASK_USER* point to the user manager
 * where TASK_GROUP* lead to the group manager.
 * 
 * @param object &$output collects the html output
 * @return void results are returned as output in $output
 */
function job_accountmanager(&$output)
{
    global $CFG;
    $output->set_helptopic('accountmanager');
    $task = get_parameter_string('task', TASK_ACCOUNTS);
    switch ($task) {
        case TASK_ACCOUNTS:
            show_accounts_intro($output);
            show_accounts_menu($output);
            break;
        case TASK_USERS:
        case TASK_USER_ADD:
        case TASK_USER_DELETE:
        case TASK_USER_EDIT:
        case TASK_USER_ADVANCED:
        case TASK_USER_GROUPS:
        case TASK_USER_GROUPADD:
        case TASK_USER_GROUPDELETE:
        case TASK_USER_GROUPSAVE:
        case TASK_USER_INTRANET:
        case TASK_USER_MODULE:
        case TASK_USER_ADMIN:
        case TASK_USER_PAGEMANAGER:
        case TASK_USER_TREEVIEW:
        case TASK_USER_SAVE:
        case TASK_USER_SAVE_NEW:
            include $CFG->progdir . '/lib/usermanager.class.php';
            $mgr = new UserManager($output);
            if ($mgr->show_parent_menu()) {
                show_accounts_menu($output, TASK_USERS);
            }
            break;
        case TASK_GROUPS:
        case TASK_GROUP_ADD:
        case TASK_GROUP_DELETE:
        case TASK_GROUP_EDIT:
        case TASK_GROUP_SAVE:
        case TASK_GROUP_SAVE_NEW:
            include $CFG->progdir . '/lib/groupmanager.class.php';
            $mgr = new GroupManager($output);
            if ($mgr->show_parent_menu()) {
                show_accounts_menu($output, TASK_GROUPS);
            }
            break;
        case TASK_GROUP_CAPACITY_OVERVIEW:
        case TASK_GROUP_CAPACITY_INTRANET:
        case TASK_GROUP_CAPACITY_MODULE:
        case TASK_GROUP_CAPACITY_ADMIN:
        case TASK_GROUP_CAPACITY_PAGEMANAGER:
        case TASK_GROUP_CAPACITY_SAVE:
            include $CFG->progdir . '/lib/groupmanager.class.php';
            $mgr = new GroupManager($output);
            if ($mgr->show_parent_menu()) {
                show_accounts_menu($output, TASK_GROUPS);
            }
            break;
        default:
            $s = utf8_strlen($task) <= 50 ? $task : utf8_substr($task, 0, 44) . ' (...)';
            $message = t('task_unknown', 'admin', array('{TASK}' => htmlspecialchars($s)));
            $output->add_message($message);
            logger('accountmanager: unknown task: ' . htmlspecialchars($s));
            show_accounts_intro($output);
            show_accounts_menu($output);
            break;
    }
}