/** * Create a category listing page showing the categories in block styling. * @return string HTML for category listing page */ function CLASSIFIEDS_catList_blocks() { global $_CONF, $_TABLES, $LANG_ADVT, $_CONF_ADVT; global $CatListcolors; $T = new Template(CLASSIFIEDS_PI_PATH . '/templates'); $T->set_file('page', 'catlist_blocks.thtml'); $T->set_var('site_url', $_CONF['site_url']); $T->set_var('site_admin_url', $_CONF['site_admin_url']); // Get all the root categories $sql = "SELECT * FROM {$_TABLES['ad_category']} \n WHERE papa_id='' " . COM_getPermSQL('AND', 0, 2) . " ORDER BY cat_name ASC"; //echo $sql;die; $cats = DB_query($sql); if (!$cats) { return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert'); } // If no root categories exist, display just return a message if (DB_numRows($cats) == 0) { $T->set_var('no_cat_found', "<p align=\"center\" class=\"headmsg\">\n {$LANG_ADVT['no_cat_found']}</p>\n"); $T->parse('output', 'page'); return $T->finish($T->get_var('output')); } $max = count($CatListcolors); $i = 0; while ($catsrow = DB_fetchArray($cats)) { if ($catsrow['fgcolor'] == '' || $catsrow['bgcolor'] == '') { if ($i >= $max) { $i = 0; } $bgcolor = $CatListcolors[$i][0]; $fgcolor = $CatListcolors[$i][1]; $hdcolor = $CatListcolors[$i][2]; $i++; } else { $fgcolor = $catsrow['fgcolor']; $bgcolor = $catsrow['bgcolor']; } // For each category, find the total ad count (including subcats) // and display the subcats below it. $T->set_block('page', 'CatDiv', 'Div'); $T->set_var('bgcolor', $bgcolor); $T->set_var('fgcolor', $fgcolor); //$T->set_var('hdcolor', $hdcolor); $T->set_var('cat_url', CLASSIFIEDS_makeUrl('home', $catsrow['cat_id'])); $T->set_var('cat_name', $catsrow['cat_name']); $T->set_var('cat_desc', $catsrow['description']); $T->set_var('cat_ad_count', findTotalAds($catsrow['cat_id'])); if ($catsrow['image']) { $T->set_var('cat_image', CLASSIFIEDS_thumbUrl('cat/' . $catsrow['image'])); } else { $T->set_var('cat_image', ''); } $T->parse('Div', 'CatDiv', true); } $T->parse('output', 'page'); return $T->finish($T->get_var('output')); }
/** * Create an edit form for a category * * @param int $catid Category ID, zero for a new entry * @return string HTML for edit form */ public function Edit($cat_id = 0) { global $_CONF, $_TABLES, $LANG_ADVT, $_CONF_ADVT, $LANG_ACCESS, $_USER; $cat_id = (int) $cat_id; if ($cat_id > 0) { // Load the requested category $this->cat_id = $cat_id; $this->Read(); } $T = new Template(CLASSIFIEDS_PI_PATH . '/templates/admin'); $T->set_file('modify', 'catEditForm.thtml'); // create a dropdown list of only master categories //$T->set_var('sel_parent_cat', COM_optionList($_TABLES['ad_category'], // 'cat_id,cat_name', $parentcat, 1, "cat_id <> $catid AND papa_id=0")); // this code creates a complete dropdown including subcategories $T->set_var('sel_parent_cat', self::buildSelection($this->papa_id, 0, '', 'NOT', $this->cat_id)); if (!$this->isNew) { // If this is an existing category, load the template with the // categories values. $T->set_var(array('permissions_editor' => SEC_getPermissionsHTML($this->perm_owner, $this->perm_group, $this->perm_members, $this->perm_anon), 'ownername' => COM_getDisplayName($this->owner_id), 'owner_id' => $this->owner_id, 'group_dropdown' => SEC_getGroupDropdown($this->group_id, 3))); } else { // A new category gets default values $T->set_var(array('txt_sub_btn' => $LANG_ADVT['add_cat'], 'permissions_editor' => SEC_getPermissionsHTML($_CONF_ADVT['default_perm_cat'][0], $_CONF_ADVT['default_perm_cat'][1], $_CONF_ADVT['default_perm_cat'][2], $_CONF_ADVT['default_perm_cat'][3]), 'ownername' => COM_getDisplayName($_USER['uid']), 'owner_id' => $_USER['uid'], 'group_dropdown' => SEC_getGroupDropdown($_CONF_ADVT['defgrpcat'], 3))); } $T->set_var(array('location' => self::BreadCrumbs($this->cat_id, true), 'catname' => $this->cat_name, 'keywords' => $this->keywords, 'description' => $this->description, 'fgcolor' => $this->fgcolor, 'bgcolor' => $this->bgcolor, 'cat_id' => $this->cat_id, 'cancel_url' => CLASSIFIEDS_ADMIN_URL . '/index.php?admin=cat')); if ($this->image != '') { $T->set_var('existing_image', CLASSIFIEDS_thumbUrl($this->image)); } $T->parse('output', 'modify'); $display .= $T->finish($T->get_var('output')); return $display; }