/**
  * @desc Redimensiona una imágen con los datos especificados
  */
 public function resizeImage($crop, $input, $output, $width, $height)
 {
     // Redimensionamos la imagen
     $redim = new RMImageResizer($input, $output);
     if ($crop) {
         $redim->resizeAndCrop($width, $height);
     } else {
         $redim->resizeWidthOrHeight($width, $height);
     }
 }
示例#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());
    }
}
示例#3
0
/**
* Update image data
*/
function update_image()
{
    global $xoopsUser, $xoopsSecurity;
    set_time_limit(0);
    $title = rmc_server_var($_POST, 'title', '');
    $category = rmc_server_var($_POST, 'cat', '');
    $desc = rmc_server_var($_POST, 'desc', '');
    $page = rmc_server_var($_POST, 'page', 1);
    $id = rmc_server_var($_POST, 'id', 0);
    if (!$xoopsSecurity->check()) {
        redirectMsg('images.php', __('Operation not allowed!', 'rmcommon'), 1);
        die;
    }
    if ($id <= 0) {
        redirectMsg("images.php?category={$cat}&page={$page}", __('Image ID not provided!', 'rmcommon'), 1);
        die;
    }
    if (trim($title) == '') {
        redirectMsg("images.php?action=edit&id={$id}&page={$page}", __('You must  provide a title for this image', 'rmcommon'), 1);
        die;
    }
    $image = new RMImage($id);
    if ($image->isNew()) {
        redirectMsg("images.php?category={$cat}&page={$page}", __('Image not exists!', 'rmcommon'), 1);
        die;
    }
    $cat = new RMImageCategory($category);
    if ($cat->isNew()) {
        redirectMsg("images.php", __('Category not exist!', 'rmcommon'), 1);
        die;
    }
    if ($cat->id() != $image->getVar('cat')) {
        $pcat = new RMImageCategory($image->getVar('cat'));
    }
    $image->setVar('title', $title);
    $image->setVar('desc', $desc);
    if (isset($pcat)) {
        $image->setVar('cat', $cat->id());
    }
    if (!$image->save()) {
        redirectMsg("images.php?action=edit&id={$id}&page={$page}", __('the image could not be updated!', 'rmcommon') . '<br />' . $image->errors(), 1);
        die;
    }
    // Modify image dimensions if category has changed
    if (!isset($pcat)) {
        redirectMsg("images.php?category=" . $cat->id() . "&page={$page}", __('Image updated succesfully!', 'rmcommon'), 0);
        die;
    }
    $fd = pathinfo($image->getVar('file'));
    $updir = XOOPS_UPLOAD_PATH . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time());
    // Delete current image files
    foreach ($pcat->getVar('sizes') as $size) {
        if ($size['width'] <= 0) {
            continue;
        }
        $file = $updir . '/sizes/' . $fd['filename'] . '_' . $size['width'] . 'x' . $size['height'] . '.' . $fd['extension'];
        @unlink($file);
    }
    // Create new image files
    foreach ($cat->getVar('sizes') as $size) {
        if ($size['width'] <= 0 && $size['height'] <= 0) {
            continue;
        }
        $name = $updir . '/sizes/' . $fd['filename'] . '_' . $size['width'] . 'x' . $size['height'] . '.' . $fd['extension'];
        $sizer = new RMImageResizer($updir . '/' . $image->getVar('file'), $name);
        switch ($size['type']) {
            case 'crop':
                $sizer->resizeAndCrop($size['width'], $size['height']);
                break;
            default:
                if ($size['width'] <= 0 || $size['height'] <= 0) {
                    $sizer->resizeWidth($size['width']);
                } else {
                    $sizer->resizeWidthOrHeight($size['width'], $size['height']);
                }
                break;
        }
        $width = $width == 0 ? $size['width'] : $width;
        if ($width < $size['width']) {
            $with = $size['width'];
            $tfile = str_replace(XOOPS_UPLOAD_PATH, XOOPS_UPLOAD_URL, $name);
        }
    }
    redirectMsg('images.php?category=' . $cat->id(), __('Image updated successfully!', 'rmcommon'), 0);
}
示例#4
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;
    }
}
示例#5
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);
    }
}
示例#6
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;
    }
}
示例#7
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;
    }
}
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;
}
示例#9
0
/**
* @desc almacena la información de la imagen
**/
function saveImages($edit = 0)
{
    global $mc, $xoopsSecurity, $db, $xoopsUser, $db;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "page={$page}&limit={$limit}&search={$search}&owner={$owner}&sort={$sort}&mode={$mode}";
    if (!$xoopsSecurity->check()) {
        redirectMsg('./images.php?' . $ruta, __('Session token expired!', 'galleries'), 1);
        die;
    }
    if ($edit) {
        //Verificamos si la imagen es válida
        if ($id <= 0) {
            redirectMsg('./images.php?op=edit&id=' . $id . '&' . $ruta, __('Image ID not valid!', 'galleries'), 1);
            die;
        }
        //Verificamos si la imagen existe
        $img = new GSImage($id);
        if ($img->isNew()) {
            redirectMsg('./images.php?op=edit&id=' . $id . '&' . $ruta, __('Specified image does not exists!', 'galleries'), 1);
            die;
        }
    } else {
        $img = new GSImage();
    }
    $img->setTitle($title);
    $img->setDesc($desc);
    $img->isNew() ? $img->setCreated(time()) : $img->setModified(time());
    if (!$edit) {
        $img->setOwner($uid);
    }
    $img->setPublic($public);
    //Insertamos las etiquetas
    $tgs = array();
    $tags = explode(",", $tags);
    foreach ($tags as $k) {
        $k = trim($k);
        if (!$k) {
            continue;
        }
        if (strlen($k) < $mc['min_tag'] || strlen($k) > $mc['max_tag']) {
            continue;
        }
        $tag = new GSTag($k);
        if (!$tag->isNew()) {
            $tgs[] = $tag->id();
            continue;
        }
        $tag->setTag(strtolower($k));
        if ($tag->save()) {
            $tgs[] = $tag->id();
        }
    }
    if (!$edit) {
        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()) {
                redirectMsg('./images.php?op=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $ruta, __('New user owner could not be saved!', 'galleries'), 1);
                die;
            } else {
                mkdir($mc['storedir'] . "/" . $user->uname());
                mkdir($mc['storedir'] . "/" . $user->uname() . "/ths");
                mkdir($mc['storedir'] . "/" . $user->uname() . "/formats");
            }
        }
    } else {
        $user = new GSUser($img->owner(), 1);
    }
    //Imagen
    include_once RMCPATH . '/class/uploader.php';
    $folder = $mc['storedir'] . "/" . $user->uname();
    $folderths = $mc['storedir'] . "/" . $user->uname() . "/ths";
    $up = new RMFileUploader($folder, $mc['size_image'] * 1024, array('jpg', 'png', 'gif'));
    if ($edit) {
        $filename = $img->image();
    } else {
        $filename = '';
    }
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            redirectMsg('./images.php?op=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $ruta, $up->getErrors(), 1);
            die;
        }
        if ($edit && $img->image() != '') {
            @unlink($mc['storedir'] . "/" . $user->uname() . "/" . $img->image());
            @unlink($mc['storedir'] . "/" . $user->uname() . "/ths/" . $img->image());
            @unlink($mc['storedir'] . "/originals/" . $img->image());
        }
        $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;
        }
    } else {
        echo $up->getErrors();
    }
    //Fin de Imagen
    $img->setImage($filename);
    $db = Database::getInstance();
    $new = $img->isNew();
    if (!$img->save()) {
        redirectMsg('./images.php?op=' . ($edit ? 'edit&id=' . $id : 'new') . '&' . $ruta, __('Errors ocurred while trying to save image.', 'galleries') . $img->errors(), 1);
        die;
    } else {
        $user->addPic();
        $img->setTags($tgs);
        $sets = '';
        $tbl1 = $db->prefix("gs_sets");
        $tbl2 = $db->prefix("gs_setsimages");
        foreach ($albums as $k => $v) {
            // Si el album existe no incrementamos el numero de imagenes
            $sets .= $sets == '' ? "{$tbl2}.id_set<>'{$v}'" : " AND {$tbl2}.id_set<>'{$v}'";
            if ($img->inSet($v)) {
                continue;
            }
            $album = new GSSet($v);
            $album->addPic($img->id());
        }
        // Actualizamos los valores de los ignorados
        $sql = "UPDATE {$tbl1}, {$tbl2} SET {$tbl1}.pics={$tbl1}.pics-1 WHERE ({$tbl2}.id_image='" . $img->id() . "'" . ($sets != '' ? ' AND ' . $sets : '') . ") AND {$tbl1}.id_set={$tbl2}.id_set";
        $db->queryF($sql);
        $sets = str_replace($tbl2 . '.', '', $sets);
        $sql = "DELETE FROM " . $db->prefix("gs_setsimages") . " WHERE id_image='" . $img->id() . "' " . ($sets != '' ? " AND ({$sets})" : '');
        $db->queryF($sql);
        redirectMsg('./images.php?' . $ruta, __('Database updated successfully!', 'galleries'), 0);
        die;
    }
}
示例#10
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'));
    }
}
示例#11
0
/**
* Resize images
*/
function gs_resize_images()
{
    global $xoopsUser, $xoopsLogger, $xoopsSecurity;
    set_time_limit(0);
    $mc = RMUtilities::module_config('galleries');
    $params = rmc_server_var($_GET, 'data', '');
    $id = rmc_server_var($_GET, 'img', 0);
    if ($params == '') {
        send_error(__('Unauthorized!', 'galleries'));
    }
    if ($id <= 0) {
        send_error(__('Invalid image!', 'galleries'));
    }
    $params = TextCleaner::decrypt($params);
    $data = explode('|', $params);
    if ($data[0] != $xoopsUser->uid()) {
        send_error(__('Unauthorized!', 'galleries'));
    }
    if ($data[1] != GS_URL . '/admin/images.php') {
        send_error(__('Unauthorized!', 'galleries'));
    }
    if (!$xoopsSecurity->check(false, $data[2])) {
        send_error(__('Unauthorized!', 'galleries'));
    }
    $image = new GSImage($id);
    if ($image->isNew()) {
        send_error(__('Image not found!', 'galleries'));
    }
    $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];
    }
    $xu = new GSUser($image->owner(), 1);
    $updir = rtrim($mc['storedir'], '/') . "/" . $xu->uname();
    $upurl = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, $updir);
    $upths = rtrim($mc['storedir'], '/') . "/" . $xu->uname() . "/ths";
    $width = 0;
    $tfile = '';
    // Almacenamos la imágen original
    if ($mc['saveoriginal']) {
        copy($updir . '/' . $image->image(), $mc['storedir'] . '/originals/' . $image->image());
    }
    $fd = pathinfo($updir . '/' . $image->image());
    $filename = $image->image();
    $redim = new RMImageResizer($updir . '/' . $image->image(), $updir . '/' . $image->image());
    switch ($mc['redim_image']) {
        case 0:
            //Recortar miniatura
            $redim->resizeWidth($imgSize[0]);
            $redim->setTargetFile($upths . "/{$filename}");
            $redim->resizeAndCrop($thSize[0], $thSize[1]);
            break;
        case 1:
            //Recortar imagen grande
            $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
            $redim->setTargetFile($upths . "/" . $image->image());
            $redim->resizeWidth($thSize[0]);
            break;
        case 2:
            //Recortar ambas
            $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]);
            $redim->setTargetFile($upths . "/{$filename}");
            $redim->resizeAndCrop($thSize[0], $thSize[1]);
            break;
        case 3:
            //Redimensionar
            $redim->resizeWidth($imgSize[0]);
            $redim->setTargetFile($upths . "/{$filename}");
            $redim->resizeWidth($thSize[0]);
            break;
    }
    $tfile = $upurl . '/ths/' . $image->image();
    $ret['message'] = sprintf(__('%s done!', 'galleries'), $image->image());
    $ret['done'] = 1;
    $ret['file'] = $tfile;
    $ret['title'] = $image->image();
    echo json_encode($ret);
    die;
}
示例#12
0
function shop_generate_thumbs()
{
    global $xoopsSecurity, $xoopsModule, $xoopsModuleConfig;
    $ids = rmc_server_var($_POST, 'ids', 0);
    $page = rmc_server_var($_POST, 'page', 1);
    $bname = rmc_server_var($_POST, 'bname', '');
    $ruta = "page={$page}&bname={$bname}";
    //Verificamos que nos hayan proporcionado un trabajo para eliminar
    if (!is_array($ids)) {
        redirectMsg('products.php?' . $ruta, __('You must select one product at least!', 'shop'), 1);
        die;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('products.php?' . $ruta, __('Session token expired!', 'shop'), 1);
        die;
    }
    //Obtenemos el tamaño de la imagen
    $thSize = explode("|", $xoopsModuleConfig['thssize']);
    $imgSize = explode("|", $xoopsModuleConfig['imgsize']);
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos si el trabajo es válido
        if ($k <= 0) {
            $errors .= sprintf(__('Product ID "%s" is not valid!', 'shop'), $k);
            continue;
        }
        //Verificamos si el trabajo existe
        $product = new ShopProduct($k);
        if ($product->isNew()) {
            $errors .= sprintf(__('Product with ID "%s" does not exists!', 'shop'), $k);
            continue;
        }
        // Redimensionamos la imagen
        $path = XOOPS_UPLOAD_PATH . '/minishop/';
        $redim = new RMImageResizer($path . $product->getVar('image'), $path . 'ths/' . $product->getVar('image'));
        if ($xoopsModuleConfig['thsredim']) {
            $redim->resizeAndCrop($thSize[0], $thSize[1]);
        } else {
            $redim->resizeWidthOrHeight($thSize[0], $thSize[1]);
        }
    }
    if ($errors != '') {
        redirectMsg('products.php?' . $ruta, __('Errors ocurred while trying to regenerate thumbnails', 'shop') . '<br />' . $errors, 1);
        die;
    } else {
        redirectMsg('products.php?' . $ruta, __('Thumbnails regenerated successfully!', 'shop'), 0);
        die;
    }
}
示例#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);
    }
}
示例#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;
    }
}
示例#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;
    }
}