[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: admin.weblinks.php 5025 2006-09-13 12:36:21Z friesengeist $ 4 * @package Joomla 5 * @subpackage Weblinks 6 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 7 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // no direct access 16 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 17 18 // ensure user has access to this function 19 if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) 20 | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_weblinks' ))) { 21 mosRedirect( 'index2.php', _NOT_AUTH ); 22 } 23 24 require_once( $mainframe->getPath( 'admin_html' ) ); 25 require_once( $mainframe->getPath( 'class' ) ); 26 27 $cid = josGetArrayInts( 'cid' ); 28 29 switch ($task) { 30 case 'new': 31 editWeblink( $option, 0 ); 32 break; 33 34 case 'edit': 35 editWeblink( $option, $cid[0] ); 36 break; 37 38 case 'editA': 39 editWeblink( $option, $id ); 40 break; 41 42 case 'save': 43 saveWeblink( $option ); 44 break; 45 46 case 'remove': 47 removeWeblinks( $cid, $option ); 48 break; 49 50 case 'publish': 51 publishWeblinks( $cid, 1, $option ); 52 break; 53 54 case 'unpublish': 55 publishWeblinks( $cid, 0, $option ); 56 break; 57 58 case 'approve': 59 break; 60 61 case 'cancel': 62 cancelWeblink( $option ); 63 break; 64 65 case 'orderup': 66 orderWeblinks( intval( $cid[0] ), -1, $option ); 67 break; 68 69 case 'orderdown': 70 orderWeblinks( intval( $cid[0] ), 1, $option ); 71 break; 72 73 default: 74 showWeblinks( $option ); 75 break; 76 } 77 78 /** 79 * Compiles a list of records 80 * @param database A database connector object 81 */ 82 function showWeblinks( $option ) { 83 global $database, $mainframe, $mosConfig_list_limit; 84 85 $catid = intval( $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 ) ); 86 $limit = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) ); 87 $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ) ); 88 $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' ); 89 if (get_magic_quotes_gpc()) { 90 $search = stripslashes( $search ); 91 } 92 93 $where = array(); 94 95 if ($catid > 0) { 96 $where[] = "a.catid = " . (int) $catid; 97 } 98 if ($search) { 99 $where[] = "LOWER(a.title) LIKE '%" . $database->getEscaped( trim( strtolower( $search ) ) ) . "%'"; 100 } 101 102 // get the total number of records 103 $query = "SELECT COUNT(*)" 104 . "\n FROM #__weblinks AS a" 105 . (count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : "") 106 ; 107 $database->setQuery( $query ); 108 $total = $database->loadResult(); 109 110 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 111 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 112 113 $query = "SELECT a.*, cc.name AS category, u.name AS editor" 114 . "\n FROM #__weblinks AS a" 115 . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid" 116 . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out" 117 . ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : "") 118 . "\n ORDER BY a.catid, a.ordering" 119 ; 120 $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); 121 122 $rows = $database->loadObjectList(); 123 if ($database->getErrorNum()) { 124 echo $database->stderr(); 125 return false; 126 } 127 128 // build list of categories 129 $javascript = 'onchange="document.adminForm.submit();"'; 130 $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $catid ), $javascript ); 131 132 HTML_weblinks::showWeblinks( $option, $rows, $lists, $search, $pageNav ); 133 } 134 135 /** 136 * Compiles information to add or edit 137 * @param integer The unique id of the record to edit (0 if new) 138 */ 139 function editWeblink( $option, $id ) { 140 global $database, $my, $mosConfig_absolute_path; 141 142 $lists = array(); 143 144 $row = new mosWeblink( $database ); 145 // load the row from the db table 146 $row->load( (int)$id ); 147 148 // fail if checked out not by 'me' 149 if ($row->isCheckedOut( $my->id )) { 150 mosRedirect( 'index2.php?option='. $option, 'The module $row->title is currently being edited by another administrator.' ); 151 } 152 153 if ($id) { 154 $row->checkout( $my->id ); 155 } else { 156 // initialise new record 157 $row->published = 1; 158 $row->approved = 1; 159 $row->order = 0; 160 $row->catid = intval( mosGetParam( $_POST, 'catid', 0 ) ); 161 } 162 163 // build the html select list for ordering 164 $query = "SELECT ordering AS value, title AS text" 165 . "\n FROM #__weblinks" 166 . "\n WHERE catid = " . (int) $row->catid 167 . "\n ORDER BY ordering" 168 ; 169 $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 ); 170 171 // build list of categories 172 $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $row->catid ) ); 173 // build the html select list 174 $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); 175 176 $file = $mosConfig_absolute_path .'/administrator/components/com_weblinks/weblinks_item.xml'; 177 $params = new mosParameters( $row->params, $file, 'component' ); 178 179 HTML_weblinks::editWeblink( $row, $lists, $params, $option ); 180 } 181 182 /** 183 * Saves the record on an edit form submit 184 * @param database A database connector object 185 */ 186 function saveWeblink( $option ) { 187 global $database, $my; 188 189 $row = new mosWeblink( $database ); 190 if (!$row->bind( $_POST )) { 191 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 192 exit(); 193 } 194 // save params 195 $params = mosGetParam( $_POST, 'params', '' ); 196 if (is_array( $params )) { 197 $txt = array(); 198 foreach ( $params as $k=>$v) { 199 $txt[] = "$k=$v"; 200 } 201 $row->params = implode( "\n", $txt ); 202 } 203 204 $row->date = date( 'Y-m-d H:i:s' ); 205 if (!$row->check()) { 206 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 207 exit(); 208 } 209 if (!$row->store()) { 210 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 211 exit(); 212 } 213 $row->checkin(); 214 $row->updateOrder( "catid = " . (int) $row->catid ); 215 216 mosRedirect( "index2.php?option=$option" ); 217 } 218 219 /** 220 * Deletes one or more records 221 * @param array An array of unique category id numbers 222 * @param string The current url option 223 */ 224 function removeWeblinks( $cid, $option ) { 225 global $database; 226 227 if (!is_array( $cid ) || count( $cid ) < 1) { 228 echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n"; 229 exit; 230 } 231 if (count( $cid )) { 232 mosArrayToInts( $cid ); 233 $cids = 'id=' . implode( ' OR id=', $cid ); 234 $query = "DELETE FROM #__weblinks" 235 . "\n WHERE ( $cids )" 236 ; 237 $database->setQuery( $query ); 238 if (!$database->query()) { 239 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 240 } 241 } 242 243 mosRedirect( "index2.php?option=$option" ); 244 } 245 246 /** 247 * Publishes or Unpublishes one or more records 248 * @param array An array of unique category id numbers 249 * @param integer 0 if unpublishing, 1 if publishing 250 * @param string The current url option 251 */ 252 function publishWeblinks( $cid=null, $publish=1, $option ) { 253 global $database, $my; 254 255 if (!is_array( $cid ) || count( $cid ) < 1) { 256 $action = $publish ? 'publish' : 'unpublish'; 257 echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n"; 258 exit; 259 } 260 261 mosArrayToInts( $cid ); 262 $cids = 'id=' . implode( ' OR id=', $cid ); 263 264 $query = "UPDATE #__weblinks" 265 . "\n SET published = " . (int) $publish 266 . "\n WHERE ( $cids )" 267 . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )" 268 ; 269 $database->setQuery( $query ); 270 if (!$database->query()) { 271 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 272 exit(); 273 } 274 275 if (count( $cid ) == 1) { 276 $row = new mosWeblink( $database ); 277 $row->checkin( $cid[0] ); 278 } 279 mosRedirect( "index2.php?option=$option" ); 280 } 281 /** 282 * Moves the order of a record 283 * @param integer The increment to reorder by 284 */ 285 function orderWeblinks( $uid, $inc, $option ) { 286 global $database; 287 $row = new mosWeblink( $database ); 288 $row->load( (int)$uid ); 289 $row->updateOrder(); 290 $row->move( $inc, "published >= 0" ); 291 $row->updateOrder(); 292 293 mosRedirect( "index2.php?option=$option" ); 294 } 295 296 /** 297 * Cancels an edit operation 298 * @param string The current url option 299 */ 300 function cancelWeblink( $option ) { 301 global $database; 302 $row = new mosWeblink( $database ); 303 $row->bind( $_POST ); 304 $row->checkin(); 305 mosRedirect( "index2.php?option=$option" ); 306 } 307 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |