/** * @desc Visualiza todas las categorías existentes **/ function showCategories() { global $xoopsModule, $xoopsSecurity; $categos = array(); DTFunctions::getCategos($categos); $categories = array(); foreach ($categos as $row) { $cat = new DTCategory(); $cat->assignVars($row); $categories[] = array('id' => $cat->id(), 'name' => $cat->name(), 'parent' => $cat->parent(), 'active' => $cat->active(), 'description' => $cat->desc(), 'indent' => $row['jumps']); } unset($categos); RMTemplate::get()->add_local_script('jquery.checkboxes.js', 'rmcommon', 'include'); RMTemplate::get()->add_local_script('jquery.validate.min.js', 'rmcommon', 'include'); RMTemplate::get()->add_local_script('admin.js', 'dtransport'); RMTemplate::get()->add_head('<script type="text/javascript"> var dt_message = "' . __('Do you really want to delete selected categories', 'dtransport') . '"; var dt_select_message = "' . __('Select at least one category to delete!', 'dtransport') . '"; </script>'); RMTemplate::get()->add_xoops_style('admin.css', 'dtransport'); DTFunctions::toolbar(); xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> » " . __('Categories', 'dtransport')); xoops_cp_header(); include RMTemplate::get()->get_template('admin/dtrans_categos.php', 'module', 'dtransport'); xoops_cp_footer(); }
function dt_block_categories($options) { include_once XOOPS_ROOT_PATH . '/modules/dtransport/class/dtcategory.class.php'; $rmu = RMUtilities::get(); $rmf = RMFunctions::get(); $mc = $rmu->module_config('dtransport'); $url = $rmf->current_url(); $rpath = parse_url($url); $xpath = parse_url(XOOPS_URL); if ($mc['permalinks']) { $params = trim(str_replace($xpath['path'] . '/' . trim($mc['htbase'], '/'), '', rtrim($rpath['path'], "/")), '/'); $search = array('category', 'publisher', 'recents', 'popular', 'rated', 'updated'); if ($params == '') { $params = array(); } else { $params = explode("/", trim($params)); } if (!empty($params) && $params[0] == 'category') { $db = XoopsDatabaseFactory::getDatabaseConnection(); $params = explode("page", implode("/", array_slice($params, 1))); $path = explode("/", $params[0]); foreach ($path as $k) { if ($k == '') { continue; } $category = new DTCategory(); $sql = "SELECT * FROM " . $db->prefix("dtrans_categos") . " WHERE nameid='{$k}' AND parent='{$idp}'"; $result = $db->query($sql); if ($db->getRowsNum($result) > 0) { $row = $db->fetchArray($result); $idp = $row['id_cat']; $category->assignVars($row); } else { $dtfunc->error_404(); } } } else { $category = new DTCategory(); } } $tpl = RMTemplate::get(); $tpl->add_xoops_style('blocks.css', 'dtransport'); include_once XOOPS_ROOT_PATH . '/modules/dtransport/class/dtfunctions.class.php'; $categories = array(); $dtfunc = new DTFunctions(); $dtfunc->getCategos($categories, 0, $category->id(), array(), false, 1); $block = array(); foreach ($categories as $cat) { if ($cat['jumps'] > $options[0] - 1 && $options[0] > 0) { continue; } $block['categories'][] = $cat; } if (!$category->isNew()) { $block['parent'] = array('name' => $category->name(), 'link' => $category->permalink()); } return $block; }
redirect_header(DT_URL, 2, __('Category not specified!', 'dtransport')); } $idp = 0; # ID de la categoria padre $path = explode("/", $path); foreach ($path as $k) { if ($k == '') { continue; } $category = new DTCategory(); $sql = "SELECT * FROM " . $db->prefix("dtrans_categos") . " WHERE nameid='{$k}' AND parent='{$idp}'"; $result = $db->query($sql); if ($db->getRowsNum($result) > 0) { $row = $db->fetchArray($result); $idp = $row['id_cat']; $category->assignVars($row); } else { $dtfunc->error_404(); } } } else { if ($id <= 0) { redirect_header(DT_URL, 1, __("Specified category does not exists!", 'dtransport')); } if (!is_numeric($page)) { $page = 1; } $category = new DTCategory($id); } // Descargas en esta categoría $tbls = $db->prefix("dtrans_software");
/** * @desc Formulario de Elementos **/ function formItems($edit = 0) { global $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $rmc_config, $xoopsSecurity, $functions; define('RMCSUBLOCATION', 'newitem'); // Get layout data $id = intval(rmc_server_var($_REQUEST, 'id', 0)); $page = intval(rmc_server_var($_REQUEST, 'page', 0)); $search = rmc_server_var($_REQUEST, 'search', ''); $sort = rmc_server_var($_REQUEST, 'sort', 'id_soft'); $mode = intval(rmc_server_var($_REQUEST, 'mode', 0)); $catid = intval(rmc_server_var($_REQUEST, 'car', 0)); $type = rmc_server_var($_REQUEST, 'type', ''); $ev = RMEvents::get(); $params = '?page=' . $page . '&search=' . $search . '&sort=' . $sort . '&mode=' . $mode . '&cat=' . $catid . '&type=' . $type; if ($edit) { //Verificamos que el software sea válido if ($id <= 0) { redirectMsg('items.php' . $params, __('Download item has not been specified!', 'dtransport'), 1); die; } //Verificamos que el software exista if ($type == 'edit') { $sw = new DTSoftwareEdited($id); $location = __('Verifying edited item!', 'dtransport'); } else { $sw = new DTSoftware($id); $location = __('Editing download item', 'dtransport'); } if ($sw->isNew()) { redirectMsg('./items.php' . $params, __('Specified download item does not exists!', 'dtransport'), 1); die; } } else { $sw = new DTSoftware(); $location = __('New Download Item', 'dtransport'); } $form = new RMForm('', '', ''); $ed = new RMFormEditor('', 'desc', '99%', '300px', $edit ? $sw->getVar('desc', $rmc_config['editor_type'] != 'tiny' ? 'e' : 's') : '', $rmc_config['editor_type']); $ed->addClass('required'); $db = XoopsDatabaseFactory::getDatabaseConnection(); //Lista de categorías $categos = array(); $swcats = $sw->categories(); DTFunctions::getCategos($categos, 0, 0, array(), false); foreach ($categos as $row) { $cat = new DTCategory(); $cat->assignVars($row); $categories[] = array('id' => $cat->id(), 'name' => $cat->name(), 'parent' => $cat->parent(), 'active' => $cat->active(), 'description' => $cat->desc(), 'indent' => $row['jumps'], 'selected' => $edit ? in_array($cat->id(), $swcats) : ''); } unset($categos); // Licencias $sql = "SELECT * FROM " . $db->prefix('dtrans_licences'); $result = $db->queryF($sql); $lics = array(); $lics[] = array('id' => 0, 'name' => __('Other license', 'dtransport'), 'selected' => !$edit || in_array(0, $sw->licences()) ? 1 : 0); while ($row = $db->fetchArray($result)) { $lic = new DTLicense(); $lic->assignVars($row); $lics[] = array('id' => $lic->id(), 'name' => $lic->name(), 'selected' => $edit ? in_array($lic->id(), $sw->licences()) : ''); } unset($lic); // Plataformas $sql = "SELECT * FROM " . $db->prefix('dtrans_platforms'); $result = $db->queryF($sql); $oss = array(); $oss[] = array('id' => 0, 'name' => __('Other platform', 'dtransport'), 'selected' => !$edit || in_array(0, $sw->platforms()) ? 1 : 0); while ($row = $db->fetchArray($result)) { $os = new DTPlatform(); $os->assignVars($row); $oss[] = array('id' => $os->id(), 'name' => $os->name(), 'selected' => $edit ? in_array($os->id(), $sw->platforms()) : ''); } unset($os); // Allowed groups $field = new RMFormGroups('', 'groups', 1, 1, 1, $edit ? $sw->getVar('groups') : array(1, 2)); $groups = $field->render(); // Tags $ftags = $sw->tags(true); $tags = array(); foreach ($ftags as $tag) { $tags[] = $tag->getVar('tag'); } unset($ftags); RMTemplate::get()->add_style('admin.css', 'dtransport'); RMTemplate::get()->add_style('items.css', 'dtransport'); RMTemplate::get()->add_local_script('itemsform.js', 'dtransport'); RMTemplate::get()->add_local_script('jquery.validate.min.js', 'rmcommon', 'include'); include DT_PATH . '/include/js_strings.php'; DTFunctions::toolbar(); xoops_cp_location($location); xoops_cp_header(); include RMTemplate::get()->get_template('admin/dtrans_formitems.php', 'module', 'dtransport'); xoops_cp_footer(); }
/** * Get the categories from database * @param bool determines if function returns DTCategories objects or array with ids * @return array */ public function categories($obj = false) { $tbl1 = $this->db->prefix("dtrans_catsoft"); $tbl2 = $this->db->prefix("dtrans_categos"); if (!empty($this->_categories) && !$obj) { return $this->_categories; } elseif (!empty($this->_catobjs) && $obj) { return $this->_catobjs; } $sql = "SELECT b.* FROM {$tbl1} a, {$tbl2} b WHERE a.soft='" . $this->id() . "' AND b.id_cat=a.cat"; $result = $this->db->query($sql); if ($obj) { $ret = array(); } while ($row = $this->db->fetchArray($result)) { $this->_categories[] = $row['id_cat']; if ($obj) { $cat = new DTCategory(); $cat->assignVars($row); $this->_catobjs[$row['id_cat']] = $cat; } } return $obj ? $this->_catobjs : $this->_categories; }
/** * @desc Genera el arreglo con las categorías existentes en la base de datos * @param array Referencia al array a rellenar * @param int Espacios en el árbol * @param int Identificar de la Categoría padre * @param int, array Identificador de la Categoría a ignorar (Junto con sus subcategoría) * @param bool True devuelve objetos {@link DTCategory} * @param int Especifica si se buscaran catagorias inactivas(0), activas(1), todas(2) * @return array */ public function getCategos(&$categos, $jumps = 0, $parent = 0, $exclude = array(), $asobj = false, $active = 1) { $db = XoopsDatabaseFactory::getDatabaseConnection(); if (!is_array($exclude)) { $exclude = array($exclude); } $result = $db->query("SELECT * FROM " . $db->prefix("dtrans_categos") . " WHERE parent='{$parent}' " . ($active ? $active == 2 ? "" : " AND active=1" : " AND active=0 ") . " ORDER BY `id_cat`"); while ($row = $db->fetchArray($result)) { if (is_array($exclude) && (in_array($row['parent'], $exclude) || in_array($row['id_cat'], $exclude))) { $exclude[] = $row['id_cat']; } else { $cat = new DTCategory(); $cat->assignVars($row); $rtn = array(); if ($asobj) { $rtn['object'] = $cat; $rtn['jumps'] = $jumps; } else { $rtn = $row; $rtn['jumps'] = $jumps; $rtn['link'] = $cat->permalink(); } $categos[] = $rtn; } DTFunctions::getCategos($categos, $jumps + 1, $row['id_cat'], $exclude, $asobj, $active); } return true; }