<?php
/**
 * Run a command on a frontend
 *
 * @url         $URL: http://svn.mythtv.org/svn/branches/release-0-23-fixes/mythplugins/mythweb/modules/remote/do.php $
 * @date        $Date: 2009-01-22 09:08:37 +0200 (Thu, 22 Jan 2009) $
 * @version     $Revision: 19784 $
 * @author      $Author: kormoc $
 *
 * @package     MythWeb
 * @subpackage  Remote
 *
/**/

    $frontend = $Frontends[$Path[2]];

    if (!isset($frontend)) {
        header('HTTP/1.0 404 Not Found', true, 404);
        die(t('Unknown frontend'));
    }

    $action   = $Path[3];
    $parms    = array_slice($Path, 4);

    switch ($action) {
        case 'SendKey':
            if (!$frontend->send_key($parms[0]))
                header('HTTP/1.0 400 Bad Request', true, 400);
            break;

        case 'PlayProgram':
            if (!$frontend->play_program($parms[0], $parms[1]))
                header('HTTP/1.0 400 Bad Request', true, 400);
            break;

        case 'JumpTo':
            if (!$frontend->send_jump($parms[0]))
                header('HTTP/1.0 400 Bad Request', true, 400);
            break;

        case 'GetLocation':
            echo json_encode($frontend->query_location());
            break;

        case 'GetJumppoints':
            echo json_encode($frontend->get_jump_points());
            break;

        case 'Query':
            echo json_encode($frontend->query($parms[0]));
            break;

        default:
            header('HTTP/1.0 501 Not Implemented', true, 501);
            die(t('Unknown action'));
    }
