function enth_get_categories($search = '', $start = 'none') { require 'config.php'; $db_link = mysql_connect($db_server, $db_user, $db_password) or die(DATABASE_CONNECT_ERROR . mysql_error()); mysql_select_db($db_database) or die(DATABASE_CONNECT_ERROR . mysql_error()); $query = "SELECT * FROM `{$db_category}` ORDER BY `catname`"; if ($search) { $query = "SELECT * FROM `{$db_category}` WHERE `catname` LIKE '%" . $search . "%' ORDER BY `catname`"; } if ($start != 'none' && ctype_digit($start)) { $settingq = "SELECT `value` FROM `{$db_settings}` " . "WHERE `setting` = 'per_page'"; $result = mysql_query($settingq); $row = mysql_fetch_array($result); $limit = $row['value']; $query .= " LIMIT {$start}, {$limit}"; } $result = mysql_query($query); if (!$result) { log_error(__FILE__ . ':' . __LINE__, 'Error executing query: <i>' . mysql_error() . '</i>; Query is: <code>' . $query . '</code>'); die(STANDARD_ERROR); } $cats = array(); while ($row = mysql_fetch_array($result)) { $cats[] = $row; } // get children, if there is a search $finalcats = $cats; if ($search) { foreach ($cats as $cat) { $finalcats = array_merge($finalcats, get_enth_category_children($cat['catid'])); } } return $finalcats; }
$ids = get_owned_by_category($catid, 2); } } } } if ((!isset($show_subcats_in_main_list) || !$show_subcats_in_main_list) && isset($_GET['cat'])) { // we then have to show the children of this category, if there are $children = get_enth_category_children(clean($_GET['cat'])); $cats = array(); $status_number = $status == 'pending' ? '0' : ($status == 'upcoming' ? 1 : 2); foreach ($children as $cat) { $cats[] = array('catid' => $cat['catid'], 'text' => $cat['catname'], 'parent' => get_category_parent($cat['catid']), 'qty' => count(get_owned_by_category($cat['catid'], $status_number))); } // check for empty categories! foreach ($cats as $index => $cat) { $children = get_enth_category_children($cat['catid']); $childqty = 0; foreach ($children as $c) { $childqty += count(get_owned_by_category($c['catid'], $status_number)); } if ($cat['qty'] == 0 && $childqty == 0) { unset($cats[$index]); } } if (count($cats) && (!isset($show_list) || !$show_list)) { // use dropdown show_owned_category_list(true, false); } else { if (count($cats) && isset($show_list) && $show_list) { show_owned_category_list(false, false); }
} else { $getcat = clean($_GET['cat']); if ($ancestors = array_reverse(get_ancestors($getcat))) { // get ancestors $text = ''; foreach ($ancestors as $a) { $text .= get_category_name($a) . ' > '; } } else { $text = get_category_name($getcat); } echo '<p class="show_joined_where_you_are">Showing listings ' . 'under the <i>' . str_replace('>', '»', rtrim($text, ' > ')) . '</i> category...</p>'; } if (!isset($show_subcats_in_main_list) || !$show_subcats_in_main_list) { // we then have to show the children of this category, if there are $children = get_enth_category_children(clean($_GET['cat'])); $cats = array(); foreach ($children as $cat) { $cats[] = array('catid' => $cat['catid'], 'text' => $cat['catname'], 'parent' => get_category_parent($cat['catid']), 'qty' => count(get_joined_by_category($cat['catid']))); } // check for empty categories! foreach ($cats as $index => $cat) { if ($cat['qty'] == 0) { unset($cats[$index]); } } // if there are subcats, then show these: if (count($cats)) { if (!isset($show_list) || !$show_list) { // use dropdown show_joined_category_list(true, false);
<tr><td colspan="2" class="right"> <input type="submit" value="Add this category" /> <input type="reset" value="Clear form" /> <input type="button" value="Cancel" onclick="javascript:window.location='categories.php';" /> </td></tr> </table></form> <?php } /*___________________________________________________________________DELETE__*/ } else { if ($action == 'delete') { if (isset($_GET['id']) && $_GET['id'] != '') { // make sure first that there are no children -- delete them first if (count(get_enth_category_children($_GET['id'])) == 0) { $cat = get_category_name($_GET['id']); $success = delete_category($_GET['id']); if ($success) { echo '<p class="success">Category <i>' . $cat . '</i> deleted.</p>'; } else { echo '<p class="error">Error deleting category. ' . 'Please try again.</p>'; } } else { echo '<p class="error">There are categories that are assigned as ' . 'children to this category. Please delete them before ' . 'attempting to delete this category.</p>'; } } /*_____________________________________________________________________EDIT__*/ } else { if ($action == 'edit') { $show_edit_form = true;