Annotation of /mambo/branches/4.7/administrator/components/com_categories/admin.categories.php
Parent Directory
|
Revision Log
Revision 1292 - (view) (download)
| 1 : | cauld | 978 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo | ||
| 4 : | * @subpackage Categories | ||
| 5 : | * @copyright Refer to copyright.php | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * @author Mambo Foundation Inc see README.php | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 14 : | require_once($mosConfig_absolute_path.'/components/com_content/content.class.php'); | ||
| 15 : | |||
| 16 : | // get parameters from the URL or submitted form | ||
| 17 : | $section = mosGetParam( $_REQUEST, 'section', 'content' ); | ||
| 18 : | $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); | ||
| 19 : | enjoyman | 1235 | if (!$cid) $id = mosGetParam( $_REQUEST, 'id', 0 ); |
| 20 : | cauld | 978 | |
| 21 : | switch ($task) { | ||
| 22 : | case 'new': | ||
| 23 : | editCategory( 0, $section ); | ||
| 24 : | break; | ||
| 25 : | |||
| 26 : | case 'edit': | ||
| 27 : | editCategory( intval( $cid[0] ) ); | ||
| 28 : | break; | ||
| 29 : | |||
| 30 : | case 'editA': | ||
| 31 : | editCategory( intval( $id ) ); | ||
| 32 : | break; | ||
| 33 : | |||
| 34 : | case 'moveselect': | ||
| 35 : | moveCategorySelect( $option, $cid, $section ); | ||
| 36 : | break; | ||
| 37 : | |||
| 38 : | case 'movesave': | ||
| 39 : | moveCategorySave( $cid, $section ); | ||
| 40 : | break; | ||
| 41 : | |||
| 42 : | case 'copyselect': | ||
| 43 : | copyCategorySelect( $option, $cid, $section ); | ||
| 44 : | break; | ||
| 45 : | |||
| 46 : | case 'copysave': | ||
| 47 : | copyCategorySave( $cid, $section ); | ||
| 48 : | break; | ||
| 49 : | |||
| 50 : | case 'go2menu': | ||
| 51 : | case 'go2menuitem': | ||
| 52 : | case 'menulink': | ||
| 53 : | case 'save': | ||
| 54 : | case 'apply': | ||
| 55 : | saveCategory( $task ); | ||
| 56 : | break; | ||
| 57 : | |||
| 58 : | case 'remove': | ||
| 59 : | removeCategories( $section, $cid ); | ||
| 60 : | break; | ||
| 61 : | |||
| 62 : | case 'publish': | ||
| 63 : | publishCategories( $section, $id, $cid, 1 ); | ||
| 64 : | break; | ||
| 65 : | |||
| 66 : | case 'unpublish': | ||
| 67 : | publishCategories( $section, $id, $cid, 0 ); | ||
| 68 : | break; | ||
| 69 : | |||
| 70 : | case 'cancel': | ||
| 71 : | cancelCategory(); | ||
| 72 : | break; | ||
| 73 : | |||
| 74 : | case 'orderup': | ||
| 75 : | orderCategory( $cid[0], -1 ); | ||
| 76 : | break; | ||
| 77 : | |||
| 78 : | case 'orderdown': | ||
| 79 : | orderCategory( $cid[0], 1 ); | ||
| 80 : | break; | ||
| 81 : | |||
| 82 : | case 'accesspublic': | ||
| 83 : | accessMenu( $cid[0], 0, $section ); | ||
| 84 : | break; | ||
| 85 : | |||
| 86 : | case 'accessregistered': | ||
| 87 : | accessMenu( $cid[0], 1, $section ); | ||
| 88 : | break; | ||
| 89 : | |||
| 90 : | case 'accessspecial': | ||
| 91 : | accessMenu( $cid[0], 2, $section ); | ||
| 92 : | break; | ||
| 93 : | |||
| 94 : | case 'saveorder': | ||
| 95 : | saveOrder( $cid, $section ); | ||
| 96 : | break; | ||
| 97 : | |||
| 98 : | default: | ||
| 99 : | showCategories( $section, $option ); | ||
| 100 : | break; | ||
| 101 : | } | ||
| 102 : | |||
| 103 : | /** | ||
| 104 : | * Compiles a list of categories for a section | ||
| 105 : | * @param string The name of the category section | ||
| 106 : | */ | ||
| 107 : | function showCategories( $section, $option ) { | ||
| 108 : | global $database, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path; | ||
| 109 : | |||
| 110 : | $sectionid = $mainframe->getUserStateFromRequest( "sectionid{$option}{$section}", 'sectionid', 0 ); | ||
| 111 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 112 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$section}limitstart", 'limitstart', 0 ); | ||
| 113 : | |||
| 114 : | $section_name = ''; | ||
| 115 : | $content_add = ''; | ||
| 116 : | $content_join = ''; | ||
| 117 : | $order = "\n ORDER BY c.ordering, c.name"; | ||
| 118 : | if (intval( $section ) > 0) { | ||
| 119 : | $table = 'content'; | ||
| 120 : | |||
| 121 : | $query = "SELECT name FROM #__sections WHERE id='$section'"; | ||
| 122 : | $database->setQuery( $query ); | ||
| 123 : | $section_name = $database->loadResult(); | ||
| 124 : | $section_name = 'Content: '. $section_name; | ||
| 125 : | $where = "\n WHERE c.section='$section'"; | ||
| 126 : | $type = 'content'; | ||
| 127 : | } else if (strpos( $section, 'com_' ) === 0) { | ||
| 128 : | $table = substr( $section, 4 ); | ||
| 129 : | |||
| 130 : | $query = "SELECT name FROM #__components WHERE link='option=$section'"; | ||
| 131 : | $database->setQuery( $query ); | ||
| 132 : | $section_name = $database->loadResult(); | ||
| 133 : | $where = "\n WHERE c.section='$section'"; | ||
| 134 : | $type = 'other'; | ||
| 135 : | // special handling for contact component | ||
| 136 : | if ( $section == 'com_contact_details' ) { | ||
| 137 : | $section_name = T_('Contact'); | ||
| 138 : | } | ||
| 139 : | $section_name = T_('Component: '). $section_name; | ||
| 140 : | } else { | ||
| 141 : | $table = $section; | ||
| 142 : | $where = "\n WHERE c.section='$section'"; | ||
| 143 : | $type = 'other'; | ||
| 144 : | } | ||
| 145 : | |||
| 146 : | // get the total number of records | ||
| 147 : | $query = "SELECT count(*) FROM #__categories WHERE section='$section'"; | ||
| 148 : | $database->setQuery( $query ); | ||
| 149 : | $total = $database->loadResult(); | ||
| 150 : | |||
| 151 : | // allows for viweing of all content categories | ||
| 152 : | if ( $section == 'content' ) { | ||
| 153 : | $table = 'content'; | ||
| 154 : | $content_add = "\n , z.title AS section_name"; | ||
| 155 : | $content_join = "\n LEFT JOIN #__sections AS z ON z.id = c.section"; | ||
| 156 : | //$where = "\n WHERE s1.catid = c.id"; | ||
| 157 : | $where = "\n WHERE c.section NOT LIKE '%com_%'"; | ||
| 158 : | $order = "\n ORDER BY c.section, c.ordering, c.name"; | ||
| 159 : | $section_name = 'All Content'; | ||
| 160 : | // get the total number of records | ||
| 161 : | $database->setQuery( "SELECT count(*) FROM #__categories INNER JOIN #__sections AS s ON s.id = section" ); | ||
| 162 : | $total = $database->loadResult(); | ||
| 163 : | $type = 'content'; | ||
| 164 : | } | ||
| 165 : | |||
| 166 : | // used by filter | ||
| 167 : | if ( $sectionid > 0 ) { | ||
| 168 : | $filter = "\n AND c.section = '$sectionid'"; | ||
| 169 : | } else { | ||
| 170 : | $filter = ''; | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | require_once( $mosConfig_absolute_path . '/administrator/includes/pageNavigation.php' ); | ||
| 174 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 175 : | |||
| 176 : | $query = "SELECT c.*, c.checked_out as checked_out_contact_category, g.name AS groupname, u.name AS editor," | ||
| 177 : | . "COUNT(DISTINCT s2.checked_out) AS checked_out" | ||
| 178 : | . $content_add | ||
| 179 : | . "\n FROM #__categories AS c" | ||
| 180 : | . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" | ||
| 181 : | . "\n LEFT JOIN #__groups AS g ON g.id = c.access" | ||
| 182 : | //. "\n LEFT JOIN #__$table AS s1 ON s1.catid = c.id" | ||
| 183 : | . "\n LEFT JOIN #__$table AS s2 ON s2.catid = c.id AND s2.checked_out > 0" | ||
| 184 : | . $content_join | ||
| 185 : | . $where | ||
| 186 : | . $filter | ||
| 187 : | . "\n AND c.published != -2" | ||
| 188 : | . "\n GROUP BY c.id" | ||
| 189 : | . $order | ||
| 190 : | . "\n LIMIT $pageNav->limitstart, $pageNav->limit" | ||
| 191 : | ; | ||
| 192 : | $database->setQuery( $query ); | ||
| 193 : | $rows = $database->loadObjectList(); | ||
| 194 : | if ($database->getErrorNum()) { | ||
| 195 : | echo $database->stderr(); | ||
| 196 : | return; | ||
| 197 : | } | ||
| 198 : | |||
| 199 : | $count = count( $rows ); | ||
| 200 : | // number of Active Items | ||
| 201 : | for ( $i = 0; $i < $count; $i++ ) { | ||
| 202 : | $query = "SELECT COUNT( a.id )" | ||
| 203 : | . "\n FROM #__content AS a" | ||
| 204 : | . "\n WHERE a.catid = ". $rows[$i]->id | ||
| 205 : | . "\n AND a.state <> '-2'" | ||
| 206 : | ; | ||
| 207 : | $database->setQuery( $query ); | ||
| 208 : | $active = $database->loadResult(); | ||
| 209 : | $rows[$i]->active = $active; | ||
| 210 : | } | ||
| 211 : | // number of Trashed Items | ||
| 212 : | for ( $i = 0; $i < $count; $i++ ) { | ||
| 213 : | $query = "SELECT COUNT( a.id )" | ||
| 214 : | . "\n FROM #__content AS a" | ||
| 215 : | . "\n WHERE a.catid = ". $rows[$i]->id | ||
| 216 : | . "\n AND a.state = '-2'" | ||
| 217 : | ; | ||
| 218 : | $database->setQuery( $query ); | ||
| 219 : | $trash = $database->loadResult(); | ||
| 220 : | $rows[$i]->trash = $trash; | ||
| 221 : | } | ||
| 222 : | |||
| 223 : | // get list of sections for dropdown filter | ||
| 224 : | $javascript = 'onchange="document.adminForm.submit();"'; | ||
| 225 : | $lists['sectionid'] = mosAdminMenus::SelectSection( 'sectionid', $sectionid, $javascript ); | ||
| 226 : | |||
| 227 : | categories_html::show( $rows, $section, $section_name, $pageNav, $lists, $type ); | ||
| 228 : | } | ||
| 229 : | |||
| 230 : | /** | ||
| 231 : | * Compiles information to add or edit a category | ||
| 232 : | * @param string The name of the category section | ||
| 233 : | * @param integer The unique id of the category to edit (0 if new) | ||
| 234 : | * @param string The name of the current user | ||
| 235 : | */ | ||
| 236 : | function editCategory( $uid=0, $section='' ) { | ||
| 237 : | global $database, $my; | ||
| 238 : | |||
| 239 : | $type = mosGetParam( $_REQUEST, 'type', '' ); | ||
| 240 : | $redirect = mosGetParam( $_REQUEST, 'section', 'content' ); | ||
| 241 : | |||
| 242 : | $row = new mosCategory( $database ); | ||
| 243 : | // load the row from the db table | ||
| 244 : | $row->load( $uid ); | ||
| 245 : | |||
| 246 : | // fail if checked out not by 'me' | ||
| 247 : | if ($row->checked_out && $row->checked_out <> $my->id) { | ||
| 248 : | mosRedirect( 'index2.php?option=categories§ion='. $row->section, sprintf(T_('The category %s is currently being edited by another administrator'), $row->title) ); | ||
| 249 : | } | ||
| 250 : | |||
| 251 : | if ($uid) { | ||
| 252 : | // existing record | ||
| 253 : | $row->checkout( $my->id ); | ||
| 254 : | // code for Link Menu | ||
| 255 : | if ( $row->section > 0 ) { | ||
| 256 : | $query = "SELECT *" | ||
| 257 : | . "\n FROM #__menu" | ||
| 258 : | . "\n WHERE componentid = ". $row->id | ||
| 259 : | . "\n AND ( type = 'content_archive_category' OR type = 'content_blog_category' OR type = 'content_category' )" | ||
| 260 : | ; | ||
| 261 : | $database->setQuery( $query ); | ||
| 262 : | $menus = $database->loadObjectList(); | ||
| 263 : | $count = count( $menus ); | ||
| 264 : | for( $i = 0; $i < $count; $i++ ) { | ||
| 265 : | switch ( $menus[$i]->type ) { | ||
| 266 : | case 'content_category': | ||
| 267 : | $menus[$i]->type = T_('Category Table'); | ||
| 268 : | break; | ||
| 269 : | |||
| 270 : | case 'content_blog_category': | ||
| 271 : | $menus[$i]->type = T_('Category Blog'); | ||
| 272 : | break; | ||
| 273 : | |||
| 274 : | case 'content_archive_category': | ||
| 275 : | $menus[$i]->type = T_('Category Blog Archive'); | ||
| 276 : | break; | ||
| 277 : | } | ||
| 278 : | } | ||
| 279 : | } else { | ||
| 280 : | $menus = array(); | ||
| 281 : | } | ||
| 282 : | } else { | ||
| 283 : | // new record | ||
| 284 : | $row->section = $section; | ||
| 285 : | $row->published = 1; | ||
| 286 : | $menus = NULL; | ||
| 287 : | } | ||
| 288 : | |||
| 289 : | // make order list | ||
| 290 : | $order = array(); | ||
| 291 : | $database->setQuery( "SELECT COUNT(*) FROM #__categories WHERE section='$row->section'" ); | ||
| 292 : | $max = intval( $database->loadResult() ) + 1; | ||
| 293 : | |||
| 294 : | for ($i=1; $i < $max; $i++) { | ||
| 295 : | $order[] = mosHTML::makeOption( $i ); | ||
| 296 : | } | ||
| 297 : | |||
| 298 : | // build the html select list for sections | ||
| 299 : | if ( $section == 'content' ) { | ||
| 300 : | $query = "SELECT s.id AS value, s.title AS text" | ||
| 301 : | . "\n FROM #__sections AS s" | ||
| 302 : | . "\n ORDER BY s.ordering" | ||
| 303 : | ; | ||
| 304 : | $database->setQuery( $query ); | ||
| 305 : | $sections = $database->loadObjectList(); | ||
| 306 : | $lists['section'] = mosHTML::selectList( $sections, 'section', 'class="inputbox" size="1"', 'value', 'text' );; | ||
| 307 : | } else { | ||
| 308 : | if ( $type == 'other' ) { | ||
| 309 : | $section_name = 'N/A'; | ||
| 310 : | } else { | ||
| 311 : | $temp = new mosSection( $database ); | ||
| 312 : | $temp->load( $row->section ); | ||
| 313 : | $section_name = $temp->name; | ||
| 314 : | } | ||
| 315 : | $lists['section'] = '<input type="hidden" name="section" value="'. $row->section .'" />'. $section_name; | ||
| 316 : | } | ||
| 317 : | |||
| 318 : | // build the html select list for category types | ||
| 319 : | $types[] = mosHTML::makeOption( '', T_('Select Type') ); | ||
| 320 : | if ($row->section == 'com_contact_details') { | ||
| 321 : | $types[] = mosHTML::makeOption( 'contact_category_table', T_('Contact Category Table') ); | ||
| 322 : | } else | ||
| 323 : | if ($row->section == 'com_newsfeeds') { | ||
| 324 : | $types[] = mosHTML::makeOption( 'newsfeed_category_table', T_('News Feed Category Table') ); | ||
| 325 : | } else | ||
| 326 : | if ($row->section == 'com_weblinks') { | ||
| 327 : | $types[] = mosHTML::makeOption( 'weblink_category_table', T_('Web Link Category Table') ); | ||
| 328 : | } else { | ||
| 329 : | $types[] = mosHTML::makeOption( 'content_category', T_('Content Category Table') ); | ||
| 330 : | $types[] = mosHTML::makeOption( 'content_blog_category', T_('Content Category Blog') ); | ||
| 331 : | $types[] = mosHTML::makeOption( 'content_archive_category', T_('Content Category Archive Blog') ); | ||
| 332 : | } // if | ||
| 333 : | $lists['link_type'] = mosHTML::selectList( $types, 'link_type', 'class="inputbox" size="1"', 'value', 'text' );; | ||
| 334 : | |||
| 335 : | // build the html select list for ordering | ||
| 336 : | $query = "SELECT ordering AS value, title AS text" | ||
| 337 : | . "\n FROM #__categories" | ||
| 338 : | . "\n WHERE section = '$row->section'" | ||
| 339 : | . "\n ORDER BY ordering" | ||
| 340 : | ; | ||
| 341 : | $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $uid, $query ); | ||
| 342 : | |||
| 343 : | // build the select list for the image positions | ||
| 344 : | $active = ( $row->image_position ? $row->image_position : 'left' ); | ||
| 345 : | $lists['image_position'] = mosAdminMenus::Positions( 'image_position', $active, NULL, 0, 0 ); | ||
| 346 : | // Imagelist | ||
| 347 : | $lists['image'] = mosAdminMenus::Images( 'image', $row->image ); | ||
| 348 : | // build the html select list for the group access | ||
| 349 : | $lists['access'] = mosAdminMenus::Access( $row ); | ||
| 350 : | // build the html radio buttons for published | ||
| 351 : | $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); | ||
| 352 : | // build the html select list for menu selection | ||
| 353 : | $lists['menuselect'] = mosAdminMenus::MenuSelect( ); | ||
| 354 : | ocs_cms | 1292 | // build and html select list of content items - including static |
| 355 : | if ( $redirect == 'com_contact_details' ) { | ||
| 356 : | $contactCatParams =& new mosParameters($row->params); | ||
| 357 : | $lists['contentselect'] = contentHandler::ContentSelect( 'contentselect', NULL, $contactCatParams->get('redirect_page', -1), TRUE ); | ||
| 358 : | } | ||
| 359 : | cauld | 978 | categories_html::edit( $row, $lists, $redirect, $menus ); |
| 360 : | } | ||
| 361 : | |||
| 362 : | /** | ||
| 363 : | * Saves the catefory after an edit form submit | ||
| 364 : | * @param string The name of the category section | ||
| 365 : | */ | ||
| 366 : | function saveCategory( $task ) { | ||
| 367 : | global $database; | ||
| 368 : | |||
| 369 : | $menu = mosGetParam( $_POST, 'menu', 'mainmenu' ); | ||
| 370 : | $menuid = mosGetParam( $_POST, 'menuid', 0 ); | ||
| 371 : | $redirect = mosGetParam( $_POST, 'redirect', '' ); | ||
| 372 : | $oldtitle = mosGetParam( $_POST, 'oldtitle', null ); | ||
| 373 : | ocs_cms | 1292 | $redirect_page = mosGetParam( $_POST, 'contentselect', '' ); |
| 374 : | cauld | 978 | |
| 375 : | $row = new mosCategory( $database ); | ||
| 376 : | if (!$row->bind( $_POST )) { | ||
| 377 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 378 : | exit(); | ||
| 379 : | } | ||
| 380 : | ocs_cms | 1292 | |
| 381 : | // handle the contact form redirect param | ||
| 382 : | if ( $redirect == 'com_contact_details' ) { | ||
| 383 : | //for contact categories, no need to loop for parms - since there is only one param | ||
| 384 : | if (is_numeric($redirect_page)) | ||
| 385 : | $row->params = "redirect_page=".$redirect_page; | ||
| 386 : | } | ||
| 387 : | |||
| 388 : | cauld | 978 | if (!$row->check()) { |
| 389 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 390 : | exit(); | ||
| 391 : | } | ||
| 392 : | |||
| 393 : | if (!$row->store()) { | ||
| 394 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 395 : | exit(); | ||
| 396 : | } | ||
| 397 : | $row->checkin(); | ||
| 398 : | $row->updateOrder( "section='$row->section'" ); | ||
| 399 : | |||
| 400 : | if ( $oldtitle ) { | ||
| 401 : | if ($oldtitle != $row->title) { | ||
| 402 : | $database->setQuery( "UPDATE #__menu SET name='$row->title' WHERE name='$oldtitle' AND type='content_category'" ); | ||
| 403 : | $database->query(); | ||
| 404 : | } | ||
| 405 : | } | ||
| 406 : | |||
| 407 : | // Update Section Count | ||
| 408 : | if ($row->section != 'com_contact_details' && | ||
| 409 : | $row->section != 'com_newsfeeds' && | ||
| 410 : | $row->section != 'com_weblinks') { | ||
| 411 : | $query = "UPDATE #__sections SET count=count+1" | ||
| 412 : | . "\n WHERE id = '$row->section'" | ||
| 413 : | ; | ||
| 414 : | $database->setQuery( $query ); | ||
| 415 : | } | ||
| 416 : | |||
| 417 : | if (!$database->query()) { | ||
| 418 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 419 : | exit(); | ||
| 420 : | } | ||
| 421 : | |||
| 422 : | switch ( $task ) { | ||
| 423 : | case 'go2menu': | ||
| 424 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menu ); | ||
| 425 : | break; | ||
| 426 : | |||
| 427 : | case 'go2menuitem': | ||
| 428 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid ); | ||
| 429 : | break; | ||
| 430 : | |||
| 431 : | case 'menulink': | ||
| 432 : | menuLink( $row->id ); | ||
| 433 : | break; | ||
| 434 : | |||
| 435 : | case 'apply': | ||
| 436 : | $msg = 'Changes to Category saved'; | ||
| 437 : | mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $row->id, $msg ); | ||
| 438 : | break; | ||
| 439 : | |||
| 440 : | case 'save': | ||
| 441 : | default: | ||
| 442 : | $msg = 'Category saved'; | ||
| 443 : | mosRedirect( 'index2.php?option=com_categories§ion='. $redirect, $msg ); | ||
| 444 : | break; | ||
| 445 : | } | ||
| 446 : | } | ||
| 447 : | |||
| 448 : | /** | ||
| 449 : | * Deletes one or more categories from the categories table | ||
| 450 : | * @param string The name of the category section | ||
| 451 : | * @param array An array of unique category id numbers | ||
| 452 : | */ | ||
| 453 : | function removeCategories( $section, $cid ) { | ||
| 454 : | global $database; | ||
| 455 : | |||
| 456 : | if (count( $cid ) < 1) { | ||
| 457 : | echo "<script> alert('".T_('Select a category to delete')."'); window.history.go(-1);</script>\n"; | ||
| 458 : | exit; | ||
| 459 : | } | ||
| 460 : | |||
| 461 : | $cids = implode( ',', $cid ); | ||
| 462 : | |||
| 463 : | //Get Section ID prior to removing Category, in order to update counts | ||
| 464 : | //$database->setQuery( "SELECT section FROM #__categories WHERE id IN ($cids)" ); | ||
| 465 : | //$secid = $database->loadResult(); | ||
| 466 : | |||
| 467 : | if (intval( $section ) > 0) { | ||
| 468 : | $table = 'content'; | ||
| 469 : | } else if (strpos( $section, 'com_' ) === 0) { | ||
| 470 : | $table = substr( $section, 4 ); | ||
| 471 : | } else { | ||
| 472 : | $table = $section; | ||
| 473 : | } | ||
| 474 : | |||
| 475 : | $query = "SELECT c.id, c.name, COUNT(s.catid) AS numcat" | ||
| 476 : | . "\n FROM #__categories AS c" | ||
| 477 : | . "\n LEFT JOIN #__$table AS s ON s.catid=c.id" | ||
| 478 : | . "\n WHERE c.id IN ($cids)" | ||
| 479 : | . "\n GROUP BY c.id" | ||
| 480 : | ; | ||
| 481 : | $database->setQuery( $query ); | ||
| 482 : | |||
| 483 : | if (!($rows = $database->loadObjectList())) { | ||
| 484 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 485 : | } | ||
| 486 : | |||
| 487 : | $err = array(); | ||
| 488 : | $cid = array(); | ||
| 489 : | foreach ($rows as $row) { | ||
| 490 : | if ($row->numcat == 0) { | ||
| 491 : | $cid[] = $row->id; | ||
| 492 : | } else { | ||
| 493 : | $err[] = $row->name; | ||
| 494 : | } | ||
| 495 : | } | ||
| 496 : | |||
| 497 : | if (count( $cid )) { | ||
| 498 : | $cids = implode( ',', $cid ); | ||
| 499 : | $database->setQuery( "DELETE FROM #__categories WHERE id IN ($cids)" ); | ||
| 500 : | if (!$database->query()) { | ||
| 501 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 502 : | } | ||
| 503 : | } | ||
| 504 : | |||
| 505 : | if (count( $err )) { | ||
| 506 : | $cids = implode( "\', \'", $err ); | ||
| 507 : | $msg = 'Category(s): '. $cids .' cannot be removed as they contain records'; | ||
| 508 : | mosRedirect( 'index2.php?option=com_categories§ion='. $section .'&mosmsg='. $msg ); | ||
| 509 : | } | ||
| 510 : | |||
| 511 : | mosRedirect( 'index2.php?option=com_categories§ion='. $section ); | ||
| 512 : | } | ||
| 513 : | |||
| 514 : | /** | ||
| 515 : | * Publishes or Unpublishes one or more categories | ||
| 516 : | * @param string The name of the category section | ||
| 517 : | * @param integer A unique category id (passed from an edit form) | ||
| 518 : | * @param array An array of unique category id numbers | ||
| 519 : | * @param integer 0 if unpublishing, 1 if publishing | ||
| 520 : | * @param string The name of the current user | ||
| 521 : | */ | ||
| 522 : | function publishCategories( $section, $categoryid=null, $cid=null, $publish=1 ) { | ||
| 523 : | global $database, $my; | ||
| 524 : | |||
| 525 : | if (!is_array( $cid )) { | ||
| 526 : | $cid = array(); | ||
| 527 : | } | ||
| 528 : | if ($categoryid) { | ||
| 529 : | $cid[] = $categoryid; | ||
| 530 : | } | ||
| 531 : | |||
| 532 : | if (count( $cid ) < 1) { | ||
| 533 : | $action = $publish ? T_('publish') : T_('unpublish'); | ||
| 534 : | echo "<script> alert('".sprintf(T_('Select a category to %s'), $action)."'); window.history.go(-1);</script>\n"; | ||
| 535 : | exit; | ||
| 536 : | } | ||
| 537 : | |||
| 538 : | $cids = implode( ',', $cid ); | ||
| 539 : | |||
| 540 : | $query = "UPDATE #__categories SET published='$publish'" | ||
| 541 : | . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" | ||
| 542 : | ; | ||
| 543 : | $database->setQuery( $query ); | ||
| 544 : | if (!$database->query()) { | ||
| 545 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 546 : | exit(); | ||
| 547 : | } | ||
| 548 : | |||
| 549 : | if (count( $cid ) == 1) { | ||
| 550 : | $row = new mosCategory( $database ); | ||
| 551 : | $row->checkin( $cid[0] ); | ||
| 552 : | } | ||
| 553 : | |||
| 554 : | mosRedirect( 'index2.php?option=com_categories§ion='. $section ); | ||
| 555 : | } | ||
| 556 : | |||
| 557 : | /** | ||
| 558 : | * Cancels an edit operation | ||
| 559 : | * @param string The name of the category section | ||
| 560 : | * @param integer A unique category id | ||
| 561 : | */ | ||
| 562 : | function cancelCategory() { | ||
| 563 : | global $database; | ||
| 564 : | |||
| 565 : | $redirect = mosGetParam( $_POST, 'redirect', '' ); | ||
| 566 : | |||
| 567 : | $row = new mosCategory( $database ); | ||
| 568 : | $row->bind( $_POST ); | ||
| 569 : | // sanitize | ||
| 570 : | $row->id = intval($row->id); | ||
| 571 : | $row->checkin(); | ||
| 572 : | mosRedirect( 'index2.php?option=com_categories§ion='. $redirect ); | ||
| 573 : | } | ||
| 574 : | |||
| 575 : | /** | ||
| 576 : | * Moves the order of a record | ||
| 577 : | * @param integer The increment to reorder by | ||
| 578 : | */ | ||
| 579 : | function orderCategory( $uid, $inc ) { | ||
| 580 : | global $database; | ||
| 581 : | |||
| 582 : | $row = new mosCategory( $database ); | ||
| 583 : | $row->load( $uid ); | ||
| 584 : | $row->move( $inc, "section='$row->section'" ); | ||
| 585 : | mosRedirect( 'index2.php?option=com_categories§ion='. $row->section ); | ||
| 586 : | } | ||
| 587 : | |||
| 588 : | /** | ||
| 589 : | * Form for moving item(s) to a specific menu | ||
| 590 : | */ | ||
| 591 : | function moveCategorySelect( $option, $cid, $sectionOld ) { | ||
| 592 : | global $database; | ||
| 593 : | |||
| 594 : | $redirect = mosGetParam( $_POST, 'section', 'content' );; | ||
| 595 : | |||
| 596 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 597 : | echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n"; | ||
| 598 : | exit; | ||
| 599 : | } | ||
| 600 : | |||
| 601 : | ## query to list selected categories | ||
| 602 : | $cids = implode( ',', $cid ); | ||
| 603 : | $query = "SELECT a.name, a.section FROM #__categories AS a WHERE a.id IN ( ". $cids ." )"; | ||
| 604 : | $database->setQuery( $query ); | ||
| 605 : | $items = $database->loadObjectList(); | ||
| 606 : | |||
| 607 : | ## query to list items from categories | ||
| 608 : | $query = "SELECT a.title FROM #__content AS a WHERE a.catid IN ( ". $cids ." ) ORDER BY a.catid, a.title"; | ||
| 609 : | $database->setQuery( $query ); | ||
| 610 : | $contents = $database->loadObjectList(); | ||
| 611 : | |||
| 612 : | ## query to choose section to move to | ||
| 613 : | $query = "SELECT a.name AS `text`, a.id AS `value` FROM #__sections AS a WHERE a.published = '1' ORDER BY a.name"; | ||
| 614 : | $database->setQuery( $query ); | ||
| 615 : | $sections = $database->loadObjectList(); | ||
| 616 : | |||
| 617 : | // build the html select list | ||
| 618 : | $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); | ||
| 619 : | |||
| 620 : | categories_html::moveCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect ); | ||
| 621 : | } | ||
| 622 : | |||
| 623 : | |||
| 624 : | /** | ||
| 625 : | * Save the item(s) to the menu selected | ||
| 626 : | */ | ||
| 627 : | function moveCategorySave( $cid, $sectionOld ) { | ||
| 628 : | global $database; | ||
| 629 : | |||
| 630 : | $sectionMove = mosGetParam( $_REQUEST, 'sectionmove', '' ); | ||
| 631 : | |||
| 632 : | $cids = implode( ',', $cid ); | ||
| 633 : | $total = count( $cid ); | ||
| 634 : | |||
| 635 : | $query = "UPDATE #__categories SET section = '". $sectionMove ."' " | ||
| 636 : | . "WHERE id IN ( ". $cids ." )" | ||
| 637 : | ; | ||
| 638 : | $database->setQuery( $query ); | ||
| 639 : | if ( !$database->query() ) { | ||
| 640 : | echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; | ||
| 641 : | exit(); | ||
| 642 : | } | ||
| 643 : | $query = "UPDATE #__content SET sectionid = '". $sectionMove ."' " | ||
| 644 : | . "WHERE catid IN ( ". $cids ." )" | ||
| 645 : | ; | ||
| 646 : | $database->setQuery( $query ); | ||
| 647 : | if ( !$database->query() ) { | ||
| 648 : | echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; | ||
| 649 : | exit(); | ||
| 650 : | } | ||
| 651 : | $sectionNew = new mosSection ( $database ); | ||
| 652 : | $sectionNew->load( $sectionMove ); | ||
| 653 : | |||
| 654 : | $msg = $total ." Categories moved to ". $sectionNew->name; | ||
| 655 : | mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg ); | ||
| 656 : | } | ||
| 657 : | |||
| 658 : | /** | ||
| 659 : | * Form for copying item(s) to a specific menu | ||
| 660 : | */ | ||
| 661 : | function copyCategorySelect( $option, $cid, $sectionOld ) { | ||
| 662 : | global $database; | ||
| 663 : | |||
| 664 : | $redirect = mosGetParam( $_POST, 'section', 'content' );; | ||
| 665 : | |||
| 666 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 667 : | echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n"; | ||
| 668 : | exit; | ||
| 669 : | } | ||
| 670 : | |||
| 671 : | ## query to list selected categories | ||
| 672 : | $cids = implode( ',', $cid ); | ||
| 673 : | $query = "SELECT a.name, a.section FROM #__categories AS a WHERE a.id IN ( ". $cids ." )"; | ||
| 674 : | $database->setQuery( $query ); | ||
| 675 : | $items = $database->loadObjectList(); | ||
| 676 : | |||
| 677 : | ## query to list items from categories | ||
| 678 : | $query = "SELECT a.title, a.id FROM #__content AS a WHERE a.catid IN ( ". $cids ." ) ORDER BY a.catid, a.title"; | ||
| 679 : | $database->setQuery( $query ); | ||
| 680 : | $contents = $database->loadObjectList(); | ||
| 681 : | |||
| 682 : | ## query to choose section to move to | ||
| 683 : | $query = "SELECT a.name AS `text`, a.id AS `value` FROM #__sections AS a WHERE a.published = '1' ORDER BY a.name"; | ||
| 684 : | $database->setQuery( $query ); | ||
| 685 : | $sections = $database->loadObjectList(); | ||
| 686 : | |||
| 687 : | // build the html select list | ||
| 688 : | $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); | ||
| 689 : | |||
| 690 : | categories_html::copyCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect ); | ||
| 691 : | } | ||
| 692 : | |||
| 693 : | |||
| 694 : | /** | ||
| 695 : | * Save the item(s) to the menu selected | ||
| 696 : | */ | ||
| 697 : | function copyCategorySave( $cid, $sectionOld ) { | ||
| 698 : | global $database; | ||
| 699 : | |||
| 700 : | $sectionMove = mosGetParam( $_REQUEST, 'sectionmove', '' ); | ||
| 701 : | $contentid = mosGetParam( $_REQUEST, 'item', '' ); | ||
| 702 : | $total = count( $contentid ); | ||
| 703 : | |||
| 704 : | $category = new mosCategory ( $database ); | ||
| 705 : | foreach( $cid as $id ) { | ||
| 706 : | $category->load( $id ); | ||
| 707 : | $category->id = NULL; | ||
| 708 : | $category->title = "Copy of ".$category->title; | ||
| 709 : | $category->name = "Copy of ".$category->name; | ||
| 710 : | $category->section = $sectionMove; | ||
| 711 : | if (!$category->check()) { | ||
| 712 : | echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; | ||
| 713 : | exit(); | ||
| 714 : | } | ||
| 715 : | |||
| 716 : | if (!$category->store()) { | ||
| 717 : | echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; | ||
| 718 : | exit(); | ||
| 719 : | } | ||
| 720 : | $category->checkin(); | ||
| 721 : | // stores original catid | ||
| 722 : | $newcatids[]["old"] = $id; | ||
| 723 : | // pulls new catid | ||
| 724 : | $newcatids[]["new"] = $category->id; | ||
| 725 : | } | ||
| 726 : | |||
| 727 : | $content = new mosContent ( $database ); | ||
| 728 : | foreach( $contentid as $id) { | ||
| 729 : | $content->load( $id ); | ||
| 730 : | $content->id = NULL; | ||
| 731 : | $content->sectionid = $sectionMove; | ||
| 732 : | $content->hits = 0; | ||
| 733 : | foreach( $newcatids as $newcatid ) { | ||
| 734 : | if ( $content->catid == $newcatid["old"] ) { | ||
| 735 : | $content->catid = $newcatid["new"]; | ||
| 736 : | } | ||
| 737 : | } | ||
| 738 : | if (!$content->check()) { | ||
| 739 : | echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; | ||
| 740 : | exit(); | ||
| 741 : | } | ||
| 742 : | |||
| 743 : | if (!$content->store()) { | ||
| 744 : | echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; | ||
| 745 : | exit(); | ||
| 746 : | } | ||
| 747 : | $content->checkin(); | ||
| 748 : | } | ||
| 749 : | |||
| 750 : | $sectionNew = new mosSection ( $database ); | ||
| 751 : | $sectionNew->load( $sectionMove ); | ||
| 752 : | |||
| 753 : | $msg = sprintf(Tn_('%d Category copied to %s', '%d Categories copied to %s', $total), $total, $sectionNew->name); | ||
| 754 : | mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg ); | ||
| 755 : | } | ||
| 756 : | |||
| 757 : | /** | ||
| 758 : | * changes the access level of a record | ||
| 759 : | * @param integer The increment to reorder by | ||
| 760 : | */ | ||
| 761 : | function accessMenu( $uid, $access, $section ) { | ||
| 762 : | global $database; | ||
| 763 : | |||
| 764 : | $row = new mosCategory( $database ); | ||
| 765 : | $row->load( $uid ); | ||
| 766 : | $row->access = $access; | ||
| 767 : | |||
| 768 : | if ( !$row->check() ) { | ||
| 769 : | return $row->getError(); | ||
| 770 : | } | ||
| 771 : | if ( !$row->store() ) { | ||
| 772 : | return $row->getError(); | ||
| 773 : | } | ||
| 774 : | |||
| 775 : | mosRedirect( 'index2.php?option=com_categories§ion='. $section ); | ||
| 776 : | } | ||
| 777 : | |||
| 778 : | function menuLink( $id ) { | ||
| 779 : | global $database; | ||
| 780 : | |||
| 781 : | $category = new mosCategory( $database ); | ||
| 782 : | $category->bind( $_POST ); | ||
| 783 : | $category->checkin(); | ||
| 784 : | |||
| 785 : | $redirect = mosGetParam( $_POST, 'redirect', '' ); | ||
| 786 : | $menu = mosGetParam( $_POST, 'menuselect', '' ); | ||
| 787 : | $name = mosGetParam( $_POST, 'link_name', '' ); | ||
| 788 : | $sectionid = mosGetParam( $_POST, 'sectionid', '' ); | ||
| 789 : | $type = mosGetParam( $_POST, 'link_type', '' ); | ||
| 790 : | |||
| 791 : | switch ( $type ) { | ||
| 792 : | case 'content_category': | ||
| 793 : | $link = 'index.php?option=com_content&task=category§ionid='. $sectionid .'&id='. $id; | ||
| 794 : | $menutype = T_('Content Category Table'); | ||
| 795 : | break; | ||
| 796 : | |||
| 797 : | case 'content_blog_category': | ||
| 798 : | $link = 'index.php?option=com_content&task=blogcategory&id='. $id; | ||
| 799 : | $menutype = T_('Content Category Blog'); | ||
| 800 : | break; | ||
| 801 : | |||
| 802 : | case 'content_archive_category': | ||
| 803 : | $link = 'index.php?option=com_content&task=archivecategory&id='. $id; | ||
| 804 : | $menutype = T_('Content Category Blog Archive'); | ||
| 805 : | break; | ||
| 806 : | |||
| 807 : | case 'contact_category_table': | ||
| 808 : | $link = 'index.php?option=com_contact&catid='. $id; | ||
| 809 : | $menutype = T_('Contact Category Table'); | ||
| 810 : | break; | ||
| 811 : | |||
| 812 : | case 'newsfeed_category_table': | ||
| 813 : | $link = 'index.php?option=com_newsfeeds&catid='. $id; | ||
| 814 : | $menutype = T_('News Feed Category Table'); | ||
| 815 : | break; | ||
| 816 : | |||
| 817 : | case 'weblink_category_table': | ||
| 818 : | $link = 'index.php?option=com_weblinks&catid='. $id; | ||
| 819 : | $menutype = T_('Web Link Category Table'); | ||
| 820 : | break; | ||
| 821 : | |||
| 822 : | default:; | ||
| 823 : | } | ||
| 824 : | |||
| 825 : | $row = new mosMenu( $database ); | ||
| 826 : | $row->menutype = $menu; | ||
| 827 : | $row->name = $name; | ||
| 828 : | $row->type = $type; | ||
| 829 : | $row->published = 1; | ||
| 830 : | $row->componentid = $id; | ||
| 831 : | $row->link = $link; | ||
| 832 : | $row->ordering = 9999; | ||
| 833 : | |||
| 834 : | if (!$row->check()) { | ||
| 835 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 836 : | exit(); | ||
| 837 : | } | ||
| 838 : | if (!$row->store()) { | ||
| 839 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 840 : | exit(); | ||
| 841 : | } | ||
| 842 : | $row->checkin(); | ||
| 843 : | $row->updateOrder( "menutype='". $menu ."'" ); | ||
| 844 : | |||
| 845 : | $msg = sprintf(T_('%s ( %s ) in menu: %s successfully created'),$name, $menutype,$menu); | ||
| 846 : | mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $id, $msg ); | ||
| 847 : | } | ||
| 848 : | |||
| 849 : | function saveOrder( &$cid, $section ) { | ||
| 850 : | global $database; | ||
| 851 : | $order = mosGetParam( $_POST, 'order', array(0) ); | ||
| 852 : | $row = new mosCategory( $database ); | ||
| 853 : | $sections = array(); | ||
| 854 : | // update ordering values | ||
| 855 : | foreach ($cid as $i=>$ciditem) { | ||
| 856 : | $row->load( $ciditem ); | ||
| 857 : | if ($row->ordering != $order[$i]) { | ||
| 858 : | $row->ordering = $order[$i]; | ||
| 859 : | if (!$row->store()) { | ||
| 860 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 861 : | exit(); | ||
| 862 : | } | ||
| 863 : | // remember to updateOrder this group | ||
| 864 : | $sections[$row->section] = $row->id; | ||
| 865 : | } | ||
| 866 : | } | ||
| 867 : | // execute updateOrder for each group | ||
| 868 : | foreach ($sections as $section=>$rowid) { | ||
| 869 : | $row->updateOrder("section='$section'"); | ||
| 870 : | } // foreach | ||
| 871 : | $msg = T_('New ordering saved'); | ||
| 872 : | mosRedirect( 'index2.php?option=com_categories§ion='. $section, $msg ); | ||
| 873 : | } // saveOrder | ||
| 874 : | |||
| 875 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

