/** * @desc Visualiza todos los archivos de un software **/ function showFiles() { global $xoopsModule, $xoopsSecurity, $tpl; define("RMCSUBLOCATION", 'fileslist'); $item = rmc_server_var($_REQUEST, 'item', 0); $edit = rmc_server_var($_REQUEST, 'edit', 0); $id = rmc_server_var($_REQUEST, 'id', 0); $db = XoopsDatabaseFactory::getDatabaseConnection(); if ($item <= 0) { redirectMsg('items.php', __('Before to view files, you must specify a download item!', 'dtransport'), RMMSG_INFO); } $sw = new DTSoftware($item); if ($sw->isNew()) { redirectMsg('items.php', __('Specified item does not exists!', 'dtransport'), RMMSG_WARN); } $files = array(); // Files data container //Archivos sin grupo $sql = "SELECT * FROM " . $db->prefix('dtrans_files') . " WHERE id_soft={$item} AND `group`=0"; $result = $db->queryF($sql); while ($rows = $db->fetchArray($result)) { $fl = new DTFile(); $fl->assignVars($rows); $files[] = array('id' => $fl->id(), 'file' => $fl->file(), 'downs' => $fl->hits(), 'group' => $fl->group(), 'default' => $fl->isDefault(), 'remote' => $fl->remote(), 'type' => 'files', 'title' => $fl->title()); } //Grupos pertenecientes al software $groups = $sw->filegroups(); foreach ($groups as $k) { $gr = new DTFileGroup($k); $files[] = array('id' => $gr->id(), 'file' => $gr->name(), 'type' => 'group'); $sql = "SELECT * FROM " . $db->prefix('dtrans_files') . " WHERE id_soft={$item} AND `group`={$k}"; $result = $db->queryF($sql); while ($rows = $db->fetchArray($result)) { $fl = new DTFile(); $fl->assignVars($rows); $files[] = array('id' => $fl->id(), 'file' => $fl->file(), 'downs' => $fl->hits(), 'group' => $fl->group(), 'default' => $fl->isDefault(), 'remote' => $fl->remote(), 'type' => 'files', 'title' => $fl->title()); } } $groups = array(); //Lista de grupos $sql = "SELECT * FROM " . $db->prefix('dtrans_groups') . " WHERE id_soft={$item}"; $result = $db->queryF($sql); while ($rows = $db->fetchArray($result)) { $group = new DTFileGroup(); $group->assignVars($rows); $groups[] = array('id' => $group->id(), 'name' => $group->name()); } xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> » <a href='./items.php'>" . __('Download Items', 'dtransport') . "</a> » " . __('Files Management', 'dtransport')); // Title $title = sprintf(__('Files for "%s"', 'dtransport'), $sw->getVar('name')); $tpl->assign('xoops_pagetitle', $title); DTFunctions::toolbar(); $tpl->add_style('admin.css', 'dtransport'); include DT_PATH . '/include/js_strings.php'; $tpl->add_local_script('admin.js', 'dtransport'); $tpl->add_local_script('files.js', 'dtransport'); $tpl->add_local_script('jquery.checkboxes.js', 'rmcommon', 'include'); xoops_cp_header(); include $tpl->get_template('admin/dtrans_files.php', 'module', 'dtransport'); xoops_cp_footer(); }
/** * Save file */ function dt_save_file($edit) { global $item, $file, $tpl, $xoopsTpl, $mc, $dtfunc; foreach ($_POST as $k => $v) { ${$k} = $v; } $db = XoopsDatabaseFactory::getDatabaseConnection(); if ($edit) { //Verificamos que la característica exista $fl = new DTFile($file); if ($fl->isNew()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('Specified file does not exists!', 'dtransport')); } } else { $fl = new DTFile(); } $tc = TextCleaner::getInstance(); //Comprueba que el título de la característica no exista $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_files') . " WHERE title='{$title}' AND id_file!=" . $fl->id() . " AND id_soft=" . $item->id(); list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('Another log with same title already exists!', 'dtransport')); } // Check if a file has been provided if ($_FILES['thefile']['name'] == '') { // Comprobamos si se ha proporcionado un archivo if (!$edit && !$remote) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('You must provide a file to upload!', 'dtransport')); } elseif ($remote && $url == '') { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('You must provide a file URL when remote type is activated!', 'dtransport')); } } else { if ($edit && !$fl->remote()) { $path = $item->getVar('secure') ? rtrim($mc['directory_secure'], '/') . '/' . $fl->file() : rtrim($mc['directory_insecure']) . '/' . $fl->file(); unlink($path); } if ($item->getVar('secure')) { $dir = $mc['directory_secure']; } else { $dir = $mc['directory_insecure']; } include RMCPATH . '/class/uploader.php'; $uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']); if (!$uploader->fetchMedia('thefile')) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors()); } if (!$uploader->upload()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors()); } } $fl->setSoftware($item->id()); $fl->setTitle($title); $fname = !$uploader && $edit ? $remote ? $url : $fl->file() : $uploader->getSavedFileName(); $fl->setFile($fname); $fl->setRemote($remote); $fl->setGroup($group); $fl->setDefault($default); $fl->setDate(time()); $fl->setSize($remote ? '' : (isset($uploader) ? $uploader->getMediaSize() : $fl->size())); $fl->setMime($remote ? '' : (isset($uploader) ? $uploader->getMediaType() : $fl->mime())); if (!$fl->save()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' . ($edit ? 'edit/' . $fl->id() : '') : '/?p=cpanel&action=files&id=' . $item->id() . ($edit ? '&op=edit&file=' . $fl->id() : '')), 1, __('File could not be saved! Please try again.', 'dtransport')); } if ($fl->isDefault()) { $db->queryF("UPDATE " . $db->prefix("dtrans_files") . " SET `default`=0 WHERE id_soft=" . $item->id() . " AND id_file !=" . $fl->id()); } redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('File saved successfully!', 'dtransport')); }
/** * Save a new or edited file to database */ function dt_save_file($edit = 0) { global $xoopsSecurity, $functions, $db; foreach ($_POST as $k => $v) { ${$k} = $v; } if (!$xoopsSecurity->check()) { $functions->dt_send_message(__('Session token not valid!', 'dtransport'), 1, 0); } //Verificamos si el software es válido if ($item <= 0) { $functions->dt_send_message(__('Item download ID not provided!', 'dtransport'), 1, 1); } //Verificamos si existe el software $sw = new DTSoftware($item); if ($sw->isNew()) { $functions->dt_send_message(__('Specified item download does nto exists!', 'dtransport'), 1, 1); } if ($edit) { //Verificamos si archivo es válido if ($id <= 0) { $functions->dt_send_message(__('File ID has not been provided!', 'dtransport'), 1, 1); } //Verificamos si existe archivo $fl = new DTFile($id); if ($fl->isNew()) { $functions->dt_send_message(__('Specified file does not exists!', 'dtransport'), 1, 1); } // Si es un archivo remoto eliminamos el archivo actual if (!$fl->remote() && $remote) { $rmu = RMUtilities::get(); $mc = $rmu->module_config('dtransport'); $dir = $sw->getVar('secure') ? $mc['directory_secure'] : $mc['directory_insecure']; if (file_exists($dir . '/' . $fl->file())) { unlink($dir . '/' . $fl->file()); } unset($dir, $mc, $rmu); } } else { $fl = new DTFile(); } $fl->setSoftware($item); $fl->setRemote($remote); $fl->setFile($file); $fl->setDefault($default); $fl->setGroup($group); $fl->setDate(time()); $fl->setTitle(trim($title)); $fl->setMime($mime); $fl->setSize($size); if (!$fl->save()) { $functions->dt_send_message(__('File could not be saved!', 'dtransport') . '<br />' . $fl->errors(), 1, 1); } else { if ($fl->isDefault()) { $db->queryF("UPDATE " . $db->prefix("dtrans_files") . " SET `default`=0 WHERE id_soft=" . $sw->id() . " AND id_file !=" . $fl->id()); } $ret = array('message' => __('File saved successfully!', 'dtransport')); showMessage(sprintf(__('File %s saved successfully!', 'dtransport'), $fl->title()), RMMSG_SAVED); $functions->dt_send_message($ret, 0, 1); } }