/** * 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); } }