00001 <?php
00015
00016 defined( '_VALID_MOS' ) or die( 'Restricted access' );
00017
00018 require_once( $mainframe->getPath( 'admin_html' ) );
00019
00020 $cid = josGetArrayInts( 'cid' );
00021
00022 switch ( $task ) {
00023 case 'cancel':
00024 cancel( $option );
00025 break;
00026
00027 case 'new':
00028 edit( 0, $option );
00029 break;
00030
00031 case 'edit':
00032 edit( $id, $option );
00033 break;
00034
00035 case 'editA':
00036 edit( intval( $cid[0] ), $option );
00037 break;
00038
00039 case 'go2menu':
00040 case 'go2menuitem':
00041 case 'resethits':
00042 case 'menulink':
00043 case 'save':
00044 case 'apply':
00045 save( $option, $task );
00046 break;
00047
00048 case 'remove':
00049 trash( $cid, $option );
00050 break;
00051
00052 case 'publish':
00053 changeState( $cid, 1, $option );
00054 break;
00055
00056 case 'unpublish':
00057 changeState( $cid, 0, $option );
00058 break;
00059
00060 case 'accesspublic':
00061 changeAccess( intval( $cid[0] ), 0, $option );
00062 break;
00063
00064 case 'accessregistered':
00065 changeAccess( intval( $cid[0] ), 1, $option );
00066 break;
00067
00068 case 'accessspecial':
00069 changeAccess( intval( $cid[0] ), 2, $option );
00070 break;
00071
00072 case 'saveorder':
00073 saveOrder( $cid );
00074 break;
00075
00076 default:
00077 view( $option );
00078 break;
00079 }
00080
00085 function view( $option ) {
00086 global $database, $mainframe, $mosConfig_list_limit;
00087
00088 $filter_authorid = intval( $mainframe->getUserStateFromRequest( "filter_authorid{$option}", 'filter_authorid', 0 ) );
00089 $order = $mainframe->getUserStateFromRequest( "zorder", 'zorder', 'c.ordering DESC' );
00090 $limit = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
00091 $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) );
00092 $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' );
00093 if (get_magic_quotes_gpc()) {
00094 $search = stripslashes( $search );
00095 }
00096
00097
00098 if ( $search ) {
00099 $searchEscaped = $database->getEscaped( trim( strtolower( $search ) ) );
00100 $search_query = "\n AND ( LOWER( c.title ) LIKE '%$searchEscaped%' OR LOWER( c.title_alias ) LIKE '%$searchEscaped%' )";
00101 } else {
00102 $search_query = '';
00103 }
00104
00105 $filter = '';
00106 if ( $filter_authorid > 0 ) {
00107 $filter = "\n AND c.created_by = " . (int) $filter_authorid;
00108 }
00109
00110 $orderAllowed = array( 'c.ordering ASC', 'c.ordering DESC', 'c.id ASC', 'c.id DESC', 'c.title ASC', 'c.title DESC', 'c.created ASC', 'c.created DESC', 'z.name ASC', 'z.name DESC', 'c.state ASC', 'c.state DESC', 'c.access ASC', 'c.access DESC' );
00111 if (!in_array( $order, $orderAllowed )) {
00112 $order = 'c.ordering DESC';
00113 }
00114
00115
00116 $query = "SELECT count(*)"
00117 . "\n FROM #__content AS c"
00118 . "\n WHERE c.sectionid = 0"
00119 . "\n AND c.catid = 0"
00120 . "\n AND c.state != -2"
00121 . $search_query
00122 . $filter
00123 ;
00124 $database->setQuery( $query );
00125 $total = $database->loadResult();
00126 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
00127 $pageNav = new mosPageNav( $total, $limitstart, $limit );
00128
00129 $query = "SELECT c.*, g.name AS groupname, u.name AS editor, z.name AS creator"
00130 . "\n FROM #__content AS c"
00131 . "\n LEFT JOIN #__groups AS g ON g.id = c.access"
00132 . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out"
00133 . "\n LEFT JOIN #__users AS z ON z.id = c.created_by"
00134 . "\n WHERE c.sectionid = 0"
00135 . "\n AND c.catid = 0"
00136 . "\n AND c.state != -2"
00137 . $search_query
00138 . $filter
00139 . "\n ORDER BY ". $order
00140 ;
00141 $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
00142 $rows = $database->loadObjectList();
00143
00144 if ($database->getErrorNum()) {
00145 echo $database->stderr();
00146 return false;
00147 }
00148
00149 $count = count( $rows );
00150 for( $i = 0; $i < $count; $i++ ) {
00151 $query = "SELECT COUNT( id )"
00152 . "\n FROM #__menu"
00153 . "\n WHERE componentid = " . (int) $rows[$i]->id
00154 . "\n AND type = 'content_typed'"
00155 . "\n AND published != -2"
00156 ;
00157 $database->setQuery( $query );
00158 $rows[$i]->links = $database->loadResult();
00159 }
00160
00161 $ordering[] = mosHTML::makeOption( 'c.ordering ASC', 'Ordering asc' );
00162 $ordering[] = mosHTML::makeOption( 'c.ordering DESC', 'Ordering desc' );
00163 $ordering[] = mosHTML::makeOption( 'c.id ASC', 'ID asc' );
00164 $ordering[] = mosHTML::makeOption( 'c.id DESC', 'ID desc' );
00165 $ordering[] = mosHTML::makeOption( 'c.title ASC', 'Title asc' );
00166 $ordering[] = mosHTML::makeOption( 'c.title DESC', 'Title desc' );
00167 $ordering[] = mosHTML::makeOption( 'c.created ASC', 'Date asc' );
00168 $ordering[] = mosHTML::makeOption( 'c.created DESC', 'Date desc' );
00169 $ordering[] = mosHTML::makeOption( 'z.name ASC', 'Author asc' );
00170 $ordering[] = mosHTML::makeOption( 'z.name DESC', 'Author desc' );
00171 $ordering[] = mosHTML::makeOption( 'c.state ASC', 'Published asc' );
00172 $ordering[] = mosHTML::makeOption( 'c.state DESC', 'Published desc' );
00173 $ordering[] = mosHTML::makeOption( 'c.access ASC', 'Access asc' );
00174 $ordering[] = mosHTML::makeOption( 'c.access DESC', 'Access desc' );
00175 $javascript = 'onchange="document.adminForm.submit();"';
00176 $lists['order'] = mosHTML::selectList( $ordering, 'zorder', 'class="inputbox" size="1"'. $javascript, 'value', 'text', $order );
00177
00178
00179 $query = "SELECT c.created_by AS value, u.name AS text"
00180 . "\n FROM #__content AS c"
00181 . "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
00182 . "\n WHERE c.sectionid = 0"
00183 . "\n GROUP BY u.name"
00184 . "\n ORDER BY u.name"
00185 ;
00186 $authors[] = mosHTML::makeOption( '0', _SEL_AUTHOR );
00187 $database->setQuery( $query );
00188 $authors = array_merge( $authors, $database->loadObjectList() );
00189 $lists['authorid'] = mosHTML::selectList( $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_authorid );
00190
00191 HTML_typedcontent::showContent( $rows, $pageNav, $option, $search, $lists );
00192 }
00193
00200 function edit( $uid, $option ) {
00201 global $database, $my, $mainframe;
00202 global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_offset;
00203
00204 $row = new mosContent( $database );
00205 $row->load( (int)$uid );
00206
00207 $lists = array();
00208 $nullDate = $database->getNullDate();
00209
00210 if ($uid) {
00211
00212 if ($row->isCheckedOut( $my->id )) {
00213 mosErrorAlert( "The module ".$row->title." is currently being edited by another administrator" );
00214 }
00215
00216 $row->checkout( $my->id );
00217
00218 if (trim( $row->images )) {
00219 $row->images = explode( "\n", $row->images );
00220 } else {
00221 $row->images = array();
00222 }
00223
00224 $row->created = mosFormatDate( $row->created, _CURRENT_SERVER_TIME_FORMAT );
00225 $row->modified = $row->modified == $nullDate ? '' : mosFormatDate( $row->modified, _CURRENT_SERVER_TIME_FORMAT );
00226 $row->publish_up = mosFormatDate( $row->publish_up, _CURRENT_SERVER_TIME_FORMAT );
00227
00228 if (trim( $row->publish_down ) == $nullDate || trim( $row->publish_down ) == '' || trim( $row->publish_down ) == '-' ) {
00229 $row->publish_down = 'Never';
00230 }
00231 $row->publish_down = mosFormatDate( $row->publish_down, _CURRENT_SERVER_TIME_FORMAT );
00232
00233 $query = "SELECT name"
00234 . "\n FROM #__users"
00235 . "\n WHERE id = " . (int) $row->created_by
00236 ;
00237 $database->setQuery( $query );
00238 $row->creator = $database->loadResult();
00239
00240
00241 if ( $row->created_by == $row->modified_by ) {
00242 $row->modifier = $row->creator;
00243 } else {
00244 $query = "SELECT name"
00245 . "\n FROM #__users"
00246 . "\n WHERE id = " . (int) $row->modified_by
00247 ;
00248 $database->setQuery( $query );
00249 $row->modifier = $database->loadResult();
00250 }
00251
00252
00253 $and = "\n AND componentid = " . (int) $row->id;
00254 $menus = mosAdminMenus::Links2Menu( 'content_typed', $and );
00255 } else {
00256
00257 $row->version = 0;
00258 $row->state = 1;
00259 $row->images = array();
00260 $row->publish_up = date( 'Y-m-d H:i:s', time() + ( $mosConfig_offset * 60 * 60 ) );
00261 $row->publish_down = 'Never';
00262 $row->sectionid = 0;
00263 $row->catid = 0;
00264 $row->creator = '';
00265 $row->modified = $nullDate;
00266 $row->modifier = '';
00267 $row->ordering = 0;
00268 $menus = array();
00269 }
00270
00271
00272 $pathA = $mosConfig_absolute_path .'/images/stories';
00273 $pathL = $mosConfig_live_site .'/images/stories';
00274 $images = array();
00275 $folders = array();
00276 $folders[] = mosHTML::makeOption( '/' );
00277 mosAdminMenus::ReadImages( $pathA, '/', $folders, $images );
00278
00279 $lists['folders'] = mosAdminMenus::GetImageFolders( $folders, $pathL );
00280
00281 $lists['imagefiles'] = mosAdminMenus::GetImages( $images, $pathL );
00282
00283 $lists['imagelist'] = mosAdminMenus::GetSavedImages( $row, $pathL );
00284
00285
00286 $active = ( intval( $row->created_by ) ? intval( $row->created_by ) : $my->id );
00287 $lists['created_by'] = mosAdminMenus::UserSelect( 'created_by', $active );
00288
00289 $lists['access'] = mosAdminMenus::Access( $row );
00290
00291 $lists['menuselect'] = mosAdminMenus::MenuSelect( );
00292
00293 $lists['_align'] = mosAdminMenus::Positions( '_align' );
00294
00295 $lists['_caption_align'] = mosAdminMenus::Positions( '_caption_align' );
00296
00297 $pos[] = mosHTML::makeOption( 'bottom', _CMN_BOTTOM );
00298 $pos[] = mosHTML::makeOption( 'top', _CMN_TOP );
00299 $lists['_caption_position'] = mosHTML::selectList( $pos, '_caption_position', 'class="inputbox" size="1"', 'value', 'text' );
00300
00301
00302 $params = new mosParameters( $row->attribs, $mainframe->getPath( 'com_xml', 'com_typedcontent' ), 'component' );
00303
00304 HTML_typedcontent::edit( $row, $images, $lists, $params, $option, $menus );
00305 }
00306
00310 function save( $option, $task ) {
00311 global $database, $my, $mosConfig_offset;
00312
00313 josSpoofCheck();
00314
00315 $nullDate = $database->getNullDate();
00316 $menu = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) );
00317 $menuid = intval( mosGetParam( $_POST, 'menuid', 0 ) );
00318
00319 $row = new mosContent( $database );
00320 if (!$row->bind( $_POST )) {
00321 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
00322 exit();
00323 }
00324
00325 if ($row->id) {
00326 $row->modified = date( 'Y-m-d H:i:s' );
00327 $row->modified_by = $my->id;
00328 }
00329
00330 $row->created_by = $row->created_by ? $row->created_by : $my->id;
00331
00332 if ($row->created && strlen(trim( $row->created )) <= 10) {
00333 $row->created .= ' 00:00:00';
00334 }
00335 $row->created = $row->created ? mosFormatDate( $row->created, _CURRENT_SERVER_TIME_FORMAT, -$mosConfig_offset ) : date( 'Y-m-d H:i:s' );
00336
00337 if (strlen(trim( $row->publish_up )) <= 10) {
00338 $row->publish_up .= ' 00:00:00';
00339 }
00340 $row->publish_up = mosFormatDate($row->publish_up, _CURRENT_SERVER_TIME_FORMAT, -$mosConfig_offset );
00341
00342 if (trim( $row->publish_down ) == 'Never' || trim( $row->publish_down ) == '') {
00343 $row->publish_down = $nullDate;
00344 } else {
00345 if (strlen(trim( $row->publish_down )) <= 10) {
00346 $row->publish_down .= ' 00:00:00';
00347 }
00348 $row->publish_down = mosFormatDate( $row->publish_down, _CURRENT_SERVER_TIME_FORMAT, -$mosConfig_offset );
00349 }
00350
00351 $row->state = intval( mosGetParam( $_REQUEST, 'published', 0 ) );
00352
00353
00354 $params = mosGetParam( $_POST, 'params', '' );
00355 if (is_array( $params )) {
00356 $txt = array();
00357 foreach ( $params as $k=>$v) {
00358 $txt[] = "$k=$v";
00359 }
00360 $row->attribs = implode( "\n", $txt );
00361 }
00362
00363
00364 $row->introtext = str_replace( '<br>', '<br />', $row->introtext );
00365
00366 $row->title = ampReplace( $row->title );
00367
00368 if (!$row->check()) {
00369 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
00370 exit();
00371 }
00372 if (!$row->store()) {
00373 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
00374 exit();
00375 }
00376 $row->checkin();
00377
00378
00379 mosCache::cleanCache( 'com_content' );
00380
00381 switch ( $task ) {
00382 case 'go2menu':
00383 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
00384 break;
00385
00386 case 'go2menuitem':
00387 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid );
00388 break;
00389
00390 case 'menulink':
00391 menuLink( $option, $row->id );
00392 break;
00393
00394 case 'resethits':
00395 resethits( $option, $row->id );
00396 break;
00397
00398 case 'save':
00399 $msg = 'Typed Content Item saved';
00400 mosRedirect( 'index2.php?option='. $option, $msg );
00401 break;
00402
00403 case 'apply':
00404 default:
00405 $msg = 'Changes to Typed Content Item saved';
00406 mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $row->id, $msg );
00407 break;
00408 }
00409 }
00410
00414 function trash( &$cid, $option ) {
00415 global $database;
00416
00417 josSpoofCheck();
00418
00419 $total = count( $cid );
00420 if ( $total < 1) {
00421 echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n";
00422 exit;
00423 }
00424
00425 $state = '-2';
00426 $ordering = '0';
00427
00428 mosArrayToInts( $cid );
00429 $cids = 'id=' . implode( ' OR id=', $cid );
00430 $query = "UPDATE #__content"
00431 . "\n SET state = " . (int) $state . ", ordering = " . (int) $ordering
00432 . "\n WHERE ( $cids )"
00433 ;
00434 $database->setQuery( $query );
00435 if ( !$database->query() ) {
00436 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
00437 exit();
00438 }
00439
00440
00441 mosCache::cleanCache( 'com_content' );
00442
00443 $msg = $total ." Item(s) sent to the Trash";
00444 mosRedirect( 'index2.php?option='. $option, $msg );
00445 }
00446
00455 function changeState( $cid=null, $state=0, $option ) {
00456 global $database, $my;
00457
00458 josSpoofCheck();
00459
00460 if (count( $cid ) < 1) {
00461 $action = $state == 1 ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
00462 echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
00463 exit;
00464 }
00465
00466 mosArrayToInts( $cid );
00467 $total = count ( $cid );
00468 $cids = 'id=' . implode( ' OR id=', $cid );
00469
00470 $query = "UPDATE #__content"
00471 . "\n SET state = " . (int) $state
00472 . "\n WHERE ( $cids )"
00473 . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )"
00474 ;
00475 $database->setQuery( $query );
00476 if (!$database->query()) {
00477 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
00478 exit();
00479 }
00480
00481 if (count( $cid ) == 1) {
00482 $row = new mosContent( $database );
00483 $row->checkin( $cid[0] );
00484 }
00485
00486
00487 mosCache::cleanCache( 'com_content' );
00488
00489 if ( $state == "1" ) {
00490 $msg = $total ." Item(s) successfully Published";
00491 } else if ( $state == "0" ) {
00492 $msg = $total ." Item(s) successfully Unpublished";
00493 }
00494 mosRedirect( 'index2.php?option='. $option .'&msg='. $msg );
00495 }
00496
00501 function changeAccess( $id, $access, $option ) {
00502 global $database;
00503
00504 josSpoofCheck();
00505
00506 $row = new mosContent( $database );
00507 $row->load( (int)$id );
00508 $row->access = $access;
00509
00510 if ( !$row->check() ) {
00511 return $row->getError();
00512 }
00513 if ( !$row->store() ) {
00514 return $row->getError();
00515 }
00516
00517
00518 mosCache::cleanCache( 'com_content' );
00519
00520 mosRedirect( 'index2.php?option='. $option );
00521 }
00522
00523
00527 function resethits( $option, $id ) {
00528 global $database;
00529
00530 josSpoofCheck();
00531
00532 $row = new mosContent($database);
00533 $row->Load( (int)$id );
00534 $row->hits = "0";
00535 $row->store();
00536 $row->checkin();
00537
00538 $msg = 'Successfully Reset Hit';
00539 mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $row->id, $msg );
00540 }
00541
00546 function cancel( $option ) {
00547 global $database;
00548
00549 josSpoofCheck();
00550
00551 $row = new mosContent( $database );
00552 $row->bind( $_POST );
00553 $row->checkin();
00554 mosRedirect( 'index2.php?option='. $option );
00555 }
00556
00557 function menuLink( $option, $id ) {
00558 global $database;
00559
00560 josSpoofCheck();
00561
00562 $menu = strval( mosGetParam( $_POST, 'menuselect', '' ) );
00563 $link = strval( mosGetParam( $_POST, 'link_name', '' ) );
00564
00565 $link = stripslashes( ampReplace($link) );
00566
00567 $row = new mosMenu( $database );
00568 $row->menutype = $menu;
00569 $row->name = $link;
00570 $row->type = 'content_typed';
00571 $row->published = 1;
00572 $row->componentid = $id;
00573 $row->link = 'index.php?option=com_content&task=view&id='. $id;
00574 $row->ordering = 9999;
00575
00576 if (!$row->check()) {
00577 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
00578 exit();
00579 }
00580 if (!$row->store()) {
00581 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
00582 exit();
00583 }
00584 $row->checkin();
00585 $row->updateOrder( "menutype=" . $database->Quote( $row->menutype ) . " AND parent=" . (int) $row->parent );
00586
00587
00588 mosCache::cleanCache( 'com_content' );
00589
00590 $msg = $link .' (Link - Static Content) in menu: '. $menu .' successfully created';
00591 mosRedirect( 'index2.php?option='. $option .'&task=edit&hidemainmenu=1&id='. $id, $msg );
00592 }
00593
00594 function go2menu() {
00595 global $database;
00596
00597 josSpoofCheck();
00598
00599
00600 $row = new mosContent( $database );
00601 $row->bind( $_POST );
00602 $row->checkin();
00603
00604 $menu = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) );
00605
00606 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu );
00607 }
00608
00609 function go2menuitem() {
00610 global $database;
00611
00612 josSpoofCheck();
00613
00614
00615 $row = new mosContent( $database );
00616 $row->bind( $_POST );
00617 $row->checkin();
00618
00619 $menu = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) );
00620 $id = intval( mosGetParam( $_POST, 'menuid', 0 ) );
00621
00622 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $id );
00623 }
00624
00625 function saveOrder( &$cid ) {
00626 global $database;
00627
00628 josSpoofCheck();
00629
00630 $total = count( $cid );
00631 $order = josGetArrayInts( 'order' );
00632
00633 $row = new mosContent( $database );
00634 $conditions = array();
00635
00636
00637 for ( $i=0; $i < $total; $i++ ) {
00638 $row->load( (int) $cid[$i] );
00639 if ($row->ordering != $order[$i]) {
00640 $row->ordering = $order[$i];
00641 if (!$row->store()) {
00642 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
00643 exit();
00644 }
00645
00646 $condition = "catid=" . (int) $row->catid . " AND state >= 0";
00647 $found = false;
00648 foreach ( $conditions as $cond )
00649 if ($cond[1]==$condition) {
00650 $found = true;
00651 break;
00652 }
00653 if (!$found) $conditions[] = array($row->id, $condition);
00654 }
00655 }
00656
00657
00658 foreach ( $conditions as $cond ) {
00659 $row->load( $cond[0] );
00660 $row->updateOrder( $cond[1] );
00661 }
00662
00663
00664 mosCache::cleanCache( 'com_content' );
00665
00666 $msg = 'New ordering saved';
00667 mosRedirect( 'index2.php?option=com_typedcontent', $msg );
00668 }
00669 ?>