[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: admin.banners.php 4982 2006-09-09 16:10:24Z friesengeist $ 4 * @package Joomla 5 * @subpackage Banners 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' )| $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_banners' ))) { 20 mosRedirect( 'index2.php', _NOT_AUTH ); 21 } 22 23 require_once( $mainframe->getPath( 'admin_html' ) ); 24 require_once( $mainframe->getPath( 'class' ) ); 25 26 $cid = josGetArrayInts( 'cid' ); 27 28 switch ($task) { 29 case 'newclient': 30 editBannerClient( 0, $option ); 31 break; 32 33 case 'editclient': 34 editBannerClient( intval( $cid[0] ), $option ); 35 break; 36 37 case 'editclientA': 38 editBannerClient( $id, $option ); 39 break; 40 41 case 'saveclient': 42 saveBannerClient( $option ); 43 break; 44 45 case 'removeclients': 46 removeBannerClients( $cid, $option ); 47 break; 48 49 case 'cancelclient': 50 cancelEditClient( $option ); 51 break; 52 53 case 'listclients': 54 viewBannerClients( $option ); 55 break; 56 57 // BANNER EVENTS 58 59 case 'new': 60 editBanner( null, $option ); 61 break; 62 63 case 'cancel': 64 cancelEditBanner(); 65 break; 66 67 case 'save': 68 case 'resethits': 69 saveBanner( $task ); 70 break; 71 72 case 'edit': 73 editBanner( $cid[0], $option ); 74 break; 75 76 case 'editA': 77 editBanner( $id, $option ); 78 break; 79 80 case 'remove': 81 removeBanner( $cid ); 82 break; 83 84 case 'publish': 85 publishBanner( $cid,1 ); 86 break; 87 88 case 'unpublish': 89 publishBanner( $cid, 0 ); 90 break; 91 92 default: 93 viewBanners( $option ); 94 break; 95 } 96 97 function viewBanners( $option ) { 98 global $database, $mainframe, $mosConfig_list_limit; 99 100 $limit = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) ); 101 $limitstart = intval( $mainframe->getUserStateFromRequest( "viewban{$option}limitstart", 'limitstart', 0 ) ); 102 103 // get the total number of records 104 $query = "SELECT COUNT(*)" 105 . "\n FROM #__banner" 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 b.*, u.name AS editor" 114 . "\n FROM #__banner AS b " 115 . "\n LEFT JOIN #__users AS u ON u.id = b.checked_out" 116 ; 117 $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); 118 $rows = $database->loadObjectList(); 119 120 HTML_banners::showBanners( $rows, $pageNav, $option ); 121 } 122 123 function editBanner( $bannerid, $option ) { 124 global $database, $my; 125 $lists = array(); 126 127 $row = new mosBanner($database); 128 $row->load( (int)$bannerid ); 129 130 if ( $bannerid ){ 131 $row->checkout( $my->id ); 132 } 133 134 // Build Client select list 135 $sql = "SELECT cid, name" 136 . "\n FROM #__bannerclient" 137 ; 138 $database->setQuery($sql); 139 if (!$database->query()) { 140 echo $database->stderr(); 141 return; 142 } 143 144 $clientlist[] = mosHTML::makeOption( '0', 'Select Client', 'cid', 'name' ); 145 $clientlist = array_merge( $clientlist, $database->loadObjectList() ); 146 $lists['cid'] = mosHTML::selectList( $clientlist, 'cid', 'class="inputbox" size="1"','cid', 'name', $row->cid); 147 148 // Imagelist 149 $javascript = 'onchange="changeDisplayImage();"'; 150 $directory = '/images/banners'; 151 $lists['imageurl'] = mosAdminMenus::Images( 'imageurl', $row->imageurl, $javascript, $directory ); 152 153 154 // make the select list for the image positions 155 $yesno[] = mosHTML::makeOption( '0', 'No' ); 156 $yesno[] = mosHTML::makeOption( '1', 'Yes' ); 157 158 $lists['showBanner'] = mosHTML::selectList( $yesno, 'showBanner', 'class="inputbox" size="1"' , 'value', 'text', $row->showBanner ); 159 160 HTML_banners::bannerForm( $row, $lists, $option ); 161 } 162 163 function saveBanner( $task ) { 164 global $database; 165 166 $row = new mosBanner($database); 167 168 $msg = 'Saved Banner info'; 169 if (!$row->bind( $_POST )) { 170 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 171 exit(); 172 } 173 174 // Resets clicks when `Reset Clicks` button is used instead of `Save` button 175 if ( $task == 'resethits' ) { 176 $row->clicks = 0; 177 $msg = 'Reset Banner clicks'; 178 } 179 180 // Sets impressions to unlimited when `unlimited` checkbox ticked 181 $unlimited = intval( mosGetParam( $_POST, 'unlimited', 0 ) ); 182 if ( $unlimited ) { 183 $row->imptotal = 0; 184 } 185 186 if (!$row->check()) { 187 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 188 exit(); 189 } 190 if (!$row->store()) { 191 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 192 exit(); 193 } 194 $row->checkin(); 195 196 mosRedirect( 'index2.php?option=com_banners', $msg ); 197 } 198 199 function cancelEditBanner() { 200 global $database; 201 202 $row = new mosBanner($database); 203 $row->bind( $_POST ); 204 $row->checkin(); 205 206 mosRedirect( 'index2.php?option=com_banners' ); 207 } 208 209 function publishBanner( $cid, $publish=1 ) { 210 global $database, $my; 211 212 if (!is_array( $cid ) || count( $cid ) < 1) { 213 $action = $publish ? 'publish' : 'unpublish'; 214 echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n"; 215 exit(); 216 } 217 218 mosArrayToInts( $cid ); 219 $cids = 'bid=' . implode( ' OR bid=', $cid ); 220 221 $query = "UPDATE #__banner" 222 . "\n SET showBanner = " . (int) $publish 223 . "\n WHERE ( $cids )" 224 . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )" 225 ; 226 $database->setQuery( $query ); 227 if (!$database->query()) { 228 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 229 exit(); 230 } 231 232 if (count( $cid ) == 1) { 233 $row = new mosBanner( $database ); 234 $row->checkin( $cid[0] ); 235 } 236 mosRedirect( 'index2.php?option=com_banners' ); 237 238 } 239 240 function removeBanner( $cid ) { 241 global $database; 242 if (count( $cid )) { 243 mosArrayToInts( $cid ); 244 $cids = 'bid=' . implode( ' OR bid=', $cid ); 245 $query = "DELETE FROM #__banner" 246 . "\n WHERE ( $cids )" 247 ; 248 $database->setQuery( $query ); 249 if (!$database->query()) { 250 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 251 } 252 } 253 mosRedirect( 'index2.php?option=com_banners' ); 254 } 255 256 // ---------- BANNER CLIENTS ---------- 257 258 function viewBannerClients( $option ) { 259 global $database, $mainframe, $mosConfig_list_limit; 260 261 $limit = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) ); 262 $limitstart = intval( $mainframe->getUserStateFromRequest( "viewcli{$option}limitstart", 'limitstart', 0 ) ); 263 264 // get the total number of records 265 $query = "SELECT COUNT(*)" 266 . "\n FROM #__bannerclient" 267 ; 268 $database->setQuery( $query ); 269 $total = $database->loadResult(); 270 271 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 272 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 273 274 $sql = "SELECT a.*, count(b.bid) AS bid, u.name AS editor" 275 . "\n FROM #__bannerclient AS a" 276 . "\n LEFT JOIN #__banner AS b ON a.cid = b.cid" 277 . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out" 278 . "\n GROUP BY a.cid"; 279 $database->setQuery($sql, $pageNav->limitstart, $pageNav->limit); 280 $rows = $database->loadObjectList(); 281 282 HTML_bannerClient::showClients( $rows, $pageNav, $option ); 283 } 284 285 function editBannerClient( $clientid, $option ) { 286 global $database, $my; 287 288 $row = new mosBannerClient($database); 289 $row->load( (int)$clientid); 290 291 // fail if checked out not by 'me' 292 if ($row->checked_out && $row->checked_out != $my->id) { 293 $msg = 'The client [ '. $row->name. ' ] is currently being edited by another person.'; 294 mosRedirect( 'index2.php?option='. $option .'&task=listclients', $msg ); 295 } 296 297 if ($clientid) { 298 // do stuff for existing record 299 $row->checkout( $my->id ); 300 } else { 301 // do stuff for new record 302 $row->published = 0; 303 $row->approved = 0; 304 } 305 306 HTML_bannerClient::bannerClientForm( $row, $option ); 307 } 308 309 function saveBannerClient( $option ) { 310 global $database; 311 312 $row = new mosBannerClient( $database ); 313 if (!$row->bind( $_POST )) { 314 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 315 exit(); 316 } 317 if (!$row->check()) { 318 mosRedirect( "index2.php?option=$option&task=editclient&cid[]=$row->cid", $row->getError() ); 319 } 320 321 if (!$row->store()) { 322 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 323 exit(); 324 } 325 $row->checkin(); 326 327 mosRedirect( "index2.php?option=$option&task=listclients" ); 328 } 329 330 function cancelEditClient( $option ) { 331 global $database; 332 $row = new mosBannerClient( $database ); 333 $row->bind( $_POST ); 334 $row->checkin(); 335 mosRedirect( "index2.php?option=$option&task=listclients" ); 336 } 337 338 function removeBannerClients( $cid, $option ) { 339 global $database; 340 341 for ($i = 0; $i < count($cid); $i++) { 342 $query = "SELECT COUNT( bid )" 343 . "\n FROM #__banner" 344 . "\n WHERE cid = " . (int) $cid[$i] 345 ; 346 $database->setQuery($query); 347 348 if(($count = $database->loadResult()) == null) { 349 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 350 } 351 352 if ($count != 0) { 353 mosRedirect( "index2.php?option=$option&task=listclients", 354 "Cannot delete client at this time as they have a banner still running" ); 355 } else { 356 $query="DELETE FROM #__bannerfinish" 357 . "\n WHERE cid = " . (int) $cid[$i] 358 ; 359 $database->setQuery($query); 360 $database->query(); 361 362 $query = "DELETE FROM #__bannerclient" 363 . "\n WHERE cid = " . (int) $cid[$i] 364 ; 365 $database->setQuery($query); 366 $database->query(); 367 } 368 } 369 mosRedirect("index2.php?option=$option&task=listclients"); 370 } 371 ?>
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 |
![]() |