Example #1
0
function saveCoach($edit = 0)
{
    global $db, $mc, $xoopsSecurity;
    $nameid = '';
    $teams = array();
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('coachs.php' . ($edit ? "?op=edit&id={$id}" : "?op=new"), __('El identificador de sesión ha expirado', 'admin_team'), 1);
        break;
    }
    if ($edit) {
        $id = TCFunctions::post('id');
        if ($id <= 0) {
            redirectMsg('coachs.php', __('Id no válido', 'admin_team'), 1);
            die;
        }
        $coach = new TCCoach($id);
        if ($coach->isNew()) {
            redirectMsg('coachs.php', __('El entrenador especificado no existe', 'admin_team'), 1);
            die;
        }
        $i = 0;
        do {
            $nameid = $nameid != '' && $i == 0 ? $nameid : $util->sweetstring($name) . ($i > 0 ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE nameid='{$nameid}' AND id_coach<>'" . $coach->id() . "'";
            list($num) = $db->fetchRow($db->query($sql));
            $i++;
        } while ($num > 0);
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE name='{$name}' AND id_coach<>'" . $coach->id() . "'";
        list($num) = $db->fetchRow($db->query($sql));
        if ($num > 0) {
            redirectMsg('coachs.php?op=edit&id=' . $coach->id(), __('Ya existe un entrenador con ese nombre', 'admin_team'), 1);
            die;
        }
    } else {
        $coach = new TCCoach();
        $i = 0;
        do {
            $nameid = TextCleaner::getInstance()->sweetstring($name) . ($i > 0 ? $i : '');
            $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE nameid='{$nameid}'";
            list($num) = $db->fetchRow($db->query($sql));
            $i++;
        } while ($num > 0);
        $sql = "SELECT COUNT(*) FROM " . $db->prefix("coach_coachs") . " WHERE name='{$name}'";
        list($num) = $db->fetchRow($db->query($sql));
        if ($num > 0) {
            redirectMsg('coachs.php?op=new&id=' . $cat->id(), __('Ya existe un entreandor con el mismo nombre', 'admin_team'), 1);
            die;
        }
    }
    // Cargamos la imágen
    include_once RMCPATH . '/class/uploader.php';
    $up = new RMFileUploader(XOOPS_UPLOAD_PATH . '/teams/coachs', $mc['filesize'] * 1024, array('jpg', 'png', 'gif'));
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            if ($edit) {
                redirectMsg('./coachs.php?op=new', $up->getErrors(), 1);
                die;
            } else {
                redirectMsg('./coachs.php?op=edit&id=' . $coach->id(), $up->getErrors(), 1);
                die;
            }
        }
        if ($edit && $coach->image() != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/teams/coachs/' . $coach->image());
            @unlink(XOOPS_UPLOAD_PATH . '/teams/coachs/ths/' . $coach->image());
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageResizer($fullpath, $fullpath);
        $redim->resizeWidth($mc['img_size']);
        $redim->setTargetFile(XOOPS_UPLOAD_PATH . "/teams/coachs/ths/{$filename}");
        switch ($mc['resize_method']) {
            case 1:
                //Recortar miniatura
                $redim->resizeAndCrop($mc['th_size'], $mc['th_size']);
                break;
            case 0:
                $redim->resizeWidth($mc['th_size']);
                break;
        }
    } else {
        $filename = $edit ? $coach->image() : '';
    }
    $coach->setName($name);
    $coach->setNameId($nameid);
    $coach->setBio($bio);
    $coach->setImage($filename);
    $coach->setRole($role);
    $coach->setTeams($teams);
    if (!$edit) {
        $coach->setCreated(time());
    }
    if ($coach->save()) {
        redirectMsg('coachs.php', __('Base de datos actualizada correctamente', 'admin_template'), 0);
    } else {
        redirectMsg('coachs.php?op=' . ($edit ? 'edit&id=' . $coach->id() : 'new'), __('Error al actualizar la base de datos', 'admin_template') . '<br />' . $coach->errors());
    }
}
Example #2
0
     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();
             }
         }
     }
 }
 $topic->setLastPost($post->id());
 if (!$create) {
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
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 #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
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 #7
0
$sw = new DTSoftware($item);
if ($sw->isNew()) {
    error(__('Specified download item does not exists!', 'dtransport'));
}
if ($sw->getVar('secure')) {
    $dir = $mc['directory_secure'];
    if (!is_dir($dir)) {
        if (!mkdir($dir, 511)) {
            error(__('Directory for protected downloads does not exists!', 'dtransport'));
        }
    }
} else {
    $dir = $mc['directory_insecure'];
    if (!is_dir($dir)) {
        if (!mkdir($dir, 511)) {
            error(__('Directory for downloads does not exists!', 'dtransport'));
        }
    }
}
include RMCPATH . '/class/uploader.php';
$uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']);
$err = array();
if (!$uploader->fetchMedia('Filedata')) {
    error($uploader->getErrors());
}
if (!$uploader->upload()) {
    error($uploader->getErrors());
}
$ret = array('file' => $uploader->getSavedFileName(), 'dir' => $uploader->getSavedDestination(), 'token' => $data[4], 'size' => $rmu->formatBytesSize($uploader->getMediaSize()), 'fullsize' => $uploader->getMediaSize(), 'type' => $uploader->getMediaType(), 'secure' => $sw->getVar('secure') ? __('Protected Download', 'dtransport') : __('Normal Download', 'dtransport'), 'error' => 0);
echo json_encode($ret);
die;
Example #8
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;
    }
}
Example #9
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 #10
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 #11
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 #12
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;
    }
}