예제 #1
0
function m_send_team_data()
{
    $id = rmc_server_var($_GET, 'id', 0);
    if ($id <= 0) {
        response_error(__('No team id has been provided!', 'match'));
    }
    $team = new MCHTeam($id);
    if ($team->isNew()) {
        response_error(__('Specified team does not exists', 'match'));
    }
    $ret = array('id' => $team->id(), 'name' => $team->getVar('name'), 'logo' => MCH_UP_URL . '/' . $team->getVar('logo'));
    echo json_encode($ret);
    die;
}
예제 #2
0
 /**
  * Get results
  */
 public function latest_results($cat = 0, $c = 0, $limit = 0)
 {
     if ($c <= 0) {
         $champ = self::current_championship();
     } else {
         $champ = new MCHChampionship($c);
     }
     if (!is_object($champ)) {
         $champ = self::last_championship();
     }
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     $tbr = $db->prefix("mch_role");
     $tbs = $db->prefix("mch_score");
     $sql = "SELECT a.*, s.item, s.local as loc, s.visitor as vis, s.win, s.champ FROM {$tbr} as a, {$tbs} as s WHERE a.champ='" . $champ->id() . "' AND a.time<" . time();
     if ($cat > 0) {
         $sql .= " AND a.category='" . $cat . "'";
     }
     $sql .= " AND s.item=a.id_role ORDER BY a.time DESC LIMIT 0, {$limit}";
     $result = $db->query($sql);
     $tf = new RMTimeFormatter();
     while ($row = $db->fetchArray($result)) {
         $local = new MCHTeam($row['local']);
         $visitor = new MCHTeam($row['visitor']);
         $category = new MCHCategory($row['category']);
         $field = new MCHField($row['field']);
         $data[] = array('local' => array('id' => $local->id(), 'name' => $local->getVar('name'), 'logo' => XOOPS_UPLOAD_URL . '/teams/' . $local->getVar('logo'), 'score' => $row['loc']), 'visitor' => array('id' => $visitor->id(), 'name' => $visitor->getVar('name'), 'logo' => XOOPS_UPLOAD_URL . '/teams/' . $visitor->getVar('logo'), 'score' => $row['vis']), 'day' => $tf->format($row['time'], __('%M% %d%', 'match')), 'hour' => $tf->format($row['time'], __('%h%:%i%', 'match')), 'category' => array('name' => $category->getVar('name'), 'link' => $category->permalink()), 'field' => $field->getVar('name'), 'win' => $row['win']);
     }
     return $data;
 }
예제 #3
0
function m_save_team($edit = 0)
{
    global $xoopsSecurity, $xoopsModuleConfig;
    $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 : '?action=new&';
    if (!$xoopsSecurity->check()) {
        redirectMsg('teams.php?action=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $query, __('Session token expired!', 'match'), 1);
        die;
    }
    if ($name == '' || $category <= 0) {
        redirectMsg('teams.php?action=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $query, __('Please fill all required data!', 'match'), 1);
    }
    if ($edit) {
        //Verificamos que el trabajo sea válido
        if ($id <= 0) {
            redirectMsg('./teams.php', __('Team ID not valid!', 'match'), 1);
            die;
        }
        //Verificamos que el trabajo exista
        $team = new MCHTeam($id);
        if ($team->isNew()) {
            redirectMsg('./teams.php', __('Specified team does not exists!', 'match'), 1);
            die;
        }
    } else {
        $team = new MCHTeam();
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    // Check if work exists already
    if ($edit) {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("mch_teams") . " WHERE name='{$name}' and category='{$category}' and id_team<>'{$id}'";
    } else {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("mch_teams") . " WHERE name='{$name}' and category='{$category}'";
    }
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        redirectMsg("teams.php" . $action . $query, __('A team with same name already exists!', 'match'), 1);
        die;
    }
    //Genera $nameid Nombre identificador
    $found = false;
    $i = 0;
    if ($name != $team->getVar('name') || empty($nameid)) {
        do {
            $nameid = TextCleaner::sweetstring($name) . ($found ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix('mch_teams') . " WHERE nameid = '{$nameid}'";
            list($num) = $db->fetchRow($db->queryF($sql));
            if ($num > 0) {
                $found = true;
                $i++;
            } else {
                $found = false;
            }
        } while ($found == true);
    }
    $team->setVar('name', $name);
    $team->setVar('nameid', $nameid);
    $team->setVar('info', $info);
    $team->setVar('category', $category);
    $team->setVar('active', $active);
    $team->setVar('created', $created);
    //Logo
    include_once RMCPATH . '/class/uploader.php';
    $folder = XOOPS_UPLOAD_PATH . '/teams';
    if ($edit) {
        $image = $team->getVar('logo');
        $filename = $team->getVar('logo');
    } else {
        $filename = '';
    }
    //Obtenemos el tamaño de la imagen
    $imgSize = $xoopsModuleConfig['logo_size'];
    $up = new RMFileUploader($folder, $xoopsModuleConfig['logo_file_size'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('logo')) {
        if (!$up->upload()) {
            redirectMsg('./teams.php' . $action . $query, $up->getErrors(), 1);
            die;
        }
        if ($edit && $team->getVar('logo') != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/teams/' . $team->getVar('logo'));
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageResizer($fullpath, $fullpath);
        //Redimensionar
        $redim->resizeWidth($imgSize);
    }
    $team->setVar('logo', $filename);
    if (!$team->save()) {
        redirectMsg('./teams.php' . $action . $query, __('Errors ocurred while trying to update database!', 'match') . $team->errors(), 1);
        die;
    } else {
        redirectMsg('./teams.php?id=' . $team->id(), __('Team saved successfully!', 'match'), 0);
        die;
    }
}
예제 #4
0
// Time Formatter
$tf = new RMTimeFormatter(0, __('%M% %d%, %Y%', 'match'));
$xoopsTpl->assign('champ', array('id' => $champ->id(), 'name' => $champ->getVar('name'), 'start' => $tf->format($champ->getVar('start')), 'end' => $tf->format($champ->getVar('end'))));
// Get category
$id_cat = rmc_server_var($_REQUEST, 'cat', 0);
if ($id_cat > 0) {
    $category = new MCHCategory($id_cat);
} else {
    $category = MCHFunctions::first_category();
}
$xoopsTpl->assign('category', array('id' => $category->id(), 'name' => $category->getVar('name'), 'desc' => $category->getVar('description')));
// Get category
$id_team = rmc_server_var($_REQUEST, 'team', 0);
if ($id_team > 0) {
    $team = new MCHTeam($id_team);
    $xoopsTpl->assign('team', array('id' => $team->id(), 'name' => $team->getVar('name'), 'desc' => $team->getVar('info')));
}
// Role
$data = MCHFunctions::next_matches($category->id(), $champ->id(), 0, $id_team);
$xoopsTpl->assign('roleplay', $data);
$categories = array();
MCHFunctions::categories_tree($categories);
foreach ($categories as $k => $cat) {
    $categories[$k]['guion'] = str_repeat("&#151;", $cat['indent']);
}
$xoopsTpl->assign('categories', $categories);
// Championships
$xoopsTpl->assign('champs', MCHFunctions::all_championships());
// Constants
$xoopsTpl->assign('mch_upurl', MCH_UP_URL);
// Labguage