|
From: FlorinCB <ory...@us...> - 2008-09-09 06:25:03
|
Update of /cvsroot/mxbb/mx_music/music_box/modules In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20992/music_box/modules Modified Files: music_cat.php Log Message: subcategory support fully added Index: music_cat.php =================================================================== RCS file: /cvsroot/mxbb/mx_music/music_box/modules/music_cat.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** music_cat.php 7 Sep 2008 18:06:42 -0000 1.7 --- music_cat.php 9 Sep 2008 06:23:57 -0000 1.8 *************** *** 20,30 **** // Check the request // ------------------------------------ ! if( isset($HTTP_POST_VARS['cat_id']) ) ! { ! $cat_id = intval($HTTP_POST_VARS['cat_id']); ! } ! else if( isset($HTTP_GET_VARS['cat_id']) ) { ! $cat_id = intval($HTTP_GET_VARS['cat_id']); } else --- 20,26 ---- // Check the request // ------------------------------------ ! if (!$mx_request_vars->is_empty_request('cat_id')) { ! $cat_id = $mx_request_vars->request('cat_id', MX_TYPE_INT, 0); } else *************** *** 32,39 **** --- 28,387 ---- mx_message_die(GENERAL_ERROR, 'No categories specified'); } + + // If not set, set the subcat output count to 50 + //To do: Add a setting in AdminCP for maximum number of subcategories to show in a category and add pagination + $count = $mx_request_vars->request('c', MX_TYPE_INT, 50); // // END check request // + // --------------------------------------------- + // Ckeck is category has subcats start + // --------------------------------------------- + $sql_count = "SELECT count(cat_id) as count + FROM ". MUSIC_CAT_TABLE ." + WHERE cat_parent = " . $cat_id; + if (($result_count = $db->sql_query($sql_count))) + { + $cat_count = $db->sql_fetchrow($result_count); + } + else + { + $cat_count = ""; + } + // -------------------------------------------- + // Ckeck is category has subcats end + // -------------------------------------------- + + //Start subcats + //If cat has subcats pass them to the template + if ($cat_count > 0) + { + + $sql = "SELECT c.*, COUNT(s.song_id) AS count + FROM ". MUSIC_CAT_TABLE ." AS c + LEFT JOIN ". MUSIC_TABLE ." AS s ON c.cat_id = s.song_cat_id + WHERE cat_parent = " . $cat_id . " + GROUP BY cat_id + ORDER BY cat_order ASC"; + if( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not query subcategories list', '', __LINE__, __FILE__, $sql); + } + + $catrows = array(); + + while( $row = $db->sql_fetchrow($result) ) + { + $music_user_access = music_user_access($row['cat_id'], $row, 1, 0, 0, 0, 0, 0); // VIEW + if ($music_user_access['view'] == 1) + { + $catrows[] = $row; + } + } + + $allowed_cat = ''; // For Recent Public Songs below + + // + // $catrows now stores all categories which this user can view. Dump them out! + // + for ($i = 0; $i < count($catrows); $i++) + { + // -------------------------------- + // Build allowed category-list (for recent songs after here) + // -------------------------------- + + $allowed_cat .= ($allowed_cat == '') ? $catrows[$i]['cat_id'] : ',' . $catrows[$i]['cat_id']; + + + // -------------------------------- + // Build moderators list + // -------------------------------- + + $l_moderators = ''; + $moderators_list = ''; + + $grouprows= array(); + + if( $catrows[$i]['cat_moderator_groups'] != '') + { + // We have usergroup_ID, now we need usergroup name + $sql = "SELECT group_id, group_name + FROM " . GROUPS_TABLE . " + WHERE group_single_user <> 1 + AND group_type <> ". GROUP_HIDDEN ." + AND group_id IN (". $catrows[$i]['cat_moderator_groups'] .") + ORDER BY group_name ASC"; + if ( !$result = $db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not obtain usergroups data', '', __LINE__, __FILE__, $sql); + } + + while( $row = $db->sql_fetchrow($result) ) + { + $grouprows[] = $row; + } + } + + if( count($grouprows) > 0 ) + { + $l_moderators = $lang['Moderators']; + + for ($j = 0; $j < count($grouprows); $j++) + { + $group_link = '<a href="'. mx_append_sid($phpbb_root_path. "groupcp.$phpEx?". POST_GROUPS_URL .'='. $grouprows[$j]['group_id']) .'">'. $grouprows[$j]['group_name'] .'</a>'; + + $moderators_list .= ($moderators_list == '') ? $group_link : ', ' . $group_link; + } + } + + // ------------------------------------------ + // Get Last song of this Category + // ------------------------------------------ + + if ($catrows[$i]['cat_type'] == 0) + { + if ($catrows[$i]['count'] == 0) + { + // + // Oh, this category is empty + // + $last_song_info = $lang['No_Songs']; + $u_last_song = ''; + $last_song_title = ''; + } + else + { + // ---------------------------- + // Check Song Approval + // ---------------------------- + + if(($catrows[$i]['cat_approval'] == MUSIC_ADMIN) or ($catrows[$i]['cat_approval'] == MUSIC_MOD)) + { + $song_approval_sql = 'AND s.song_approval = 1'; // song Approval ON + } + else + { + $song_approval_sql = ''; // song Approval OFF + } + + + // ---------------------------- + // OK, we may do a query now... + // ---------------------------- + + $sql = "SELECT s.song_id, s.song_title, s.song_singer, s.song_user_id, s.song_username, s.song_time, s.song_cat_id, u.user_id, u.username + FROM ". MUSIC_TABLE ." AS s LEFT JOIN ". USERS_TABLE ." AS u ON s.song_user_id = u.user_id + WHERE s.song_cat_id = '". $catrows[$i]['cat_id'] ."' $song_approval_sql + ORDER BY s.song_time DESC + LIMIT 1"; + if ( !$result = $db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not get last song information', '', __LINE__, __FILE__, $sql); + } + $lastrow = $db->sql_fetchrow($result); + + + // ---------------------------- + // Write the Date + // ---------------------------- + + $last_song_info = music_create_date($board_config['default_dateformat'], $lastrow['song_time'], $board_config['board_timezone']); + + $last_song_info .= '<br />'; + + + // ---------------------------- + // Write username of last poster + // ---------------------------- + + if( ($lastrow['user_id'] == MUSIC_GUEST) or ($lastrow['username'] == '') ) + { + $last_song_info .= ($lastrow['song_username'] == '') ? $lang['Guest'] : $lastrow['song_username']; + } + else + { + $last_song_info .= $lang['Poster'] .': <a href="'. mx_append_sid($phpbb_root_path . "profile.$phpEx?mode=viewprofile&". POST_USERS_URL .'='. $lastrow['user_id']) .'">'. $lastrow['username'] .'</a>'; + } + + + // ---------------------------- + // Write the last song's title. + // Truncate it if it's too long + // ---------------------------- + + if( !isset($music_config['last_song_title_length']) ) + { + $music_config['last_song_title_length'] = 25; + } + + $lastrow['song_title'] = $lastrow['song_title']; + + if (strlen($lastrow['song_title']) > $music_config['last_song_title_length']) + { + $lastrow['song_title'] = substr($lastrow['song_title'], 0, $music_config['last_song_title_length']) . '...'; + } + + $last_song_info .= '<br />'. $lang['Song_Title'] .': <a href="'; + + $last_song_info .= mx_append_sid(this_mo_mxurl("music_mode=music_page&song_id=". $lastrow['song_id'])) .'">' ; + + $last_song_info .= $lastrow['song_title'] .'</a>'; + } + // END of Last Song + + $template->assign_vars(array( + 'L_PUBLIC_CATS' => $lang['Public_Categories'], + 'L_CAT_VIEWS' => $lang['Cat_Views'], + 'L_LAST_SONG' => $lang['Last_Song'], + 'SWITCH_HAS_CATROW' => true) + ); + + $template->assign_block_vars('catrow', array( + 'U_VIEW_CAT' => mx_append_sid(this_mo_mxurl("music_mode=music_cat&cat_id=". $catrows[$i]['cat_id'])), + 'U_VIEW_PIC_CAT' => mx_append_sid(this_mo_mxurl("music_mode=music_pic_cat&cat_id=". $catrows[$i]['cat_id'])), + 'U_VIEW_MEDIA_CAT' => mx_append_sid(this_mo_mxurl("music_mode=music_media_cat&cat_id=". $catrows[$i]['cat_id'])), + 'CAT_TITLE' => $catrows[$i]['cat_title'], + 'CAT_IMG' => $images['folder'], + 'CAT_DESC' => $catrows[$i]['cat_desc'], + 'SONGS' => $catrows[$i]['count'], + 'CAT_VIEWS' => $catrows[$i]['cat_views'], + 'L_MODERATORS' => $l_moderators, + 'L_ALL_CAT_PICS' => $lang['Category_pics'], + 'L_ALL_CAT_SONGS' => $lang['Category_songs'], + 'MODERATORS' => $moderators_list, + 'LAST_SONG_INFO' => $last_song_info) + ); + + $sql = "SELECT s.*, u.user_id, u.username, r.rate_song_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments + FROM ". MUSIC_TABLE ." AS s + LEFT JOIN ". USERS_TABLE ." AS u ON s.song_user_id = u.user_id + LEFT JOIN ". MUSIC_RATE_TABLE ." AS r ON s.song_id = r.rate_song_id + LEFT JOIN ". MUSIC_COMMENT_TABLE ." AS c ON s.song_id = c.comment_song_id + WHERE s.song_cat_id = '". $catrows[$i]['cat_id'] ."' $song_approval_sql + AND s.song_filetype NOT LIKE 'jpg' + AND s.song_filetype NOT LIKE 'gif' + AND s.song_filetype NOT LIKE 'png' + GROUP BY s.song_id"; + if( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not query songs information', '', __LINE__, __FILE__, $sql); + } + + $mediarow = array(); + + while( $row = $db->sql_fetchrow($result) ) + { + $mediarow[] = $row; + } + + $total_media = count($mediarow); + + if(!empty($template->xs_version)) + { + if ($total_media > 0) + { + $template->assign_block_vars('catrow.virtualmediacat', array()); + } + } + + $sql = "SELECT s.*, u.user_id, u.username, r.rate_song_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT c.comment_id) AS comments + FROM ". MUSIC_TABLE ." AS s + LEFT JOIN ". USERS_TABLE ." AS u ON s.song_user_id = u.user_id + LEFT JOIN ". MUSIC_RATE_TABLE ." AS r ON s.song_id = r.rate_song_id + LEFT JOIN ". MUSIC_COMMENT_TABLE ." AS c ON s.song_id = c.comment_song_id + WHERE s.song_cat_id = '". $catrows[$i]['cat_id'] ."' $song_approval_sql + GROUP BY s.song_id"; + if( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not query songs information', '', __LINE__, __FILE__, $sql); + } + + $totalrow = array(); + + while( $row = $db->sql_fetchrow($result) ) + { + $totalrow[] = $row; + } + + $total_items = count($totalrow); + + $total_images = $total_items - $total_media; + + if(!empty($template->xs_version)) + { + if ($total_images > 0) + { + $template->assign_block_vars('catrow.virtualimagecat', array()); + } + } + } + else + { + // this is a parent category + $sc_sql = "SELECT * + FROM ". MUSIC_CAT_TABLE ." + WHERE cat_parent = " . $catrows[$i]['cat_id'] . " + GROUP BY cat_id + ORDER BY cat_order ASC"; + + if ( !($sc_result = $db->sql_query($sc_sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Could not query sub categories', '', __LINE__, __FILE__, $sql); + } + + $sql_count = "SELECT count(cat_id) as count + FROM ". MUSIC_CAT_TABLE ." + WHERE cat_parent = " . $catrows[$i]['cat_id']; + if ( ($result_count = $db->sql_query($sql_count)) ) + { + $subcat_count = $db->sql_fetchrow($result_count); + $subcat_count = $subcat_count['count'] . " sub catagories"; + } + else + { + $subcat_count = ""; + } + + $subcats = '<br /><span class="gensmall" style="font-weight: bold;">' . $lang['Music_sub_categories'] . ':<br />'; + while ( $subcatrow = $db->sql_fetchrow($sc_result) ) + { + $subcats .= ' <img src="' . $images['folder'] . '" alt="' . $subcatrow['cat_name'] . '" title="' . $subcatrow['cat_name'] . '" /> <a class="gensmall" href="' . mx_append_sid(this_mo_mxurl('music_mode=music_cat&cat_id='. $subcatrow['cat_id'])) . '">' . $subcatrow['cat_title'] . '</a></li><br />'; + } + $subcats .= '</span><br />'; + + $template->assign_block_vars('catrow', array( + 'U_VIEW_CAT' => mx_append_sid(this_mo_mxurl("music_mode=music_index&c=". $catrows[$i]['cat_id'])), + 'CAT_TITLE' => $catrows[$i]['cat_title'], + 'CAT_DESC' => $catrows[$i]['cat_desc'], + 'SONGS' => $subcat_count, + 'CAT_IMG' => $images['forum'], + 'CAT_VIEWS' => $catrows[$i]['cat_views'], + 'L_MODERATORS' => $l_moderators, + 'L_ALL_CAT_PICS' => $lang['Category_pics'], + 'L_ALL_CAT_SONGS' => $lang['Category_songs'], + 'MODERATORS' => $moderators_list, + 'LAST_SONG_INFO' => $last_song_info) + ); + + if ($music_config['show_index_subcats'] == 1) + { + $template->assign_block_vars('catrow.subcat_link', array( + 'L_SUBCATS' => $lang['Music_sub_categories'], + 'SUBCATS' => $subcats) + ); + } + elseif ($userdata['user_level'] == ADMIN) + { + $template->assign_block_vars('catrow.subcat_link', array( + 'L_SUBCATS' => '<i>' . $lang['Music_sub_categories'] . '</i>', + 'SUBCATS' => $subcats) + ); + } + } + } + } + //Subcats end + // ------------------------------------ // Get this cat info |