Esempio n. 1
0
function formCoachs($edit = 0)
{
    global $xoopsModule, $db, $mc, $xoopsConfig;
    if ($edit) {
        $id = TCFunctions::get('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;
        }
    }
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; <a href='./coachs.php'>" . __('Entrenadores', 'admin_team') . "</a> &raquo; " . ($edit ? __('Editar entrenador', 'admin_team') : __('Crear entrenador', 'admin_team')));
    $cHead = '<link href="' . TC_URL . '/styles/admin.css" media="all" rel="stylesheet" type="text/css" />';
    xoops_cp_header($cHead);
    $form = new RMForm($edit ? __('Editar Entrenador', 'admin_team') : __('Crear Entrenador', 'admin_team'), 'frmNew', 'coachs.php', 'post');
    $form->oddClass('oddForm');
    $form->setExtra('enctype="multipart/form-data"');
    $form->addElement(new RMFormText(__('Nombre', 'admin_team'), 'name', 50, 150, $edit ? $coach->name() : ''), true);
    if ($edit) {
        $form->addElement(new RMFormText(__('Nombre corto', 'admin_team'), 'nameid', 50, 150, $coach->nameId()));
    }
    $form->addElement(new RMFormText(__('Cargo', 'admin_team'), 'role', 50, 150, $edit ? $coach->role() : ''), true);
    $form->addElement(new RMFormFile(__('Imagen', 'admin_team'), 'image', 45, $mc['filesize'] * 1024));
    if ($edit && $coach->image() != '') {
        $form->addElement(new RMFormLabel(__('Imagen actual', 'admin_team'), "<img src='" . XOOPS_URL . "/uploads/teams/coachs/ths/" . $coach->image() . "' alt='' />"));
    }
    $form->addElement(new RMFormEditor(__('Biografía', 'admin_team'), 'bio', '90%', '300px', $edit ? $coach->bio('e') : ''));
    $form->addElement(new RMFormSubTitle(__('Equipos', 'admin_team'), 1));
    $ele = new RMFormCheck(__('Seleccionar equipos', 'admin_team'));
    $ele->asTable(3);
    $sql = "SELECT * FROM " . $db->prefix("coach_teams") . " ORDER BY name";
    $result = $db->query($sql);
    if ($edit) {
        $teams = $coach->teams(false);
    }
    while ($row = $db->fetchArray($result)) {
        $team = new TCTeam();
        $team->assignVars($row);
        $cat =& $team->category(true);
        $ele->addOption($team->name() . " <span class='coachNameCat'>(" . $cat->name() . ")</span>", 'teams[]', $team->id(), $edit ? in_array($team->id(), $teams) ? 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=\'coachs.php\';"');
    $form->addElement($ele);
    $form->addElement(new RMFormHidden('op', $edit ? 'saveedit' : 'save'));
    if ($edit) {
        $form->addElement(new RMFormHidden('id', $id));
    }
    $form->display();
    xoops_cp_footer();
}