'; $navigation.= $lang['home']; $navigation.= ''; $navigation.= $separator; $current_category = get_cat_info($_GET['parent_id']); $navigation.= get_cat_display_name($current_category['name'], $separator, $base_url.'&parent_id=', false); } // +-----------------------------------------------------------------------+ // | rank updates | // +-----------------------------------------------------------------------+ $current_rank = 0; if (isset($_GET['up']) and is_numeric($_GET['up'])) { // 1. searching the id of the category just above at the same level while (list ($id,$current) = each($categories)) { if ($current['id'] == $_GET['up']) { $current_rank = $current['rank']; break; } } if ($current_rank > 1) { // 2. Exchanging ranks between the two categories $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = '.($current_rank-1).' WHERE id = '.$_GET['up'].' ;'; pwg_query($query); $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = '.$current_rank.' WHERE id = '.$categories[($current_rank-1)]['id'].' ;'; pwg_query($query); // 3. Updating the cache array $categories[$current_rank] = $categories[($current_rank-1)]; $categories[($current_rank-1)] = $current; } else { // 2. Updating the rank of our category to be after the previous max rank $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = '.(count($categories) + 1).' WHERE id = '.$_GET['up'].' ;'; pwg_query($query); $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = rank-1 WHERE id_uppercat '; if (empty($_GET['parent_id'])) { $query.= 'IS NULL'; } else { $query.= '= '.$_GET['parent_id']; } $query.= ' ;'; pwg_query($query); // 3. Updating the cache array array_push($categories, $current); array_shift($categories); } } else if (isset($_GET['down']) and is_numeric($_GET['down'])) { // 1. searching the id of the category just above at the same level while (list ($id,$current) = each($categories)) { if ($current['id'] == $_GET['down']) { $current_rank = $current['rank']; break; } } if ($current_rank < count($categories)) { // 2. Exchanging ranks between the two categories $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = '.($current_rank+1).' WHERE id = '.$_GET['down'].' ;'; pwg_query($query); $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = '.$current_rank.' WHERE id = '.$categories[($current_rank+1)]['id'].' ;'; pwg_query($query); // 3. Updating the cache array $categories[$current_rank]=$categories[($current_rank+1)]; $categories[($current_rank+1)] = $current; } else { // 2. updating the rank of our category to be the first one $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = 0 WHERE id = '.$_GET['down'].' ;'; pwg_query($query); $query = ' UPDATE '.CATEGORIES_TABLE.' SET rank = rank+1 WHERE id_uppercat '; if (empty($_GET['parent_id'])) { $query.= 'IS NULL'; } else { $query.= '= '.$_GET['parent_id']; } $query.= ' ;'; pwg_query($query); // 3. Updating the cache array array_unshift($categories, $current); array_pop($categories); } } reset($categories); // +-----------------------------------------------------------------------+ // | template initialization | // +-----------------------------------------------------------------------+ $template->set_filenames(array('categories'=>'admin/cat_list.tpl')); $template->assign_vars(array( 'CATEGORIES_NAV'=>$navigation, 'NEXT_RANK'=>count($categories)+1, 'L_ADD_VIRTUAL'=>$lang['cat_add'], 'L_SUBMIT'=>$lang['submit'], 'L_STORAGE'=>$lang['storage'], 'L_NB_IMG'=>$lang['pictures'], 'L_MOVE_UP'=>$lang['cat_up'], 'L_MOVE_DOWN'=>$lang['cat_down'], 'L_EDIT'=>$lang['edit'], 'L_INFO_IMG'=>$lang['cat_image_info'], 'L_DELETE'=>$lang['delete'], )); $tpl = array('cat_first','cat_last'); // +-----------------------------------------------------------------------+ // | errors & infos | // +-----------------------------------------------------------------------+ if (count($errors) != 0) { $template->assign_block_vars('errors',array()); foreach ($errors as $error) { $template->assign_block_vars('errors.error',array('ERROR'=>$error)); } } if (count($infos) != 0) { $template->assign_block_vars('infos',array()); foreach ($infos as $info) { $template->assign_block_vars('infos.info',array('INFO'=>$info)); } } // +-----------------------------------------------------------------------+ // | Categories display | // +-----------------------------------------------------------------------+ while (list($id,$category) = each($categories)) { $images_folder = PHPWG_ROOT_PATH.'template/'; $images_folder.= $user['template'].'/admin/images'; if ($category['visible'] == 'false') { $image_src = $images_folder.'/icon_folder_lock.gif'; $image_alt = $lang['cat_private']; $image_title = $lang['cat_private']; } else if (empty($category['dir'])) { $image_src = $images_folder.'/icon_folder_link.gif'; $image_alt = $lang['cat_virtual']; $image_title = $lang['cat_virtual']; } else { // (Gweltas) May be should we have to introduce a computed field in the // table to avoid this query -> (z0rglub) no because the number of // sub-categories depends on permissions $query = ' SELECT COUNT(id) AS nb_sub_cats FROM '. CATEGORIES_TABLE.' WHERE id_uppercat = '.$category['id'].' ;'; $row = mysql_fetch_array(pwg_query($query)); if ($row['nb_sub_cats'] > 0) { $image_src = $images_folder.'/icon_subfolder.gif'; } else { $image_src = $images_folder.'/icon_folder.gif'; } $image_alt = ''; $image_title = ''; } $base_url = PHPWG_ROOT_PATH.'admin.php?page='; $cat_list_url = $base_url.'cat_list'; $self_url = $cat_list_url; if (isset($_GET['parent_id'])) { $self_url.= '&parent_id='.$_GET['parent_id']; } $template->assign_block_vars( 'category', array( 'CATEGORY_IMG_SRC'=>$image_src, 'CATEGORY_IMG_ALT'=>$image_alt, 'CATEGORY_IMG_TITLE'=>$image_title, 'CATEGORY_NAME'=>$category['name'], 'CATEGORY_DIR'=>@$category['dir'], 'CATEGORY_NB_IMG'=>$category['nb_images'], 'U_CATEGORY'=> add_session_id($cat_list_url.'&parent_id='.$category['id']), 'U_MOVE_UP'=>add_session_id($self_url.'&up='.$category['id']), 'U_MOVE_DOWN'=>add_session_id($self_url.'&down='.$category['id']), 'U_CAT_EDIT'=> add_session_id($base_url.'cat_modify&cat_id='.$category['id']), 'U_CAT_DELETE'=>add_session_id($self_url.'&delete='.$category['id']), 'U_INFO_IMG' => add_session_id($base_url.'infos_images&cat_id='.$category['id']) )); if (!empty($category['dir'])) { $template->assign_block_vars('category.storage' ,array()); } else { $template->assign_block_vars('category.virtual' ,array()); } if ($category['nb_images'] > 0) { $template->assign_block_vars('category.image_info' ,array()); } else { $template->assign_block_vars('category.no_image_info' ,array()); } } // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); ?>