function tc_block_players($options) { global $xoopsModule; if ($xoopsModule && $xoopsModule->dirname() == 'team') { global $xoopsModuleConfig; $mc =& $xoopsModuleConfig; } else { $util =& RMUtils::getInstance(); $mc =& $util->moduleConfig('team'); } $db =& XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT * FROM " . $db->prefix("coach_players"); if ($options[0] > 0) { $sql .= " WHERE team='" . $options[0] . "'"; } $sql .= " ORDER BY RAND() LIMIT 0,{$options['1']}"; $result = $db->query($sql); $block = array(); while ($row = $db->fetchArray($result)) { $rtn = array(); $player = new TCPlayer(); $player->assignVars($row); $rtn['link'] = XOOPS_URL . '/modules/team/' . ($mc['urlmode'] ? 'player/' . $player->nameId() . '/' : 'player.php?id=' . $player->id()); $rtn['name'] = $player->name(); $rtn['number'] = $player->number(); $rtn['image'] = $player->image(); $block['players'][] = $rtn; } $block['cols'] = $options[2]; return $block; }
redirect_header(TC_URL, 1, _MS_TC_ERRNOEXISTIS); die; } $xoopsOption['template_main'] = "coach_player.html"; include 'header.php'; $tpl->assign('coach_title', $player->name() . " (#" . $player->number() . ")"); $tpl->assign('lang_comment', _MS_TC_COMMENT); $tpl->assign('lang_data', _MS_TC_DATA); $tpl->assign('lang_name', _MS_TC_NAME); $tpl->assign('lang_number', _MS_TC_NUMBER); $tpl->assign('lang_team', _MS_TC_TEAM); $tpl->assign('lang_age', _MS_TC_AGE); $tpl->assign('lang_date', _MS_TC_DATE); $tpl->assign('lang_bio', _MS_TC_BIO); $tpl->assign('lang_link', _MS_TC_LINK); $link = TC_URL . '/' . ($mc['urlmode'] ? 'player/' . $player->nameId() . '/' : 'player.php?id=' . $player->id()); $tpl->assign('player', array('id' => $player->id(), 'name' => $player->name(), 'image' => $player->image(), 'number' => $player->number(), 'age' => $player->age(), 'date' => formatTimestamp($player->date(), 'c'), 'bio' => $player->bio(), 'link' => $link)); $team = new TCTeam($player->team()); $tpl->assign('xoops_pagetitle', sprintf(_MS_TC_PTITLE, $team->name(), $player->number())); $tlink = TC_URL . '/' . ($mc['urlmode'] ? 't/' . $team->nameId() . '/' : 'team.php?id=' . $team->id()); $location = "<a href='" . TC_URL . "'>" . $xoopsModule->name() . "</a> » <a href='{$tlink}'>" . $team->name() . "</a> » " . $player->name(); $tpl->assign('coach_location', $location); $tpl->assign('team', array('id' => $team->id(), 'name' => $team->name(), 'link' => $tlink)); $tpl->assign('lang_players', sprintf(_MS_TC_PLAYERS, $team->name())); // Integrantes $players = $team->players(true, 'RAND()'); $i = 1; foreach ($players as $player) { if ($i > 4) { break; }
function savePlayer($edit = 0) { global $db, $mc, $xoopsSecurity; $nameid = ''; $teams = array(); $idteam = 0; foreach ($_POST as $k => $v) { ${$k} = $v; } if (!$xoopsSecurity->validateToken()) { redirectMsg('players.php?team=' . $idteam . ($edit ? "&op=edit&id={$id}" : "&op=new"), __('El identificador se sesión ha expirado', 'admin_team'), 1); break; } $idteam = TCFunctions::request('team'); if ($idteam <= 0) { redirectMsg('teams.php', __('No se ha especificado un equipo', 'admin_team'), 1); die; } $team = new TCTeam($idteam); if ($team->isNew()) { redirectMsg('teams.php', __('El equipo especificado no existe', 'admin_team'), 1); die; } if ($edit) { $id = TCFunctions::post('id'); if ($id <= 0) { redirectMsg('players.php?team=' . $idteam, __('No se ha especificado un jugador para editar', 'admin_team'), 1); die; } $player = new TCPLayer($id); if ($player->isNew()) { redirectMsg('players.php?team=' . $idteam, __('El jugador especificado no existe', 'admin_team'), 1); die; } $i = 0; do { $nameid = $nameid != '' && $i == 0 ? $nameid : $util->sweetstring($name) . ($i > 0 ? $i : ''); $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_players") . " WHERE nameid='{$nameid}' AND id_play<>'" . $player->id() . "'"; list($num) = $db->fetchRow($db->query($sql)); $i++; } while ($num > 0); $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_players") . " WHERE name='{$name}' AND id_play<>'" . $player->id() . "'"; list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { redirectMsg('players.php?team=' . $idteam . '&op=edit&id=' . $player->id(), __('Ya existe otro jugador con el mismo nombre', 'admin_team'), 1); die; } } else { $player = new TCPlayer(); $i = 0; do { $nameid = TextCleaner::getInstance()->sweetstring($name) . ($i > 0 ? $i : ''); $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_players") . " WHERE nameid='{$nameid}'"; list($num) = $db->fetchRow($db->query($sql)); $i++; } while ($num > 0); $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_players") . " WHERE name='{$name}'"; list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { redirectMsg('players.php?team=' . $idteam . '&op=new&id=' . $cat->id(), __('Ya existe otro jugador con el mismo nombre', 'admin_team'), 1); die; } } // Cargamos la imágen include_once RMCPATH . '/class/uploader.php'; $up = new RMFileUploader(XOOPS_UPLOAD_PATH . '/teams/players', $mc['filesize'] * 1024, array('jpg', 'png', 'gif')); if ($up->fetchMedia('image')) { if (!$up->upload()) { if ($edit) { redirectMsg('./players.php?team=' . $idteam . '&op=edit&id=' . $player->id(), $up->getErrors(), 1); die; } else { redirectMsg('./players.php?team=' . $idteam . '&op=new', $up->getErrors(), 1); die; } } if ($edit && $player->image() != '') { @unlink(XOOPS_UPLOAD_PATH . '/teams/players/' . $player->image()); @unlink(XOOPS_UPLOAD_PATH . '/teams/players/ths/' . $player->image()); } $filename = $up->getSavedFileName(); $fullpath = $up->getSavedDestination(); // Redimensionamos la imagen $redim = new RMImageResizer($fullpath, $fullpath); $redim->resizeWidth($mc['img_size']); $redim->setTargetFile(XOOPS_UPLOAD_PATH . "/teams/players/ths/{$filename}"); switch ($mc['resize_method']) { case 1: //Recortar miniatura $redim->resizeAndCrop($mc['th_size'], $mc['th_size']); break; case 0: $redim->resizeWidth($mc['th_size']); break; } } else { $filename = $edit ? $player->image() : ''; } $player->setName($name); $player->setNameId($nameid); $player->setBirth($birth); $player->setBio($bio); if (!$edit) { $player->setDate(time()); } $player->setTeam($idteam); $player->setNumber($number); $player->setImage($filename); $player->setVar('dohtml', isset($dohtml) ? 1 : 0); $player->setVar('doxcode', isset($doxcode) ? 1 : 0); $player->setVar('doimage', isset($doimage) ? 1 : 0); $player->setVar('dosmiley', isset($dosmiley) ? 1 : 0); $player->setVar('dobr', isset($dobr) ? 1 : 0); if ($player->save()) { redirectMsg('players.php?team=' . $idteam, __('Base de datos actualizada correctamente', 'admin_team'), 0); } else { redirectMsg('players.php?team=' . $idteam . '&op=' . ($edit ? 'edit&id=' . $player->id() : 'new'), __('Ocurrieron errores al intentar actualizar la base de datos', 'admin_team') . '<br />' . $player->errors(), 0); } }