/** * Delete files */ function dt_delete_file() { global $mc, $item, $file; $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 is not valid!', 'dtransport')); } if (!$fl->delete()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('File could not be deleted! Please try again.', 'dtransport')); } if ($item->getVar('secure')) { $dir = rtrim($mc['directory_secure'], '/'); } else { $dir = rtrim($mc['directory_insecure'], '/'); } if (!$fl->remote()) { unlink($dir . '/' . $fl->file()); } redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('File deleted successfully!', 'dtransport')); }
/** * @desc Formulario de archivos **/ function formFiles($edit = 0) { global $tpl, $xoopsModule, $xoopsModuleConfig, $xoopsUser, $xoopsSecurity; define("RMCSUBLOCATION", 'newfile'); $id = rmc_server_var($_GET, 'id', 0); $item = rmc_server_var($_GET, 'item', 0); //Verificamos si el software es válido if ($item <= 0) { redirectMsg('files.php', __('No download item ID has been provided!', 'dtransport'), RMMSG_WARN); } //Verificamos si existe el software $sw = new DTSoftware($item); if ($sw->isNew()) { redirectMsg('files.php', __('Specified download item does not exists!', 'dtransport'), RMMSG_ERROR); } $file_exists = true; if ($edit) { //Verificamos si archivo es válido if ($id <= 0) { redirectMsg('./files.php?item=' . $item, __('No file ID has been specified!', 'dtransport'), RMMSG_WARN); } //Verificamos si existe archivo $fl = new DTFile($id); if ($fl->isNew()) { redirectMsg('files.php?item=' . $item, __('Specified file does not exists!', 'dtransport'), RMMSG_ERROR); } if ($sw->getVar('secure')) { $dir = $xoopsModuleConfig['directory_secure']; } else { $dir = $xoopsModuleConfig['directory_insecure']; } if (!$fl->remote()) { if (!is_file($dir . '/' . $fl->file())) { $file_exists = false; showMessage(sprintf(__('File %s does not exists! You need to upload this file again.', 'dtransport'), $dir . '/' . $fl->file()), RMMSG_WARN); } } } xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> » <a href='items.php'>" . $sw->getVar('name') . "</a> » <a href='files.php?item=" . $sw->id() . "'>" . __('Files', 'dtransport') . "</a> » " . ($edit ? __('Edit file', 'dtransport') : __('New file', 'dtransport'))); $tpl->assign('xoops_pagetitle', $xoopsModule->name() . " » " . $sw->getVar('name') . " » " . __('Files', 'dtransport') . " » " . ($edit ? __('Edit file', 'dtransport') : __('New file', 'dtransport'))); $db = XoopsDatabaseFactory::getDatabaseConnection(); $func = new DTFunctions(); $func->toolbar(); $rmf = RMFunctions::get(); $rmu = RMUtilities::get(); // Uploader $tc = TextCleaner::getInstance(); $uploader = new RMFlashUploader('dtfiles-uploader', DT_URL . '/ajax/upload.php'); $token = $xoopsSecurity->createToken(); $uploader->add_setting('onUploadStart', 'function(file){ $("#dtfiles-uploader").uploadify("settings", "formData", { action: "upload", item: $("#item").val(), XOOPS_TOKEN_REQUEST: $("#XOOPS_TOKEN_REQUEST").val(), data: "' . $tc->encrypt($_SERVER['HTTP_USER_AGENT'] . '|' . session_id() . '|' . $xoopsUser->uid() . '|' . $rmf->current_url()) . '" }); }'); $uploader->add_setting('multi', false); $uploader->add_setting('fileExt', '*.' . implode(";*.", $xoopsModuleConfig['type_file'])); $uploader->add_setting('fileDesc', sprintf(__('Allowed files (%s)', 'dtransport'), implode(";*.", $xoopsModuleConfig['type_file']) . ')')); $uploader->add_setting('sizeLimit', $xoopsModuleConfig['size_file'] * 1024 * 1024); $uploader->add_setting('buttonText', __('Select File...', 'rmcommon')); $uploader->add_setting('queueSizeLimit', 1); $uploader->add_setting('auto', true); $uploader->add_setting('onUploadSuccess', "function(file, resp, data){\n eval('ret = '+resp);\n if (ret.error==1){\n \$('.dt-errors').html(ret.message).slideDown('fast');\n upload_error = 1;\n } else {\n upload_error = 0;\n getFilesToken();\n \$('#dtfiles-preview .name').html(ret.file);\n \$('#dtfiles-preview .size').html(ret.size);\n \$('#size').val(ret.fullsize);\n \$('#dtfiles-preview .type').html(ret.type);\n \$('#dtfiles-preview .secure').html(ret.secure);\n }\n return true;\n }"); $uploader->add_setting('onQueueComplete', "function(event, data){\n if(upload_error==1) return;\n \$('.dt-errors').slideUp('fast');\n \$('#dtfiles-uploader').fadeOut('fast');\n \$('#dtfiles-preview').fadeIn('fast');\n }"); $uploader->add_setting('onSelectOnce', "function(event, data){\n \$('#upload-errors').html('');\n }"); if ($edit && $file_exists) { $uploader->add_setting('onInit', 'function(instance){ $("#dtfiles-uploader").hide(); }'); } $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()); } $tpl->add_head($uploader->render()); $tpl->add_style('admin.css', 'dtransport'); $tpl->add_style('files.css', 'dtransport'); $tpl->add_local_script('admin.js', 'dtransport'); $tpl->add_local_script('files.js', 'dtransport'); $tpl->add_head_script('var upload_error = 0;'); include DT_PATH . '/include/js_strings.php'; xoops_cp_header(); include $tpl->get_template("admin/dtrans_filesform.php", 'module', 'dtransport'); xoops_cp_footer(); }
// Comprobamos si el archivo es seguro o no if (!$item->getVar('secure')) { // Comprobamos si es un archivo remoto o uno local if ($file->remote()) { // Almacenamos las estadísticas $st = new DTStatistics(); $st->setDate(time()); $st->setFile($file->id()); $st->setSoftware($item->id()); $st->setUid($xoopsUser ? $xoopsUser->uid() : 0); $st->setIp($_SERVER['REMOTE_ADDR']); $st->save(); $item->addHit(); $file->addHit(); unset($_SESSION['dttoken']); header('location: ' . $file->file()); die; } else { $dir = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, $mc['directory_insecure']); $dir = str_replace("\\", "/", $dir); $dir = rtrim($dir, '/'); $path = $mc['directory_insecure']; $path = str_replace("\\", "/", $path); $path = rtrim($path, '/'); if (!file_exists($path . '/' . $file->file())) { redirect_header(DT_URL . '/report.php?item=' . $item->id() . "&error=0", 2, __('We\'re sorry but specified file does not exists!', 'dtransport')); } $st = new DTStatistics(); $st->setDate(time()); $st->setFile($file->id()); $st->setSoftware($item->id());
/** * Elimina archivos de la base de datos y el disco duro */ function dt_delete_file() { global $xoopsSecurity, $functions; if (!$xoopsSecurity->check()) { $functions->dt_send_message(__('Session token not valid!', 'dtransport'), 1, 0); } $id = rmc_server_var($_POST, 'id', 0); $item = rmc_server_var($_POST, 'item', 0); $file = new DTFile($id); if ($file->isNew()) { $functions->dt_send_message(__('Specified file does not exists!', 'dtransport'), 1, 1); } $sw = new DTSoftware($item); if ($sw->isNew()) { $functions->dt_send_message(__('Specified item download does nto exists!', 'dtransport'), 1, 1); } if ($file->software() != $item) { $functions->dt_send_message(__('This file seems not belong to specified download item!', 'dtransport'), 1, 1); } if (!$file->delete()) { $functions->dt_send_message(__('File could not be deleted!', 'dtransport'), 1, 1); } $rmu = RMUtilities::get(); $mc = $rmu->module_config('dtransport'); $dir = $sw->getVar('secure') ? $mc['directory_secure'] : $mc['directory_insecure']; unlink($dir . '/' . $file->file()); $functions->dt_send_message(__('File deleted successfully!', 'dtransport'), 0, 1); }