Пример #1
0
function m_set_score()
{
    global $xoopsSecurity;
    $id = rmc_server_var($_POST, 'id', 0);
    $token = rmc_server_var($_POST, 'token', 0);
    $local = rmc_server_var($_POST, 'local', 0);
    $visitor = rmc_server_var($_POST, 'visitor', 0);
    $other = rmc_server_var($_POST, 'other', 0);
    $comments = rmc_server_var($_POST, 'comments', 0);
    $win = rmc_server_var($_POST, 'win', 0);
    $champ = rmc_server_var($_POST, 'win', 0);
    if ($id <= 0) {
        response_error(__('No role item has been specified!', 'match'));
    }
    if (!$xoopsSecurity->check(true, $token)) {
        response_error(__('Session token expired!', 'match'));
    }
    $item = new MCHRoleItem($id);
    if ($item->isNew()) {
        response_error(__('Specified role item does not exists', 'match'));
    }
    $score = new MCHScoreItem();
    $score->byRole($item->id());
    $score->setVar('item', $id);
    $score->setVar('local', $local);
    $score->setVar('visitor', $visitor);
    $score->setVar('other', $other);
    $score->setVar('comments', $comments);
    $score->setVar('win', $local > $visitor ? $item->getVar('local') : ($visitor > $local ? $item->getVar('visitor') : $win));
    $score->setVAr('champ', $item->getVar('champ'));
    if ($score->save()) {
        $ret = array('done' => 1);
        echo json_encode($ret);
        die;
    } else {
        response_error($score->errors());
    }
}