/** * @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(); }
/** * Muestra las características existentes de una descarga */ function dt_show_files($edit = 0) { global $xoopsOption, $db, $tpl, $xoopsTpl, $xoopsUser, $mc, $dtfunc, $page, $item, $xoopsConfig, $xoopsModuleConfig, $file; include 'header.php'; $dtfunc->cpHeader($item, sprintf(__('%s files', 'dtransport'), $item->getVar('name'))); if ($file > 0 && $edit) { $file = new DTFile($file); if ($file->isNew() || $file->software() != $item->id()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('Specified feature does not exists!', 'dtransport')); } } $tc = TextCleaner::getInstance(); $tf = new RMTimeFormatter('', "%m%/%d%/%Y% %h%:%i%"); $rmu = RMUtilities::get(); $tfiles = $db->prefix('dtrans_files'); $tgroup = $db->prefix('dtrans_groups'); $sql = "SELECT * FROM {$tfiles} WHERE id_soft=" . $item->id(); $gcache = array(); $result = $db->queryF($sql); while ($rows = $db->fetchArray($result)) { $fl = new DTFile(); $fl->assignVars($rows); if (!isset($gcache[$fl->group()])) { $gcache[$fl->group()] = new DTFileGroup($fl->group()); } $group = $gcache[$fl->group()]; $xoopsTpl->append('files', array('id' => $fl->id(), 'title' => $fl->title(), 'date' => $tf->format($fl->date()), 'software' => $item->getVar('name'), 'remote' => $fl->remote(), 'size' => $rmu->formatBytesSize($fl->size()), 'hits' => $fl->hits(), 'date' => $tf->format($fl->date()), 'group' => $group->isNew() ? '' : $group->name(), 'links' => array('edit' => DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->getVar('nameid') . '/edit/' . $fl->id() . '/' : '/?p=cpanel&id=' . $item->id() . '&action=files&feature=' . $fl->id()), 'delete' => DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->getVar('nameid') . '/delete/' . $fl->id() . '/' : '/?p=cpanel&id=' . $item->id() . '&action=delete&feature=' . $fl->id())))); } $formurl = DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/save/' . ($edit ? $file->id() : '0') . '/' : '/p=cpanel'); // files Form $form = new RMForm($edit ? sprintf(__('Editing file of "%s"', 'dtransport'), $item->getVar('name')) : sprintf(__('New file for "%s"', 'dtransport'), $item->getVar('name')), 'frmFile', $formurl); $form->setExtra('enctype="multipart/form-data"'); $form->addElement(new RMFormLabel(__('Download item', 'dtransport'), $item->getVar('name'))); $form->addElement(new RMFormText(__('File title', 'dtransport'), 'title', 50, 200, $edit ? $file->title() : ''), true); //Lista de grupos $sql = "SELECT * FROM " . $db->prefix('dtrans_groups') . " WHERE id_soft=" . $item->id(); $result = $db->query($sql); $groups = array(); while ($rows = $db->fetchArray($result)) { $group = new DTFileGroup(); $group->assignVars($rows); $groups[] = array('id' => $group->id(), 'name' => $group->name()); } $ele = new RMFormSelect(__('Group', 'dtransport'), 'group', 0, $edit ? $file->group() : ''); $ele->addOption('', __('Select group...', 'dtransport')); foreach ($groups as $group) { $ele->addOption($group['id'], $group['name']); } $form->addElement($ele); $form->addElement(new RMFormYesNo(__('Default file', 'dtransport'), 'default', $edit ? $file->isDefault() : 0)); $form->addElement(new RMFormYesNo(__('Remote file', 'dtransport'), 'remote', $edit ? $file->remote() : 0)); $form->addElement(new RMFormFile(__('File', 'dtransport'), 'thefile', 50, $xoopsModuleConfig['size_file'] * 1024 * 1024)); if ($edit) { $form->addElement(new RMFormLabel(__('Current file', 'dtransport'), $file->file())); } $form->addElement(new RMFormText(__('File URL', 'dtransport'), 'url', 50, 200, $edit ? $file->title() : ''))->setDescription(__('Used only when remote file is activated.', 'dtransport')); $form->addElement(new RMFormHidden('action', 'save')); $form->addElement(new RMFormHidden('id', $item->id())); $form->addElement(new RMFormHidden('file', $edit ? $file->id() : 0)); $form->addElement(new RMFormHidden('op', 'save')); $buttons = new RMFormButtonGroup(); $buttons->addButton('sbt', $edit ? __('Save Changes', 'dtransport') : __('Save File', 'dtransport'), 'submit'); $buttons->addButton('cancel', __('Cancel', 'dtransport'), 'button', 'onclick="window.location=\'' . (DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id())) . '\';"'); $form->addElement($buttons); $xoopsTpl->assign('file_form', $form->render()); $tpl->add_xoops_style('cpanel.css', 'dtransport'); $tpl->add_head_script('$(document).ready(function(){ $("a.delete").click(function(){ if(!confirm("' . __('Do you really want to delete selected file?', 'dtransport') . '")) return false; }); });'); $xoopsTpl->assign('lang_id', __('ID', 'dtransport')); $xoopsTpl->assign('lang_title', __('Title', 'dtransport')); $xoopsTpl->assign('lang_group', __('Group', 'dtransport')); $xoopsTpl->assign('lang_remote', __('Remote', 'dtransport')); $xoopsTpl->assign('lang_size', __('Size', 'dtransport')); $xoopsTpl->assign('lang_hits', __('Hits', 'dtransport')); $xoopsTpl->assign('lang_date', __('Date', 'dtransport')); $xoopsTpl->assign('lang_edit', __('Edit', 'dtransport')); $xoopsTpl->assign('lang_delete', __('Delete', 'dtransport')); $xoopsTpl->assign('lang_addfile', __('Add File', 'dtransport')); $xoopsTpl->assign('edit', $edit); include 'footer.php'; }
/** * 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); } }