Example #1
0
$updir .= '/' . date('m', time());
if (!file_exists($updir)) {
    mkdir($updir);
    chmod($updir, octdec('0777'));
}
if (!file_exists($updir . '/sizes')) {
    mkdir($updir . '/sizes');
    chmod($updir . '/sizes', octdec('0777'));
}
include RMCPATH . '/class/uploader.php';
$uploader = new RMFileUploader($updir, $cat->max_file_size(), array('gif', 'jpg', 'jpeg', 'png'));
$err = array();
if (!$uploader->fetchMedia('Filedata')) {
    error($uploader->getErrors());
}
if (!$uploader->upload()) {
    error($uploader->getErrors());
}
// Insertamos el archivo en la base de datos
$image = new RMImage();
$image->setVar('title', $uploader->savedFileName);
$image->setVar('date', time());
$image->setVar('file', $uploader->savedFileName);
$image->setVar('cat', $cat->id());
$image->setVar('uid', $xoopsUser->uid());
if (!$image->save()) {
    unlink($uploader->savedDestination);
    error(__('File could not be inserted to database!', 'rmcommon'));
}
$ret['message'] = '1';
$ret['id'] = $image->id();
Example #2
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());
    }
}
Example #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;
    }
}
Example #4
0
/**
* Save file
*/
function dt_save_file($edit)
{
    global $item, $file, $tpl, $xoopsTpl, $mc, $dtfunc;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verificamos que la característica exista
        $fl = new DTFile($file);
        if ($fl->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&amp;action=files&amp;id=' . $item->id()), 1, __('Specified file does not exists!', 'dtransport'));
        }
    } else {
        $fl = new DTFile();
    }
    $tc = TextCleaner::getInstance();
    //Comprueba que el título de la característica no exista
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_files') . " WHERE title='{$title}' AND id_file!=" . $fl->id() . " AND id_soft=" . $item->id();
    list($num) = $db->fetchRow($db->queryF($sql));
    if ($num > 0) {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&amp;action=files&amp;id=' . $item->id() . '&amp;op=edit&amp;file=' . $fl->id()), 1, __('Another log with same title already exists!', 'dtransport'));
    }
    // Check if a file has been provided
    if ($_FILES['thefile']['name'] == '') {
        // Comprobamos si se ha proporcionado un archivo
        if (!$edit && !$remote) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&amp;action=files&amp;id=' . $item->id() . '&amp;op=edit&amp;file=' . $fl->id()), 1, __('You must provide a file to upload!', 'dtransport'));
        } elseif ($remote && $url == '') {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&amp;action=files&amp;id=' . $item->id() . '&amp;op=edit&amp;file=' . $fl->id()), 1, __('You must provide a file URL when remote type is activated!', 'dtransport'));
        }
    } else {
        if ($edit && !$fl->remote()) {
            $path = $item->getVar('secure') ? rtrim($mc['directory_secure'], '/') . '/' . $fl->file() : rtrim($mc['directory_insecure']) . '/' . $fl->file();
            unlink($path);
        }
        if ($item->getVar('secure')) {
            $dir = $mc['directory_secure'];
        } else {
            $dir = $mc['directory_insecure'];
        }
        include RMCPATH . '/class/uploader.php';
        $uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']);
        if (!$uploader->fetchMedia('thefile')) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&amp;action=files&amp;id=' . $item->id() . '&amp;op=edit&amp;file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors());
        }
        if (!$uploader->upload()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&amp;action=files&amp;id=' . $item->id() . '&amp;op=edit&amp;file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors());
        }
    }
    $fl->setSoftware($item->id());
    $fl->setTitle($title);
    $fname = !$uploader && $edit ? $remote ? $url : $fl->file() : $uploader->getSavedFileName();
    $fl->setFile($fname);
    $fl->setRemote($remote);
    $fl->setGroup($group);
    $fl->setDefault($default);
    $fl->setDate(time());
    $fl->setSize($remote ? '' : (isset($uploader) ? $uploader->getMediaSize() : $fl->size()));
    $fl->setMime($remote ? '' : (isset($uploader) ? $uploader->getMediaType() : $fl->mime()));
    if (!$fl->save()) {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' . ($edit ? 'edit/' . $fl->id() : '') : '/?p=cpanel&amp;action=files&amp;id=' . $item->id() . ($edit ? '&amp;op=edit&amp;file=' . $fl->id() : '')), 1, __('File could not be saved! Please try again.', 'dtransport'));
    }
    if ($fl->isDefault()) {
        $db->queryF("UPDATE " . $db->prefix("dtrans_files") . " SET `default`=0 WHERE id_soft=" . $item->id() . " AND id_file !=" . $fl->id());
    }
    redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&amp;action=files&amp;id=' . $item->id()), 1, __('File saved successfully!', 'dtransport'));
}
Example #5
0
/**
* @desc Almacena las imágenes en la base de datos
**/
function saveImages($edit = 0)
{
    global $xoopsModuleConfig, $xoopsSecurity;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "&page={$page}";
    //Verificamos que el trabajo sea válido
    if ($work <= 0) {
        redirectMsg('./works.php', __('You must specify a work ID!', 'works'), 1);
        die;
    }
    //Verificamos que el trabajo exista
    $work = new PWWork($work);
    if ($work->isNew()) {
        redirectMsg('./works.php', __('Specified work does not exists!', 'works'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Session token expired!', 'works'), 1);
        die;
    }
    if ($edit) {
        //Verificamos que la imagen sea válida
        if ($id <= 0) {
            redirectMsg('./images.php?work=' . $work->id() . $ruta, __('You must specify an image ID!', 'works'), 1);
            die;
        }
        //Verificamos que la imagen exista
        $img = new PWImage($id);
        if ($img->isNew()) {
            redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Specified image does not exists!', 'works'), 1);
            die;
        }
    } else {
        $img = new PWImage();
    }
    $img->setTitle($title);
    $img->setDesc(substr($desc, 0, 100));
    $img->setWork($work->id());
    //Imagen
    include_once RMCPATH . '/class/uploader.php';
    $folder = XOOPS_UPLOAD_PATH . '/works';
    $folderths = XOOPS_UPLOAD_PATH . '/works/ths';
    if ($edit) {
        $image = $img->image();
        $filename = $img->image();
    } else {
        $filename = '';
    }
    //Obtenemos el tamaño de la imagen
    $thSize = $xoopsModuleConfig['image_ths'];
    $imgSize = $xoopsModuleConfig['image'];
    $up = new RMFileUploader($folder, $xoopsModuleConfig['size_image'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            redirectMsg('./images.php?op=' . ($edit ? 'edit' : 'new') . '&work=' . $work->id() . $ruta, $up->getErrors(), 1);
            die;
        }
        if ($edit && $img->image() != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/works/' . $img->image());
            @unlink(XOOPS_UPLOAD_PATH . '/works/ths/' . $img->image());
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageResizer($fullpath, $fullpath);
        switch ($xoopsModuleConfig['redim_image']) {
            case 0:
                //Recortar miniatura
                $redim->resizeWidth($imgSize[0]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeAndCrop($thSize[0], $thSize[1]);
                break;
            case 1:
                //Recortar imagen grande
                $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeWidth($thSize[0]);
                break;
            case 2:
                //Recortar ambas
                $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeAndCrop($thSize[0], $thSize[1]);
                break;
            case 3:
                //Redimensionar
                $redim->resizeWidth($imgSize[0]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeWidth($thSize[0]);
                break;
        }
    }
    $img->setImage($filename);
    RMEvents::get()->run_event('works.save.image', $img);
    if (!$img->save()) {
        redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Errors ocurred while trying to save the image', 'works') . '<br />' . $img->errors(), 1);
        die;
    } else {
        redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Database updated successfully!', 'works'), 0);
        die;
    }
}
Example #6
0
     redirect_header($retlink, 2, __('Message could not be posted! Please try again', 'bxpress'));
     die;
 }
 if (!$topic->approved()) {
     bXFunctions::notifyAdmin($forum->moderators(), $forum, $topic, $post);
 }
 // Adjuntamos archivos si existen
 if ($forum->attachments() && $forum->isAllowed($xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS, 'attach')) {
     $folder = $xoopsModuleConfig['attachdir'];
     $exts = array();
     include_once RMCPATH . '/class/uploader.php';
     $up = new RMFileUploader($folder, $xoopsModuleConfig['maxfilesize'] * 1024, $forum->extensions());
     $errors = '';
     $filename = '';
     if ($up->fetchMedia('attach')) {
         if (!$up->upload()) {
             $errors .= $up->getErrors();
         } else {
             $filename = $up->getSavedFileName();
             $fullpath = $up->getSavedDestination();
             $attach = new bXAttachment();
             $attach->setPost($post->id());
             $attach->setFile($filename);
             $attach->setMime($up->getMediaType());
             $attach->setDate(time());
             $attach->downloads(0);
             $attach->setName($up->getMediaName());
             if (!$attach->save()) {
                 $errors .= $attach->getErrors();
             }
         }
function dt_upload_screenshots()
{
    global $xoopsSecurity;
    $item = rmc_server_var($_REQUEST, 'item', 0);
    $data = rmc_server_var($_REQUEST, 'data', '');
    $rmu = RMUtilities::get();
    $mc = $rmu->module_config('dtransport');
    $tc = TextCleaner::getInstance();
    $data = explode("|", $tc->decrypt($data));
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $ses = new XoopsSessionHandler($db);
    session_decode($ses->read($data[1]));
    $_SERVER['HTTP_USER_AGENT'] = trim($data[0]);
    if (!$xoopsSecurity->check(false)) {
        error(__('Session token not valid!', 'dtransport'));
    }
    if ($item <= 0) {
        error(__('Download item ID not provided!', 'dtransport'));
    }
    require_once XOOPS_ROOT_PATH . '/modules/dtransport/class/dtsoftware.class.php';
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        error(__('Specified download item does not exists!', 'dtransport'));
    }
    if ($sw->getVar('screens') >= $mc['limit_screen']) {
        error(__('You have reached the limit screens number for this download item!', 'dtransport'));
    }
    // Directorio de almacenamiento
    $dir = XOOPS_UPLOAD_PATH . '/screenshots';
    if (!is_dir($dir)) {
        mkdir($dir, 511);
    }
    $dir .= '/' . date('Y', time());
    if (!is_dir($dir)) {
        mkdir($dir, 511);
    }
    $dir .= '/' . date('m', time());
    if (!is_dir($dir)) {
        mkdir($dir, 511);
    }
    if (!is_dir($dir . '/ths')) {
        mkdir($dir . '/ths', 511);
    }
    if (!is_dir($dir)) {
        error(__('Directory for store screenshots does not exists!', 'dtransport'));
    }
    include RMCPATH . '/class/uploader.php';
    $uploader = new RMFileUploader($dir, $mc['image'] * 1024, array('jpg', 'gif', 'png'));
    $err = array();
    if (!$uploader->fetchMedia('Filedata')) {
        error($uploader->getErrors());
    }
    if (!$uploader->upload()) {
        error($uploader->getErrors());
    }
    // Saving image
    require_once XOOPS_ROOT_PATH . '/modules/dtransport/class/dtscreenshot.class.php';
    $img = new DTScreenshot();
    $img->setDesc('');
    $img->setTitle($uploader->getSavedFileName());
    $img->setImage($uploader->getSavedFileName());
    $img->setDate(time());
    $img->setSoftware($item);
    if (!$img->save()) {
        unlink($dir . '/' . $img->image());
        error(__('Screenshot could not be saved!', 'dtransport'));
    }
    // Resize image
    $thumb = explode(":", $mc['size_ths']);
    $big = explode(":", $mc['size_image']);
    $sizer = new RMImageResizer($dir . '/' . $img->getVar('image'), $dir . '/ths/' . $img->getVar('image'));
    // Thumbnail
    if (!isset($thumb[2]) || $thumb[2] == 'crop') {
        $sizer->resizeAndCrop($thumb[0], $thumb[1]);
    } else {
        $sizer->resizeWidthOrHeight($thumb[0], $thumb[1]);
    }
    // Full size image
    $sizer->setTargetFile($dir . '/' . $img->image());
    if (!isset($big[2]) || $big[2] == 'crop') {
        $sizer->resizeAndCrop($big[0], $big[1]);
    } else {
        $sizer->resizeWidthOrHeight($big[0], $big[1]);
    }
    $ret = array('image' => $uploader->getSavedFileName(), 'dir' => str_replace(XOOPS_UPLOAD_PATH, XOOPS_UPLOAD_URL, $dir), 'token' => $xoopsSecurity->createToken(), 'type' => $uploader->getMediaType(), 'error' => 0, 'id' => $img->id());
    echo json_encode($ret);
    die;
}
Example #8
0
function saveTeam($edit = 0)
{
    global $db, $mc, $xoopsSecurity;
    $nameid = '';
    $coachs = array();
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if (!$xoopsSecurity->validateToken()) {
        redirectMsg('teams.php' . ($edit ? "?op=edit&id={$id}" : "?op=new"), __('Identficador de sesión expiró', 'admin_team'), 1);
        break;
    }
    if ($edit) {
        $id = TCFunctions::post('id');
        if ($id <= 0) {
            die;
            redirectMsg('teams.php', __('Id no válido', 'admin_team'), 1);
            die;
        }
        $team = new TCTeam($id);
        if ($team->isNew()) {
            redirectMsg('teams.php', __('No existe el equipo especificado', '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_teams") . " WHERE nameid='{$nameid}' AND id_team<>'" . $team->id() . "'";
            list($num) = $db->fetchRow($db->query($sql));
            $i++;
        } while ($num > 0);
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_teams") . " WHERE name='{$name}' AND cat={$cat} AND id_team<>'" . $team->id() . "'";
        list($num) = $db->fetchRow($db->query($sql));
        if ($num > 0) {
            redirectMsg('teams.php?op=edit&id=' . $coach->id(), __('Ya existe un equipo con el mismo nombre', 'admin_team'), 1);
            die;
        }
    } else {
        $team = new TCTeam();
        $i = 0;
        do {
            $nameid = TextCleaner::getInstance()->sweetstring($name) . ($i > 0 ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_teams") . " WHERE nameid='{$nameid}'";
            list($num) = $db->fetchRow($db->query($sql));
            $i++;
        } while ($num > 0);
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_teams") . " WHERE name='{$name}' AND cat='{$cat}'";
        list($num) = $db->fetchRow($db->query($sql));
        if ($num > 0) {
            redirectMsg('teams.php?op=new', __('Ya existe un equipo 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', $mc['filesize'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            if ($edit) {
                redirectMsg('./teams.php?op=new', $up->getErrors(), 1);
                die;
            } else {
                redirectMsg('./teams.php?op=edit&id=' . $team->id(), $up->getErrors(), 1);
                die;
            }
        }
        if ($edit && $team->image() != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/teams/' . $team->image());
            @unlink(XOOPS_UPLOAD_PATH . '/teams/ths/' . $team->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/ths/{$filename}");
        $redim->resizeWidth($mc['th_size']);
    } else {
        $filename = $edit ? $team->image() : '';
    }
    $team->setCategory($cat);
    $team->setName($name);
    $team->setNameId($nameid);
    $team->setDesc($desc);
    $team->setImage($filename);
    if (!$edit) {
        $team->setCreated(time());
    }
    $team->setCoachs($coachs);
    $team->setVar('dohtml', isset($dohtml) ? 1 : 0);
    $team->setVar('doxcode', isset($doxcode) ? 1 : 0);
    $team->setVar('doimage', isset($doimage) ? 1 : 0);
    $team->setVar('dosmiley', isset($dosmiley) ? 1 : 0);
    $team->setVar('dobr', isset($dobr) ? 1 : 0);
    if ($team->save()) {
        redirectMsg('teams.php', __('Base de datos actualizada correctamente', 'admin_team'), 0);
    } else {
        redirectMsg('teams.php?op=' . ($edit ? "edit&id=" . $team->id() : "new"), __('No se pudo actualizar la base de datos', 'admin_team') . '<br />' . $team->errors(), 0);
    }
}
Example #9
0
/**
* @desc almacena la informacion de la pantalla en la base de datos
**/
function dt_save_screens($edit = 0)
{
    global $item, $xoopsModuleConfig, $screen, $mc;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verificamos que la pantalla exista
        $sc = new DTScreenshot($screen);
        if ($sc->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Specified screenshot is not valid!', 'dtransport'));
        }
        //Comprueba que el título de la pantalla no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_screens') . " WHERE title='{$title}' AND id_soft=" . $item->id() . " AND id_screen!=" . $sc->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/edit/' . $sc->id() : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id() . '&amp;op=edit&amp;screen' . $sc->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        }
    } else {
        //Comprueba que el título de la pantalla no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_screens') . " WHERE title='{$title}' AND id_soft=" . $item->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        }
        $sc = new DTScreenshot();
    }
    $sc->setTitle($title);
    $sc->setDesc($desc);
    $sc->setDate(time());
    $sc->setSoftware($item->id());
    //Cargamos la imagen
    // Directorio de almacenamiento
    if (isset($_FILES['image']) && $_FILES['image']['name'] != '') {
        $dir = XOOPS_UPLOAD_PATH . '/screenshots';
        // Eliminamos la imagen existente
        if ($edit) {
            $dir .= '/' . date('Y', $sc->date()) . '/' . date('m', $sc->date());
            unlink($dir . '/' . $sc->image());
            unlink($dir . '/ths/' . $sc->image());
            $dir = XOOPS_UPLOAD_PATH . '/screenshots';
        }
        if (!is_dir($dir)) {
            mkdir($dir, 511);
        }
        $dir .= '/' . date('Y', time());
        if (!is_dir($dir)) {
            mkdir($dir, 511);
        }
        $dir .= '/' . date('m', time());
        if (!is_dir($dir)) {
            mkdir($dir, 511);
        }
        if (!is_dir($dir . '/ths')) {
            mkdir($dir . '/ths', 511);
        }
        if (!is_dir($dir)) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Image could not be upload due to an internal error!', 'dtransport'));
        }
        include RMCPATH . '/class/uploader.php';
        $uploader = new RMFileUploader($dir, $mc['image'] * 1024, array('jpg', 'gif', 'png'));
        $err = array();
        if (!$uploader->fetchMedia('image')) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Image could not be upload due to an internal error!', 'dtransport'));
        }
        if (!$uploader->upload()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Image could not be upload due to an internal error!', 'dtransport'));
        }
        $sc->setImage($uploader->getSavedFileName());
        // Resize image
        $thumb = explode(":", $mc['size_ths']);
        $big = explode(":", $mc['size_image']);
        $sizer = new RMImageResizer($dir . '/' . $sc->getVar('image'), $dir . '/ths/' . $sc->getVar('image'));
        // Thumbnail
        if (!isset($thumb[2]) || $thumb[2] == 'crop') {
            $sizer->resizeAndCrop($thumb[0], $thumb[1]);
        } else {
            $sizer->resizeWidthOrHeight($thumb[0], $thumb[1]);
        }
        // Full size image
        $sizer->setTargetFile($dir . '/' . $sc->image());
        if (!isset($big[2]) || $big[2] == 'crop') {
            $sizer->resizeAndCrop($big[0], $big[1]);
        } else {
            $sizer->resizeWidthOrHeight($big[0], $big[1]);
        }
    }
    if (!$sc->save()) {
        if ($sc->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        } else {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/edit/' . $sc->id() : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id() . '&amp;op=edit&amp;screen' . $sc->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        }
    } else {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Screenshot saved successfully!', 'dtransport'));
    }
}
Example #10
0
function m_save_player($edit)
{
    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('roster.php?action=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $query, __('Session token expired!', 'match'), 1);
        die;
    }
    if ($name == '' || $birth <= 0 || $team <= 0 || $lastname == '' || $surname == '') {
        echo "{$name}<br />{$birth}<br />{$team}<br />{$lastname}<br />{$surname}";
        die;
        //redirectMsg('roster.php?action='.($edit ? 'edit&id='.$id : 'new').'&'.$query, __('Please fill all required data!','match'), 1);
    }
    if ($edit) {
        if ($id <= 0) {
            redirectMsg('./roster.php', __('Player ID not valid!', 'match'), 1);
            die;
        }
        //Verificamos que el trabajo exista
        $player = new MCHPlayer($id);
        if ($player->isNew()) {
            redirectMsg('./roster.php', __('Specified player does not exists!', 'match'), 1);
            die;
        }
    } else {
        $player = new MCHPlayer();
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    // Check if work exists already
    if ($edit) {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("mch_players") . " WHERE name='{$name}' and team='{$team}' and id_player<>'{$id}'";
    } else {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("mch_players") . " WHERE name='{$name}' and team='{$team}'";
    }
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        redirectMsg("roster.php" . $action . $query, __('A player with same name already exists!', 'match'), 1);
        die;
    }
    //Genera $nameid Nombre identificador
    $found = false;
    $i = 0;
    if ($name != $player->getVar('name') || empty($nameid)) {
        do {
            $nameid = TextCleaner::sweetstring($lastname . ' ' . $surname . ' ' . $name) . ($found ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix('mch_players') . " WHERE nameid = '{$nameid}'";
            list($num) = $db->fetchRow($db->queryF($sql));
            if ($num > 0) {
                $found = true;
                $i++;
            } else {
                $found = false;
            }
        } while ($found == true);
    }
    $player->setVar('name', $name);
    $player->setVar('lastname', $lastname);
    $player->setVar('surname', $surname);
    $player->setVar('nameid', $nameid);
    $player->setVar('bio', $bio);
    $player->setVar('team', $team);
    $player->setVar('created', $created > 0 ? $created : time());
    $player->setVar('position', $position);
    $player->setVar('birth', $birth);
    //Logo
    include_once RMCPATH . '/class/uploader.php';
    $folder = XOOPS_UPLOAD_PATH . '/teams/players';
    if ($edit) {
        $image = $player->getVar('photo');
        $filename = $player->getVar('photo');
    } else {
        $filename = '';
    }
    //Obtenemos el tamaño de la imagen
    $imgSize = $xoopsModuleConfig['photo_size'];
    $thSize = $xoopsModuleConfig['th_size'];
    $up = new RMFileUploader($folder, $xoopsModuleConfig['logo_file_size'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('photo')) {
        if (!$up->upload()) {
            redirectMsg('./roster.php' . $action . $query, $up->getErrors(), 1);
            die;
        }
        if ($edit && $player->getVar('photo') != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/teams/players/' . $player->getVar('photo'));
            @unlink(XOOPS_UPLOAD_PATH . '/teams/players/ths/' . $player->getVar('photo'));
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageResizer($fullpath, $fullpath);
        //Redimensionar
        $redim->resizeWidth($imgSize);
        $redim->setTargetFile($folder . '/ths/' . $filename);
        $redim->resizeAndCrop($thSize, $thSize);
    }
    $player->setVar('photo', $filename);
    if (!$player->save()) {
        redirectMsg('./roster.php' . $action . $query, __('Errors ocurred while trying to update database!', 'match') . $player->errors(), 1);
        die;
    } else {
        redirectMsg('./roster.php?id=' . $player->id(), __('Player saved successfully!', 'match'), 0);
        die;
    }
}
Example #11
0
/**
* @desc Almacena la información del grupo de imágenes
**/
function saveBulkImages()
{
    global $util, $mc, $xoopsUser;
    XoopsLogger::getInstance()->activated = false;
    XoopsLogger::getInstance()->renderingEnabled = false;
    set_time_limit(0);
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "page={$page}&search={$search}&owner={$uid}&sort={$sort}&mode={$mode}";
    if ($xoopsUser->uid() == $uid) {
        $xu = $xoopsUser;
    } else {
        $xu = new XoopsUser($uid);
    }
    //Verificamos si el usuario se encuentra registrado
    $user = new GSUser($xu->uname());
    if ($user->isNew()) {
        //Insertamos información del usuario
        $user->setUid($uid);
        $user->setUname($xu->uname());
        $user->setQuota($mc['quota'] * 1024 * 1024);
        $user->setDate(time());
        if (!$user->save()) {
            send_error(__('User owner could not be created!', 'galleries') . "<br />" . $user->errors());
            die;
        } else {
            mkdir($mc['storedir'] . "/" . $user->uname());
            mkdir($mc['storedir'] . "/" . $user->uname() . "/ths");
            mkdir($mc['storedir'] . "/" . $user->uname() . "/formats");
        }
    } else {
        @mkdir($mc['storedir'] . "/" . $user->uname());
        @mkdir($mc['storedir'] . "/" . $user->uname() . "/ths");
        @mkdir($mc['storedir'] . "/" . $user->uname() . "/formats");
    }
    // Insertamos las etiquetas
    $tgs = explode(",", $tags);
    /**
     * @desc Almacena los ids de las etiquetas que se asignarán a la imágen
     */
    $ret = array();
    foreach ($tgs as $k) {
        $k = trim($k);
        if ($k == '') {
            continue;
        }
        // Comprobamos que la palabra tenga la longitud permitida
        if (strlen($k) < $mc['min_tag'] || strlen($k) > $mc['max_tag']) {
            continue;
        }
        // Creamos la etiqueta
        $tag = new GSTag($k);
        if (!$tag->isNew()) {
            // Si ya existe nos saltamos
            $ret[] = $tag->id();
            continue;
        }
        $tag->setTag($k);
        if ($tag->save()) {
            $ret[] = $tag->id();
        }
    }
    $errors = '';
    $k = 1;
    include_once RMCPATH . '/class/uploader.php';
    $updir = $mc['storedir'] . "/" . $xu->uname();
    $upths = $mc['storedir'] . "/" . $xu->uname() . "/ths";
    // Cargamos la imágen
    if (!file_exists($updir)) {
        mkdir($updir, 511);
    }
    if (!file_exists($upths)) {
        mkdir($upths, 511);
    }
    $uploader = new RMFileUploader($updir, $mc['size_image'] * 1024, array('gif', 'jpg', 'jpeg', 'png'));
    $err = array();
    if (!$uploader->fetchMedia('Filedata')) {
        send_error($uploader->getErrors());
    }
    if (!$uploader->upload()) {
        send_error($uploader->getErrors());
    }
    // Insertamos el archivo en la base de datos
    $img = new GSImage();
    $img->setTitle($uploader->savedFileName);
    $img->setOwner($uid);
    $img->setPublic(2);
    $img->setCreated(time());
    $img->setImage($uploader->getSavedFileName());
    if (!$image->save()) {
        unlink($uploader->savedDestination);
        send_error(__('File could not be inserted to database!', 'galleries'));
    }
    $ret['message'] = '1';
    $ret['id'] = $image->id();
    echo json_encode($ret);
    die;
}
Example #12
0
/**
* @desc Almacena las imágenes en la base de datos
**/
function shop_save_image($edit = 0)
{
    global $xoopsModuleConfig, $xoopsSecurity;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "action=images&page={$page}&bname={$bname}&id={$id}";
    //Verificamos que el trabajo sea válido
    if ($id <= 0) {
        redirectMsg('products.php', __('You must specify a product ID!', 'shop'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('products.php?' . $ruta, __('Session token expired!', 'shop'), 1);
        die;
    }
    //Verificamos que el trabajo exista
    $product = new ShopProduct($id);
    if ($product->isNew()) {
        redirectMsg('products.php', __('Specified product does not exists!', 'shop'), 1);
        die;
    }
    if ($edit) {
        //Verificamos que la imagen sea válida
        if ($idimg <= 0) {
            redirectMsg('products.php?' . $ruta, __('You must specify an image ID!', 'shop'), 1);
            die;
        }
        //Verificamos que la imagen exista
        $img = new ShopImage($idimg);
        if ($img->isNew()) {
            redirectMsg('products.php?' . $ruta, __('Specified image does not exists!', 'shop'), 1);
            die;
        }
    } else {
        $img = new ShopImage();
    }
    $img->setVar('title', $title);
    $img->setVar('description', $description);
    $img->setVar('product', $product->id());
    //Imagen
    include_once RMCPATH . '/class/uploader.php';
    $folder = XOOPS_UPLOAD_PATH . '/minishop';
    $folderths = XOOPS_UPLOAD_PATH . '/minishop/ths';
    if ($edit) {
        $image = $img->getVar('file');
        $filename = $img->getVar('file');
    } else {
        $filename = '';
    }
    //Obtenemos el tamaño de la imagen
    $thSize = explode("|", $xoopsModuleConfig['thssize']);
    $imgSize = explode("|", $xoopsModuleConfig['imgsize']);
    $up = new RMFileUploader($folder, $xoopsModuleConfig['maxsize'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('file')) {
        if (!$up->upload()) {
            redirectMsg('products.php?action=' . ($edit ? 'edit' : 'new') . '&' . $ruta, $up->getErrors(), 1);
            die;
        }
        if ($edit && $img->getVar('file') != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/minishop/' . $img->getVar('file'));
            @unlink(XOOPS_UPLOAD_PATH . '/minishop/ths/' . $img->getVar('file'));
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageResizer($fullpath, $fullpath);
        if ($xoopsModuleConfig['imgredim']) {
            $redim->resizeAndCrop($imgSize[0], $imgSize[1]);
        } else {
            $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
        }
        $redim->setTargetFile($folderths . "/{$filename}");
        if ($xoopsModuleConfig['thsredim']) {
            $redim->resizeAndCrop($thSize[0], $thSize[1]);
        } else {
            $redim->resizeWidthOrHeight($thSize[0], $thSize[1]);
        }
    }
    $img->setVar('file', $filename);
    RMEvents::get()->run_event('shop.save.image', $img);
    if (!$img->save()) {
        redirectMsg('products.php?action=images&' . $ruta, __('Errors ocurred while trying to save the image', 'shop') . '<br />' . $img->errors(), 1);
        die;
    } else {
        redirectMsg('products.php?' . $ruta, __('Database updated successfully!', 'shop'), 0);
        die;
    }
}
Example #13
0
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);
    }
}
Example #14
0
/**
* @desc Almacena las imágenes en la base de datos y en el disco duro
*/
function saveImages()
{
    global $db, $xoopsOption, $xoopsUser, $mc, $tpl, $xmh, $xoopsModuleConfig, $util;
    $mc =& $xoopsModuleConfig;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    //Verificamos si el usuario se encuentra registrado
    $user = new GSUser($xoopsUser->uname());
    if ($user->isNew()) {
        //Insertamos información del usuario
        $user->setUid($xoopsUser->uid());
        $user->setUname($xoopsUser->uname());
        $user->setQuota($mc['quota'] * 1024 * 1024);
        $user->setDate(time());
        if (!$user->save()) {
            redirect_header('./submit.php', 1, __('Sorry, an error ocurred while trying to register your permissions on database. Try again later!', 'galleries'));
            die;
        }
    }
    @mkdir($mc['storedir'] . "/" . $user->uname());
    @mkdir($mc['storedir'] . "/" . $user->uname() . "/ths");
    @mkdir($mc['storedir'] . "/" . $user->uname() . "/formats");
    $mc['saveoriginal'] ? @mkdir($mc['storedir'] . "/originals") : '';
    // Insertamos las etiquetas
    $tgs = explode(" ", $tags);
    /**
     * @desc Almacena los ids de las etiquetas que se asignarán a la imagen
     */
    $ret = array();
    foreach ($tgs as $k) {
        $k = trim($k);
        $kf = TextCleaner::getInstance()->sweetstring($k);
        if ($kf == '') {
            continue;
        }
        // Comprobamos que la palabra tenga la longitud permitida
        if (strlen($kf) < $mc['min_tag'] || strlen($kf) > $mc['max_tag']) {
            continue;
        }
        // Creamos la etiqueta
        $tag = new GSTag($k);
        if (!$tag->isNew()) {
            // Si ya existe nos saltamos
            $ret[] = $tag->id();
            continue;
        }
        $tag->setTag($k);
        $tag->setVar('nameid', $kf);
        if ($tag->save()) {
            $ret[] = $tag->id();
        }
    }
    $errors = '';
    $k = 1;
    include_once RMCPATH . '/class/uploader.php';
    $up = new RMFileUploader(true);
    $folder = $mc['storedir'] . "/" . $xoopsUser->uname();
    $folderths = $mc['storedir'] . "/" . $xoopsUser->uname() . "/ths";
    foreach ($_FILES['images']['name'] as $k => $v) {
        if ($v == '') {
            continue;
        }
        $img = new GSImage();
        $img->setOwner($xoopsUser->uid());
        $img->setPublic($privacy);
        $img->setCreated(time());
        //Imagen
        $filename = '';
        $up = new RMFileUploader($folder, $mc['size_image'] * 1024, array('jpg', 'png', 'gif'));
        if ($up->fetchMedia('images', $k)) {
            if (!$up->upload()) {
                $errors .= $up->getErrors();
                continue;
            }
            $filename = $up->getSavedFileName();
            $fullpath = $up->getSavedDestination();
            $thSize = $mc['image_ths'];
            $imgSize = $mc['image'];
            if ($thSize[0] <= 0) {
                $thSize[0] = 100;
            }
            if (!isset($thSize[1]) || $thSize[1] <= 0) {
                $thSize[1] = $thSize[0];
            }
            if ($imgSize[0] <= 0) {
                $imgSize[0] = 500;
            }
            if (!isset($imgSize[1]) || $imgSize[1] <= 0) {
                $imgSize[1] = $imgSize[0];
            }
            // Almacenamos la imágen original
            if ($mc['saveoriginal']) {
                copy($fullpath, $mc['storedir'] . '/originals/' . $filename);
            }
            // Redimensionamos la imagen
            $redim = new RMImageResizer($fullpath, $fullpath);
            switch ($mc['redim_image']) {
                case 0:
                    //Recortar miniatura
                    $redim->resizeWidth($imgSize[0]);
                    $redim->setTargetFile($folderths . "/{$filename}");
                    $redim->resizeAndCrop($thSize[0], $thSize[1]);
                    break;
                case 1:
                    //Recortar imagen grande
                    $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
                    $redim->setTargetFile($folderths . "/{$filename}");
                    $redim->resizeWidth($thSize[0]);
                    break;
                case 2:
                    //Recortar ambas
                    $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
                    $redim->setTargetFile($folderths . "/{$filename}");
                    $redim->resizeAndCrop($thSize[0], $thSize[1]);
                    break;
                case 3:
                    //Redimensionar
                    $redim->resizeWidth($imgSize[0]);
                    $redim->setTargetFile($folderths . "/{$filename}");
                    $redim->resizeWidth($thSize[0]);
                    break;
            }
        }
        //Fin de Imagen
        $img->setImage($filename);
        if ($up->getErrors() == '') {
            if (!$img->save()) {
                $errors .= sprintf(__('Picture %s could not be uploaded!', 'galleries'), $v) . " (" . $img->errors() . ")";
            } else {
                $user->addPic();
                if ($ret) {
                    $img->setTags($ret);
                }
            }
        } else {
            $errors .= $up->getErrors();
        }
        ++$k;
    }
    if ($errors != '') {
        redirect_header(GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/images' : '?cp=images'), 2, __('Errors ocurred while trying to upload images!', 'galleries') . $errors);
        die;
    } else {
        redirect_header(GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/images' : '?cp=images'), 2, __('Pictures stored successfully!', 'galleries'));
        die;
    }
}
Example #15
0
/**
* @desc Almacena la información del trabajo en la base de datos
**/
function saveWorks($edit = 0)
{
    global $xoopsSecurity, $xoopsModuleConfig;
    $query = '';
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'op' || $k == 'sbt') {
            continue;
        }
        $query .= $query == '' ? "{$k}=" . urlencode($v) : "&{$k}=" . urlencode($v);
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('./works.php?op=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $query, __('Session token expired!', 'works'), 1);
        die;
    }
    if ($edit) {
        //Verificamos que el trabajo sea válido
        if ($id <= 0) {
            redirectMsg('./works.php?' . $query, __('Work ID not valid!', 'works'), 1);
            die;
        }
        //Verificamos que el trabajo exista
        $work = new PWWork($id);
        if ($work->isNew()) {
            redirectMsg('./works.php?' . $query, __('Specified work does not exists!', 'works'), 1);
            die;
        }
    } else {
        $work = new PWWork();
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    // Check if work exists already
    if ($edit) {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("pw_works") . " WHERE title='{$title}' and id_work<>'{$id}'";
    } else {
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("pw_works") . " WHERE title='{$title}'";
    }
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        redirectMsg("works.php?" . $query, __('A work with same name already exists!', 'works'), 1);
        die;
    }
    $work->setTitle($title);
    $work->set_title_id(TextCleaner::sweetstring($title));
    $work->setDescShort(substr(stripcslashes($short), 0, 255));
    $work->setDesc($desc);
    $work->setCategory($catego);
    $work->setClient($client);
    $work->setComment($comment);
    $work->setNameSite($site);
    $work->setUrl(formatURL($url));
    $work->setStart($start);
    $work->setPeriod($period);
    $work->setCost($cost);
    $work->setMark($mark);
    $work->setPublic($public);
    $work->setRating($rating);
    $work->isNew() ? $work->setCreated(time()) : '';
    $work->setVar('dohtml', isset($dohtml) ? 1 : 0);
    $work->setVar('doxcode', isset($doxcode) ? 1 : 0);
    $work->setVar('dobr', isset($dobr) ? 1 : 0);
    $work->setVar('dosmiley', isset($dosmiley) ? 1 : 0);
    $work->setVar('doimage', isset($doimage) ? 1 : 0);
    //Imagen
    include_once RMCPATH . '/class/uploader.php';
    $folder = XOOPS_UPLOAD_PATH . '/works';
    $folderths = XOOPS_UPLOAD_PATH . '/works/ths';
    if ($edit) {
        $image = $work->image();
        $filename = $work->image();
    } else {
        $filename = '';
    }
    //Obtenemos el tamaño de la imagen
    $thSize = $xoopsModuleConfig['image_main_ths'];
    $imgSize = $xoopsModuleConfig['image_main'];
    $up = new RMFileUploader($folder, $xoopsModuleConfig['size_image'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            redirectMsg('./works.php?id=' . $id . '&op=' . ($edit ? 'edit' : 'new'), $up->getErrors(), 1);
            die;
        }
        if ($edit && $work->image() != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/works/' . $work->image());
            @unlink(XOOPS_UPLOAD_PATH . '/works/ths/' . $work->image());
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageResizer($fullpath, $fullpath);
        switch ($xoopsModuleConfig['redim_image']) {
            case 0:
                //Recortar miniatura
                $redim->resizeWidth($imgSize[0]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeAndCrop($thSize[0], $thSize[1]);
                break;
            case 1:
                //Recortar imagen grande
                $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeWidth($thSize[0]);
                break;
            case 2:
                //Recortar ambas
                $redim->resizeAndCrop($imgSize[0], $imgSize[1]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeAndCrop($thSize[0], $thSize[1]);
                break;
            case 3:
                //Redimensionar
                $redim->resizeWidth($imgSize[0]);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeWidth($thSize[0]);
                break;
        }
    }
    $work->setImage($filename);
    if (!$work->save()) {
        redirectMsg('./works.php?' . $query, __('Errors ocurred while trying to update database!', 'works') . $work->errors(), 1);
        die;
    } else {
        redirectMsg('./works.php?op=edit&id=' . $work->id(), __('Database updated successfully!', 'works'), 0);
        die;
    }
}