Exemple #1
0
function saveCoach($edit = 0)
{
    global $db, $mc, $xoopsSecurity;
    $nameid = '';
    $teams = array();
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('coachs.php' . ($edit ? "?op=edit&id={$id}" : "?op=new"), __('El identificador de sesión ha expirado', 'admin_team'), 1);
        break;
    }
    if ($edit) {
        $id = TCFunctions::post('id');
        if ($id <= 0) {
            redirectMsg('coachs.php', __('Id no válido', 'admin_team'), 1);
            die;
        }
        $coach = new TCCoach($id);
        if ($coach->isNew()) {
            redirectMsg('coachs.php', __('El entrenador 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_coachs") . " WHERE nameid='{$nameid}' AND id_coach<>'" . $coach->id() . "'";
            list($num) = $db->fetchRow($db->query($sql));
            $i++;
        } while ($num > 0);
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE name='{$name}' AND id_coach<>'" . $coach->id() . "'";
        list($num) = $db->fetchRow($db->query($sql));
        if ($num > 0) {
            redirectMsg('coachs.php?op=edit&id=' . $coach->id(), __('Ya existe un entrenador con ese nombre', 'admin_team'), 1);
            die;
        }
    } else {
        $coach = new TCCoach();
        $i = 0;
        do {
            $nameid = TextCleaner::getInstance()->sweetstring($name) . ($i > 0 ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE nameid='{$nameid}'";
            list($num) = $db->fetchRow($db->query($sql));
            $i++;
        } while ($num > 0);
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE name='{$name}'";
        list($num) = $db->fetchRow($db->query($sql));
        if ($num > 0) {
            redirectMsg('coachs.php?op=new&id=' . $cat->id(), __('Ya existe un entreandor 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/coachs', $mc['filesize'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            if ($edit) {
                redirectMsg('./coachs.php?op=new', $up->getErrors(), 1);
                die;
            } else {
                redirectMsg('./coachs.php?op=edit&id=' . $coach->id(), $up->getErrors(), 1);
                die;
            }
        }
        if ($edit && $coach->image() != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/teams/coachs/' . $coach->image());
            @unlink(XOOPS_UPLOAD_PATH . '/teams/coachs/ths/' . $coach->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/coachs/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 ? $coach->image() : '';
    }
    $coach->setName($name);
    $coach->setNameId($nameid);
    $coach->setBio($bio);
    $coach->setImage($filename);
    $coach->setRole($role);
    $coach->setTeams($teams);
    if (!$edit) {
        $coach->setCreated(time());
    }
    if ($coach->save()) {
        redirectMsg('coachs.php', __('Base de datos actualizada correctamente', 'admin_template'), 0);
    } else {
        redirectMsg('coachs.php?op=' . ($edit ? 'edit&id=' . $coach->id() : 'new'), __('Error al actualizar la base de datos', 'admin_template') . '<br />' . $coach->errors());
    }
}
 /**
  * @desc Devuelve los entrenadores del equipo
  * @return array Objetos {@link TCCoach}
  */
 public function coachs($obj = true)
 {
     if (empty($this->_coachs)) {
         $this->_teams = array();
         $this->_teamsid = array();
         $tbl1 = $this->db->prefix("coach_coachs");
         $tbl2 = $this->db->prefix("coach_teamcoach");
         $sql = "SELECT a.* FROM {$tbl1} a, {$tbl2} b WHERE b.id_team='" . $this->id() . "' AND a.id_coach=b.id_coach";
         $result = $this->db->query($sql);
         while ($row = $this->db->fetchArray($result)) {
             $coach = new TCCoach();
             $coach->assignVars($row);
             $this->_coachs[] = $coach;
             $this->_coachsid[] = $coach->id();
         }
     }
     return $obj ? $this->_coachs : $this->_coachsid;
 }
Exemple #3
0
function formTeams($edit = 0)
{
    global $db, $xoopsModule, $mc, $xoopsConfig;
    if ($edit) {
        $id = TCFunctions::get('id');
        if ($id <= 0) {
            redirectMsg('teams.php', __('Id not valid', 'admin_team'), 1);
            die;
        }
        $team = new TCTeam($id);
        if ($team->isNew()) {
            redirectMsg('teams.php', __('No existe el equipo especificado', 'admin_team'), 1);
            die;
        }
    }
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; <a href='./teams.php'>" . __('Equipos', 'admin_team') . "</a>\n\t\t\t&raquo; " . ($edit ? __('Editar Equipo', 'admin_team') : __('Crear Equipo', 'admin_team')));
    xoops_cp_header();
    $form = new RMForm($edit ? __('Editar Equipo', 'admin_team') : __('Crear Equipo', 'admin_team'), 'frmTeam', 'teams.php');
    $form->setExtra('enctype="multipart/form-data"');
    $form->oddClass('oddForm');
    $ele = new RMFormRadio(__('Categoría', 'admin_team'), 'cat', 0, 1, 1);
    $result = $db->query("SELECT * FROM " . $db->prefix("coach_categos") . " ORDER BY name");
    while ($row = $db->fetchArray($result)) {
        $ele->addOption($row['name'], $row['id_cat'], $edit ? $team->category() == $row['id_cat'] ? 1 : 0 : 0);
    }
    $form->addElement($ele, true, 'checked');
    $form->addElement(new RMFormText(__('Nombre', 'admin_team'), 'name', 50, 100, $edit ? $team->name() : ''), true);
    if ($edit) {
        $form->addElement(new RMFormText(__('Nombre corto', 'admin_team'), 'nameid', 50, 100, $edit ? $team->nameId() : ''));
    }
    $form->addElement(new RMFormFile(__('Imagen', 'admin_team'), 'image', 46, $mc['filesize'] * 1024));
    if ($edit && $team->image() != '') {
        $form->addElement(new RMFormLabel(__('Imagen actual', 'admin_team'), '<img src="' . XOOPS_URL . '/uploads/teams/ths/' . $team->image() . '" alt="" />'));
    }
    $form->addElement(new RMFormEditor(__('Información', 'admin_team'), 'desc', '90%', '300px', $edit ? $team->desc('e') : ''));
    if ($edit) {
        $html = $team->getVar('dohtml');
        $xcode = $team->getVar('doxcode');
        $doimage = $team->getVar('doimage');
        $smiley = $team->getVar('dosmiley');
        $br = $team->getVar('dobr');
    } else {
        $html = $xoopsConfig['editor_type'] == 'tiny' ? 1 : 0;
        $xcode = $xoopsConfig['editor_type'] == 'tiny' ? 0 : 1;
        $doimage = $xoopsConfig['editor_type'] == 'tiny' ? 0 : 1;
        $smiley = $xoopsConfig['editor_type'] == 'tiny' ? 0 : 1;
        $br = $xoopsConfig['editor_type'] == 'tiny' ? 0 : 1;
    }
    $form->addElement(new RMFormTextOptions(__('Opciones', 'admin_team'), $html, $xcode, $doimage, $smiley, $br));
    $form->addElement(new RMFormSubTitle(__('Entrenadores', 'admin_team'), 1));
    $ele = new RMFormCheck(__('Entrenadores', 'admin_team'));
    $ele->asTable(3);
    $result = $db->query("SELECT * FROM " . $db->prefix("coach_coachs") . " ORDER BY name");
    if ($edit) {
        $coachs = $team->coachs(false);
    }
    while ($row = $db->fetchArray($result)) {
        $coach = new TCCoach();
        $coach->assignVars($row);
        $ele->addOption($coach->name(), 'coachs[]', $coach->id(), $edit ? in_array($coach->id(), $coachs) ? 1 : 0 : 0);
    }
    $form->addElement($ele);
    $ele = new RMFormButtonGroup();
    $ele->addButton('sbt', __('Enviar', 'admin_team'), 'submit');
    $ele->addButton('cancel', __('Cancelar', 'admin_team'), 'button', 'onclick="window.location=\'teams.php\';"');
    $form->addElement($ele);
    $form->addElement(new RMFormHidden('op', $edit ? 'saveedit' : 'save'));
    if ($edit) {
        $form->addElement(new RMFormHidden('id', $team->id()));
    }
    $form->display();
    xoops_cp_footer();
}
Exemple #4
0
$id = str_replace("/", "", $id);
$coach = new TCCoach($id);
if ($coach->isNew()) {
    redirect_header(TC_URL, 1, _MS_TC_ERRNOEXISTIS);
    die;
}
$xoopsOption['template_main'] = "coach_coach.html";
include 'header.php';
$tpl->assign('coach_title', $coach->name());
$tpl->assign('lang_comment', _MS_TC_COMMENT);
$tpl->assign('lang_data', _MS_TC_DATA);
$tpl->assign('lang_name', _MS_TC_NAME);
$tpl->assign('lang_team', _MS_TC_TEAM);
$tpl->assign('lang_date', _MS_TC_DATE);
$tpl->assign('lang_bio', _MS_TC_BIO);
$link = TC_URL . '/' . ($mc['urlmode'] ? 'coach/' . $coach->nameId() . '/' : 'coach.php?id=' . $coach->id());
$tpl->assign('coach', array('id' => $coach->id(), 'name' => $coach->name(), 'image' => $coach->image(), 'date' => formatTimestamp($coach->created(), 'string'), 'bio' => $coach->bio(), 'link' => $link));
$teams = $coach->teams();
$st = '';
foreach ($teams as $team) {
    $tlink = TC_URL . '/' . ($mc['urlmode'] ? 't/' . $team->nameId() . '/' : 'team.php?id=' . $team->id());
    $cat = $team->category(true);
    $st .= $st == '' ? "<a href='{$tlink}'>" . $team->name() . " <em>(" . $cat->name() . ")</em></a>" : ", <a href='{$tlink}'>" . $team->name() . " <em>(" . $cat->name() . ")</em></a>";
}
$tpl->assign('teams', $st);
$tpl->assign('xoops_pagetitle', sprintf(_MS_TC_PTITLE, $coach->name()));
$location = "<a href='" . TC_URL . "'>" . $xoopsModule->name() . "</a> &raquo; " . $coach->name();
$tpl->assign('coach_location', $location);
include 'footer.php';
?>