PageRenderTime 68ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/index.php

https://github.com/bitweaver/categories
PHP | 307 lines | 212 code | 65 blank | 30 comment | 55 complexity | e6ff7702de0287e3281e9fa2b147c7a8 MD5 | raw file
  1. <?php
  2. // $Header$
  3. // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  4. // All Rights Reserved. See below for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  6. //
  7. // $Header$
  8. //
  9. // Initialization
  10. require_once( '../../kernel/setup_inc.php' );
  11. if( !$gBitSystem->isPackageActive( 'categories' ) ) {
  12. $gBitSystem->fatalError( tra("This feature is disabled").": package_categories" );
  13. }
  14. if (!$gBitUser->hasPermission( 'p_categories_admin' )) {
  15. $gBitSystem->fatalError( tra("You dont have permission to use this feature") );
  16. }
  17. require_once( CATEGORIES_PKG_PATH.'categ_lib.php');
  18. require_once( CATEGORIES_PKG_PATH.'CatAdminTreeMaker.php' );
  19. if( defined( 'FILEGALS_PKG_PATH' ) ) {
  20. include_once( FILEGALS_PKG_PATH.'filegal_lib.php' );
  21. }
  22. if( defined( 'POLLS_PKG_PATH' ) ) {
  23. include_once( POLLS_PKG_PATH.'poll_lib.php' );
  24. if (!isset($polllib)) {
  25. $polllib = new PollLib();
  26. }
  27. }
  28. if( defined( 'ARTICLES_PKG_PATH' ) ) {
  29. include_once( ARTICLES_PKG_PATH.'BitArticle.php' );
  30. }
  31. if( defined( 'BLOGS_PKG_PATH' ) ) {
  32. include_once( BLOGS_PKG_PATH.'BitBlog.php' );
  33. }
  34. if( defined( 'WIKI_PKG_PATH' ) ) {
  35. include_once( WIKI_PKG_PATH.'BitPage.php' );
  36. }
  37. if( defined( 'DIRECTORY_PKG_PATH' ) ) {
  38. include_once( DIRECTORY_PKG_PATH.'dir_lib.php' );
  39. }
  40. if( defined( 'TRACKERS_PKG_PATH' ) ) {
  41. include_once( TRACKERS_PKG_PATH.'tracker_lib.php' );
  42. }
  43. // Check for parent category or set to 0 if not present
  44. if (!isset($_REQUEST["parent_id"])) {
  45. $_REQUEST["parent_id"] = 1;
  46. }
  47. $gBitSmarty->assign('parent_id', $_REQUEST["parent_id"]);
  48. if (isset($_REQUEST["addpage"])) {
  49. // Here we categorize multiple pages at once
  50. foreach ($_REQUEST['class_content'] as $contentId ) {
  51. $categlib->categorize_page( $contentId, $_REQUEST["parent_id"] );
  52. }
  53. }
  54. if (isset($_REQUEST["addpoll"])) {
  55. // Here we categorize a poll
  56. $categlib->categorize_poll($_REQUEST["poll_id"], $_REQUEST["parent_id"]);
  57. }
  58. if (isset($_REQUEST["addfaq"])) {
  59. // Here we categorize a faq
  60. $categlib->categorize_faq($_REQUEST["faq_id"], $_REQUEST["parent_id"]);
  61. }
  62. if (isset($_REQUEST["addtracker"])) {
  63. // Here we categorize a tracker
  64. $categlib->categorize_tracker($_REQUEST["tracker_id"], $_REQUEST["parent_id"]);
  65. }
  66. if (isset($_REQUEST["addquiz"])) {
  67. // Here we categorize a quiz
  68. $categlib->categorize_quiz($_REQUEST["quiz_id"], $_REQUEST["parent_id"]);
  69. }
  70. if (isset($_REQUEST["addforum"])) {
  71. // Here we categorize a forum
  72. $categlib->categorize_forum($_REQUEST["forum_id"], $_REQUEST["parent_id"]);
  73. }
  74. if (isset($_REQUEST["addgallery"])) {
  75. // Here we categorize an image gallery
  76. $categlib->categorize_gallery($_REQUEST["gallery_id"], $_REQUEST["parent_id"]);
  77. }
  78. if (isset($_REQUEST["addfilegallery"])) {
  79. // Here we categorize a file gallery
  80. $categlib->categorize_file_gallery($_REQUEST["file_gallery_id"], $_REQUEST["parent_id"]);
  81. }
  82. if (isset($_REQUEST["addarticle"])) {
  83. // Here we categorize an article
  84. $categlib->categorize_article($_REQUEST["article_id"], $_REQUEST["parent_id"]);
  85. }
  86. if (isset($_REQUEST["addblog"])) {
  87. // Here we categorize a blog
  88. $categlib->categorize_blog($_REQUEST["blog_id"], $_REQUEST["parent_id"]);
  89. }
  90. if (isset($_REQUEST["adddirectory"])) {
  91. // Here we categorize a directory category
  92. $categlib->categorize_directory($_REQUEST["directoryId"], $_REQUEST["parent_id"]);
  93. }
  94. if (isset($_REQUEST["category_id"])) {
  95. $info = $categlib->get_category($_REQUEST["category_id"]);
  96. } else {
  97. $_REQUEST["category_id"] = 0;
  98. $info["name"] = '';
  99. $info["description"] = '';
  100. }
  101. if (isset($_REQUEST["removeObject"])) {
  102. $categlib->remove_object_from_category($_REQUEST["removeObject"], $_REQUEST["parent_id"]);
  103. }
  104. if (isset($_REQUEST["removeCat"])) {
  105. $categlib->remove_category($_REQUEST["removeCat"]);
  106. }
  107. if (isset($_REQUEST["save"]) && isset($_REQUEST["name"]) && strlen($_REQUEST["name"]) > 0) {
  108. // Save
  109. if ($_REQUEST["category_id"]) {
  110. $categlib->update_category($_REQUEST["category_id"], $_REQUEST["name"], $_REQUEST["description"], $_REQUEST["parent_id"]);
  111. } else {
  112. $categlib->add_category($_REQUEST["parent_id"], $_REQUEST["name"], $_REQUEST["description"]);
  113. }
  114. $info["name"] = '';
  115. $info["description"] = '';
  116. $_REQUEST["category_id"] = 0;
  117. }
  118. $gBitSmarty->assign('category_id', $_REQUEST["category_id"]);
  119. $gBitSmarty->assign('name', $info["name"]);
  120. $gBitSmarty->assign('description', $info["description"]);
  121. // If the parent category is not zero get the category path
  122. if( empty( $_REQUEST["parent_id"] ) ) {
  123. $_REQUEST["parent_id"] = 0;
  124. }
  125. $catInfo = $categlib->get_category($_REQUEST["parent_id"]);
  126. $catInfo['path'] = $categlib->get_category_path_admin($_REQUEST["parent_id"]);
  127. $gBitSmarty->assign('catInfo', $catInfo);
  128. // Convert $childrens
  129. //$debugger->var_dump('$children');
  130. $ctall = $categlib->get_all_categories_ext();
  131. $tree_nodes = array();
  132. // XINGICON need to remove these non biticon icon paths!
  133. foreach ($ctall as $c) {
  134. $tree_nodes[] = array(
  135. "id" => $c["category_id"],
  136. "parent" => $c["parent_id"],
  137. "data" => '<a class="catname" href="'.CATEGORIES_PKG_URL.'admin/index.php?parent_id=' . $c["category_id"] . '" title="' . tra( 'Objects in category'). ':' . $c["objects"] . '">' . $c["name"] . '</a>',
  138. // "data" => '<a class="catname" href="'.CATEGORIES_PKG_URL.'admin/index.php?parent_id=' . $c["category_id"] . '" title="' . tra( 'Child categories'). ':' . $c["children"] . ' ' . tra( 'Objects in category'). ':' . $c["objects"] . '">' . $c["name"] . '</a>',
  139. "edit" =>
  140. '<a class="floaticon" href="'.CATEGORIES_PKG_URL.'admin/index.php?parent_id=' . $c["parent_id"] . '&amp;category_id=' . $c["category_id"] . '#editcreate" title="' . tra( 'edit'). '"><img class="icon" src="'.LIBERTY_PKG_URL.'icons/edit.gif" /></a>',
  141. "remove" =>
  142. '<a class="floaticon" href="'.CATEGORIES_PKG_URL.'admin/index.php?parent_id=' . $c["parent_id"] . '&amp;removeCat=' . $c["category_id"] . '" title="' . tra( 'remove'). '"><img class="icon" src="'.LIBERTY_PKG_URL.'icons/delete.png" /></a>',
  143. "children" => 0,
  144. // "children" => $c["children"],
  145. "objects" => $c["objects"]
  146. );
  147. }
  148. //$debugger->var_dump('$tree_nodes');
  149. $tm = new CatAdminTreeMaker("admcat");
  150. $res = $tm->make_tree($_REQUEST["parent_id"], $tree_nodes);
  151. $gBitSmarty->assign('tree', $res);
  152. if ( empty( $_REQUEST["sort_mode"] ) ) {
  153. $sort_mode = 'name_asc';
  154. } else {
  155. $sort_mode = $_REQUEST["sort_mode"];
  156. }
  157. if (!isset($_REQUEST["offset"])) {
  158. $offset = 0;
  159. } else {
  160. $offset = $_REQUEST["offset"];
  161. }
  162. $gBitSmarty->assign_by_ref('offset', $offset);
  163. if (isset($_REQUEST["find"])) {
  164. $find = $_REQUEST["find"];
  165. } else {
  166. $find = '';
  167. }
  168. $gBitSmarty->assign('find', $find);
  169. if (isset($_REQUEST["find_objects"])) {
  170. $find_objects = $_REQUEST["find_objects"];
  171. } else {
  172. $find_objects = '';
  173. }
  174. $gBitSmarty->assign('find_objects', $find_objects);
  175. $gBitSmarty->assign_by_ref('sort_mode', $sort_mode);
  176. $gBitSmarty->assign_by_ref('find', $find);
  177. $objects = $categlib->list_category_objects($_REQUEST["parent_id"], $offset, $max_records, $sort_mode, $find);
  178. $gBitSmarty->assign_by_ref('objects', $objects["data"]);
  179. $cant_pages = ceil($objects["cant"] / $max_records);
  180. $gBitSmarty->assign_by_ref('cant_pages', $cant_pages);
  181. $gBitSmarty->assign('actual_page', 1 + ($offset / $max_records));
  182. if ($objects["cant"] > ($offset + $max_records)) {
  183. $gBitSmarty->assign('next_offset', $offset + $max_records);
  184. } else {
  185. $gBitSmarty->assign('next_offset', -1);
  186. }
  187. // If offset is > 0 then prev_offset
  188. if ($offset > 0) {
  189. $gBitSmarty->assign('prev_offset', $offset - $max_records);
  190. } else {
  191. $gBitSmarty->assign('prev_offset', -1);
  192. }
  193. $categories = $categlib->get_all_categories();
  194. $gBitSmarty->assign_by_ref('categories', $categories);
  195. if ( $gBitSystem->isPackageActive( 'imagegals' ) ) {
  196. $galleries = $gBitSystem->list_galleries(0, -1, 'name_desc', 'admin', $find_objects);
  197. $gBitSmarty->assign_by_ref('galleries', $galleries["data"]);
  198. }
  199. if ( $gBitSystem->isPackageActive( 'filegals' ) ) {
  200. $file_galleries = $filegallib->list_file_galleries(0, -1, 'name_desc', 'admin', $find_objects);
  201. $gBitSmarty->assign_by_ref('file_galleries', $file_galleries["data"]);
  202. }
  203. if ( $gBitSystem->isPackageActive( 'tiki_forums' ) ) {
  204. $forums = $gBitSystem->list_forums(0, -1, 'name_asc', $find_objects);
  205. $gBitSmarty->assign_by_ref('forums', $forums["data"]);
  206. }
  207. if ( $gBitSystem->isPackageActive( 'polls' ) ) {
  208. $polls = $polllib->list_polls(0, -1, 'title_asc', $find_objects);
  209. $gBitSmarty->assign_by_ref('polls', $polls["data"]);
  210. }
  211. if ( $gBitSystem->isPackageActive( 'blogs' ) ) {
  212. $blogs = $gBlog->list_blogs(0, -1, 'title_asc', $find_objects);
  213. $gBitSmarty->assign_by_ref('blogs', $blogs["data"]);
  214. }
  215. if ( $gBitSystem->isPackageActive( 'wiki' ) ) {
  216. $pages = $wikilib->getList(0, -1, 'title_asc', $find_objects);
  217. $gBitSmarty->assign_by_ref('pages', $pages["data"]);
  218. }
  219. if ( $gBitSystem->isPackageActive( 'faqs' ) ) {
  220. $faqs = $gBitSystem->list_faqs(0, -1, 'title_asc', $find_objects);
  221. $gBitSmarty->assign_by_ref('faqs', $faqs["data"]);
  222. }
  223. if ( $gBitSystem->isPackageActive( 'quizzes' ) ) {
  224. $quizzes = $gBitSystem->list_quizzes(0, -1, 'name_asc', $find_objects);
  225. $gBitSmarty->assign_by_ref('quizzes', $quizzes["data"]);
  226. }
  227. if ( $gBitSystem->isPackageActive( 'trackers' ) ) {
  228. $trackers = $trklib->list_trackers(0, -1, 'name_asc', $find_objects);
  229. $gBitSmarty->assign_by_ref('trackers', $trackers["data"]);
  230. }
  231. if ( $gBitSystem->isPackageActive( 'articles' ) ) {
  232. $art = new BitArticle();
  233. $articles = $art->getList( $_REQUEST );
  234. $gBitSmarty->assign_by_ref('articles', $articles["data"]);
  235. }
  236. if ( $gBitSystem->isPackageActive( 'directory' ) ) {
  237. $directories = $dirlib->dir_list_all_categories(0, -1, 'name_asc', $find_objects);
  238. $gBitSmarty->assign_by_ref('directories', $directories["data"]);
  239. }
  240. // Display the template
  241. $gBitSystem->display( 'bitpackage:categories/categories_admin.tpl', NULL, array( 'display_mode' => 'admin' ));
  242. ?>