Exemplo n.º 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());
    }
}
Exemplo n.º 2
0
function m_save_roleitem($edit = 0)
{
    global $xoopsModule, $xoopsModuleConfig, $xoopsSecurity;
    $query = '';
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'action' || $k == 'sbt') {
            continue;
        }
        $query .= $query == '' ? "{$k}=" . urlencode($v) : "&{$k}=" . urlencode($v);
    }
    $action = $edit ? '?action=edit&id=' . $id : '?';
    if (!$xoopsSecurity->check()) {
        redirectMsg('role.php?action=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $query, __('Session token expired!', 'match'), 1);
        die;
    }
    if ($local <= 0 || $visitor <= 0 || $field <= 0 || $date <= 0) {
        redirectMsg('role.php?action=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $query, __('Please fill all required data!', 'match'), 1);
    }
    if ($edit) {
        if ($id <= 0) {
            redirectMsg('./role.php', __('Role item ID not valid!', 'match'), 1);
            die;
        }
        //Verificamos que el trabajo exista
        $item = new MCHRoleItem($id);
        if ($item->isNew()) {
            redirectMsg('./role.php', __('Specified role item does not exists!', 'match'), 1);
            die;
        }
    } else {
        $item = new MCHRoleItem();
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    // Check if work exists already
    if ($edit) {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("mch_role") . " WHERE time='{$time}' AND champ='" . $champ . "' AND id_role<>'{$id}' AND (local='" . $local . "' OR visitor='" . $visitor . "')";
    } else {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("mch_role") . " WHERE time='{$time}' AND champ='" . $champ . "' AND (local='" . $local . "' OR visitor='" . $visitor . "')";
    }
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        redirectMsg("fields.php" . $action . $query, __('A field with same name already exists!', 'match'), 1);
        die;
    }
    $item->setVar('local', $local);
    $item->setVar('visitor', $visitor);
    $item->setVar('time', $date);
    $item->setVar('field', $field);
    $item->setVar('champ', $champ);
    $item->setVar('category', $category);
    if (!$item->save()) {
        redirectMsg('./role.php' . $action . $query, __('Errors ocurred while trying to update database!', 'match') . $item->errors(), 1);
        die;
    } else {
        redirectMsg('./role.php?champ=' . $champ . '&category=' . $category . '&id=' . $item->id(), __('Role item saved successfully!', 'match'), 0);
        die;
    }
}