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;
}
Exemplo n.º 2
0
        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");
$tblc = $db->prefix("dtrans_catsoft");
$sql = "SELECT COUNT(*) FROM {$tbls} as s, {$tblc} as c WHERE c.cat='" . $category->id() . "' AND s.id_soft=c.soft AND s.approved=1 AND s.delete=0";
list($num) = $db->fetchRow($db->query($sql));
$limit = $mc['xpage'];
$limit = $limit <= 0 ? 10 : $limit;
$tpages = ceil($num / $limit);
if ($tpages < $page && $tpages > 0) {
    header('location: ' . $category->permalink());
    die;
}
$p = $page > 0 ? $page - 1 : $page;
$start = $num <= 0 ? 0 : $p * $limit;
Exemplo n.º 3
0
/**
* @desc Elimina las categorías especificadas
**/
function deleteCategos()
{
    global $xoopsModule, $xoopsSecurity;
    $ids = rmc_server_var($_POST, 'ids', array());
    //Verificamos si nos proporcionaron alguna categoria
    if (!is_array($ids) || empty($ids)) {
        redirectMsg('./categories.php', __('You must select at least one category to delete!', 'dtransport'), 1);
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('categories.php', __('Session token expired!', 'dtransport'), 1);
    }
    $errors = '';
    foreach ($ids as $k) {
        //Verificamos si la categoría es válida
        if ($k <= 0) {
            $errors .= sprintf(__('Category ID "%s" is not valid!', 'dtransport'), $k);
            continue;
        }
        //verificamos si la categoría existe
        $cat = new DTCategory($k);
        if ($cat->isNew()) {
            $errors .= sprintf(__('Category "%s" does not exists!', 'dtransport'), $k);
            continue;
        }
        if (!$cat->delete()) {
            $errors .= sprintf(__('Category "%s" could not be deleted!', 'dtransport'), $cat->name());
        }
    }
    if ($errors != '') {
        redirectMsg('categories.php', __('There was errors trying to delete categories', 'dtransport') . '<br />' . $errors, 1);
        die;
    } else {
        redirectMsg('categories.php', __('Categories deleted successfully!', 'dtransport'), 0);
        die;
    }
}
Exemplo n.º 4
0
/**
* @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();
}
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * Get featured items
  * @param int Allows to select items from a specific category
  * @param string Smarty varibale name. Useful when assign is true
  * @param string Type of items (all, featured, recent, daily, rated, updated
  * @return array
  */
 public function get_items($cat = 0, $type = 'all', $limit = 10)
 {
     global $xoopsTpl, $mc;
     $items = array();
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     switch ($type) {
         case 'featured':
             $filter = "a.approved=1 AND a.featured=1 AND a.delete=0";
             $order = "ORDER BY RAND()";
             break;
         case 'recent':
             $filter = "a.approved=1 AND a.delete=0";
             $order = "ORDER BY a.created DESC";
             break;
         case 'daily':
             $filter = "a.approved=1 AND a.daily=1 AND a.delete=0";
             $order = "ORDER BY RAND()";
             break;
         case 'rated':
             $filter = "a.approved=1 AND a.delete=0";
             $order = "ORDER BY a.rating DESC";
             break;
         case 'updated':
             $filter = "a.approved=1 AND a.delete=0";
             $order = "ORDER BY a.modified DESC";
             break;
         default:
             $filter = 'a.delete=0';
             $order = "ORDER BY created DESC";
             break;
     }
     if ($cat > 0) {
         // Categories under current category
         $categos = array();
         $this->categoryTreeId($categos, $cat);
         $sql = "SELECT a.*, b.*, c.name AS namecat, c.id_cat\n                    FROM " . $db->prefix("dtrans_software") . " AS a, " . $db->prefix("dtrans_catsoft") . " AS b\n                    JOIN " . $db->prefix("dtrans_categos") . " AS c\n                    WHERE b.cat IN(" . implode(",", $categos) . ") AND a.id_soft=b.soft AND {$filter} AND c.id_cat=b.cat\n                    GROUP BY b.soft\n                    {$order} LIMIT 0,{$limit}";
     } else {
         $sql = "SELECT a.*, c.name as namecat, c.id_cat\n                    FROM " . $db->prefix("dtrans_software") . " AS a, " . $db->prefix("dtrans_catsoft") . " AS b\n                    JOIN " . $db->prefix("dtrans_categos") . " AS c\n                    WHERE {$filter} AND a.id_soft=b.soft AND c.id_cat=b.cat\n                    GROUP BY b.soft\n                    {$order} LIMIT 0,{$limit}";
     }
     $result = $db->query($sql);
     while ($row = $db->fetchArray($result)) {
         $item = new DTSoftware();
         $item->assignVars($row);
         $ocat = new DTCategory($row['id_cat']);
         $items[] = array_merge($this->createItemData($item), array('category' => $row['namecat'], 'categoryid' => $row['id_cat'], 'categorylink' => $ocat->permalink()));
     }
     return $items;
 }