Annotation of /mambo/branches/4.7/administrator/components/com_banners/admin.banners.php
Parent Directory
|
Revision Log
Revision 917 - (view) (download)
| 1 : | cauld | 917 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo Open Source | ||
| 4 : | * @subpackage Banners | ||
| 5 : | * @copyright (C) 2005 - 2006 Mambo Foundation Inc. | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * | ||
| 8 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 9 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 10 : | * Mambo is Free Software | ||
| 11 : | */ | ||
| 12 : | |||
| 13 : | /** ensure this file is being included by a parent file */ | ||
| 14 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 15 : | |||
| 16 : | // ensure user has access to this function | ||
| 17 : | if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' )| $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_banners' ))) { | ||
| 18 : | mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); | ||
| 19 : | } | ||
| 20 : | |||
| 21 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 22 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 23 : | |||
| 24 : | $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); | ||
| 25 : | if (!is_array( $cid )) { | ||
| 26 : | $cid = array(0); | ||
| 27 : | } | ||
| 28 : | |||
| 29 : | switch ($task) { | ||
| 30 : | case 'newclient': | ||
| 31 : | editBannerClient( 0, $option ); | ||
| 32 : | break; | ||
| 33 : | |||
| 34 : | case 'editclient': | ||
| 35 : | editBannerClient( $cid[0], $option ); | ||
| 36 : | break; | ||
| 37 : | |||
| 38 : | case 'editclientA': | ||
| 39 : | editBannerClient( $id, $option ); | ||
| 40 : | break; | ||
| 41 : | |||
| 42 : | case 'saveclient': | ||
| 43 : | saveBannerClient( $option ); | ||
| 44 : | break; | ||
| 45 : | |||
| 46 : | case 'removeclients': | ||
| 47 : | removeBannerClients( $cid, $option ); | ||
| 48 : | break; | ||
| 49 : | |||
| 50 : | case 'cancelclient': | ||
| 51 : | cancelEditClient( $option ); | ||
| 52 : | break; | ||
| 53 : | |||
| 54 : | case 'listclients': | ||
| 55 : | viewBannerClients( $option ); | ||
| 56 : | break; | ||
| 57 : | |||
| 58 : | // BANNER EVENTS | ||
| 59 : | |||
| 60 : | case 'new': | ||
| 61 : | editBanner( null, $option ); | ||
| 62 : | break; | ||
| 63 : | |||
| 64 : | case 'cancel': | ||
| 65 : | cancelEditBanner(); | ||
| 66 : | break; | ||
| 67 : | |||
| 68 : | case 'save': | ||
| 69 : | case 'resethits': | ||
| 70 : | saveBanner( $task ); | ||
| 71 : | break; | ||
| 72 : | |||
| 73 : | case 'edit': | ||
| 74 : | editBanner( $cid[0], $option ); | ||
| 75 : | break; | ||
| 76 : | |||
| 77 : | case 'editA': | ||
| 78 : | editBanner( $id, $option ); | ||
| 79 : | break; | ||
| 80 : | |||
| 81 : | case 'remove': | ||
| 82 : | removeBanner( $cid ); | ||
| 83 : | break; | ||
| 84 : | |||
| 85 : | case 'publish': | ||
| 86 : | publishBanner( $cid,1 ); | ||
| 87 : | break; | ||
| 88 : | |||
| 89 : | case 'unpublish': | ||
| 90 : | publishBanner( $cid, 0 ); | ||
| 91 : | break; | ||
| 92 : | |||
| 93 : | default: | ||
| 94 : | viewBanners( $option ); | ||
| 95 : | break; | ||
| 96 : | } | ||
| 97 : | |||
| 98 : | function viewBanners( $option ) { | ||
| 99 : | global $database, $mainframe, $mosConfig_list_limit; | ||
| 100 : | |||
| 101 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 102 : | $limitstart = $mainframe->getUserStateFromRequest( "viewban{$option}limitstart", 'limitstart', 0 ); | ||
| 103 : | |||
| 104 : | // get the total number of records | ||
| 105 : | $database->setQuery( "SELECT count(*) FROM #__banner" ); | ||
| 106 : | $total = $database->loadResult(); | ||
| 107 : | |||
| 108 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 109 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 110 : | |||
| 111 : | $query = "SELECT b.*, u.name as editor FROM #__banner as b " | ||
| 112 : | . "\n LEFT JOIN #__users AS u ON u.id = b.checked_out" | ||
| 113 : | . "\nLIMIT $pageNav->limitstart,$pageNav->limit"; | ||
| 114 : | $database->setQuery( $query ); | ||
| 115 : | |||
| 116 : | if(!$result = $database->query()) { | ||
| 117 : | echo $database->stderr(); | ||
| 118 : | return; | ||
| 119 : | } | ||
| 120 : | $rows = $database->loadObjectList(); | ||
| 121 : | HTML_banners::showBanners( $rows, $pageNav, $option ); | ||
| 122 : | } | ||
| 123 : | |||
| 124 : | function editBanner( $bannerid, $option ) { | ||
| 125 : | global $database, $my; | ||
| 126 : | $lists = array(); | ||
| 127 : | |||
| 128 : | $row = new mosBanner($database); | ||
| 129 : | $row->load( $bannerid ); | ||
| 130 : | |||
| 131 : | if ( $bannerid ){ | ||
| 132 : | $row->checkout( $my->id ); | ||
| 133 : | } | ||
| 134 : | |||
| 135 : | // Build Client select list | ||
| 136 : | $sql = "SELECT cid as value, name as text FROM #__bannerclient"; | ||
| 137 : | $database->setQuery($sql); | ||
| 138 : | if (!$database->query()) { | ||
| 139 : | echo $database->stderr(); | ||
| 140 : | return; | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | $clientlist[] = mosHTML::makeOption( '0', 'Select Client' ); | ||
| 144 : | $clientlist = array_merge( $clientlist, $database->loadObjectList() ); | ||
| 145 : | $lists['cid'] = mosHTML::selectList( $clientlist, 'cid', 'class="inputbox" size="1"','value', 'text', $row->cid); | ||
| 146 : | |||
| 147 : | // Imagelist | ||
| 148 : | $javascript = 'onchange="changeDisplayImage();"'; | ||
| 149 : | $directory = '/images/banners'; | ||
| 150 : | $lists['imageurl'] = mosAdminMenus::Images( 'imageurl', $row->imageurl, $javascript, $directory ); | ||
| 151 : | |||
| 152 : | |||
| 153 : | // make the select list for the image positions | ||
| 154 : | $yesno[] = mosHTML::makeOption( '0', T_('No') ); | ||
| 155 : | $yesno[] = mosHTML::makeOption( '1', T_('Yes') ); | ||
| 156 : | |||
| 157 : | $lists['showBanner'] = mosHTML::selectList( $yesno, 'showBanner', 'class="inputbox" size="1"' , 'value', 'text', $row->showBanner ); | ||
| 158 : | |||
| 159 : | HTML_banners::bannerForm( $row, $lists, $option ); | ||
| 160 : | } | ||
| 161 : | |||
| 162 : | function saveBanner( $task ) { | ||
| 163 : | global $database; | ||
| 164 : | |||
| 165 : | $row = new mosBanner($database); | ||
| 166 : | |||
| 167 : | $msg = T_('Saved Banner info'); | ||
| 168 : | if ( $task == 'resethits' ) { | ||
| 169 : | $row->clicks = 0; | ||
| 170 : | $msg = T_('Reset Banner clicks'); | ||
| 171 : | } | ||
| 172 : | if (!$row->bind( $_POST )) { | ||
| 173 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 174 : | exit(); | ||
| 175 : | } | ||
| 176 : | if (!$row->check()) { | ||
| 177 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 178 : | exit(); | ||
| 179 : | } | ||
| 180 : | if (!$row->store()) { | ||
| 181 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 182 : | exit(); | ||
| 183 : | } | ||
| 184 : | $row->checkin(); | ||
| 185 : | |||
| 186 : | mosRedirect( 'index2.php?option=com_banners', $msg ); | ||
| 187 : | } | ||
| 188 : | |||
| 189 : | function cancelEditBanner() { | ||
| 190 : | global $database; | ||
| 191 : | |||
| 192 : | $row = new mosBanner($database); | ||
| 193 : | $row->bind( $_POST ); | ||
| 194 : | $row->checkin(); | ||
| 195 : | // sanitize | ||
| 196 : | $row->id = intval($row->id); | ||
| 197 : | |||
| 198 : | mosRedirect( 'index2.php?option=com_banners' ); | ||
| 199 : | } | ||
| 200 : | |||
| 201 : | function publishBanner( $cid, $publish=1 ) { | ||
| 202 : | global $database, $my; | ||
| 203 : | |||
| 204 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 205 : | $action = $publish ? T_('publish') : T_('unpublish'); | ||
| 206 : | echo "<script> alert('".sprintf(T_('Select an item to %s'), $action)."'); window.history.go(-1);</script>\n"; | ||
| 207 : | exit; | ||
| 208 : | } | ||
| 209 : | |||
| 210 : | $cids = implode( ',', $cid ); | ||
| 211 : | |||
| 212 : | $database->setQuery( "UPDATE #__banner SET showBanner='$publish'" | ||
| 213 : | . "\nWHERE bid IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" | ||
| 214 : | ); | ||
| 215 : | if (!$database->query()) { | ||
| 216 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 217 : | exit(); | ||
| 218 : | } | ||
| 219 : | |||
| 220 : | if (count( $cid ) == 1) { | ||
| 221 : | $row = new mosBanner( $database ); | ||
| 222 : | $row->checkin( $cid[0] ); | ||
| 223 : | } | ||
| 224 : | mosRedirect( 'index2.php?option=com_banners' ); | ||
| 225 : | |||
| 226 : | } | ||
| 227 : | |||
| 228 : | function removeBanner( $cid ) { | ||
| 229 : | global $database; | ||
| 230 : | if (count( $cid )) { | ||
| 231 : | $cids = implode( ',', $cid ); | ||
| 232 : | $database->setQuery( "DELETE FROM #__banner WHERE bid IN ($cids)" ); | ||
| 233 : | if (!$database->query()) { | ||
| 234 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 235 : | } | ||
| 236 : | } | ||
| 237 : | mosRedirect( 'index2.php?option=com_banners' ); | ||
| 238 : | } | ||
| 239 : | |||
| 240 : | // ---------- BANNER CLIENTS ---------- | ||
| 241 : | |||
| 242 : | function viewBannerClients( $option ) { | ||
| 243 : | global $database, $mainframe, $mosConfig_list_limit; | ||
| 244 : | |||
| 245 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 246 : | $limitstart = $mainframe->getUserStateFromRequest( "viewcli{$option}limitstart", 'limitstart', 0 ); | ||
| 247 : | |||
| 248 : | // get the total number of records | ||
| 249 : | $database->setQuery( "SELECT count(*) FROM #__bannerclient" ); | ||
| 250 : | $total = $database->loadResult(); | ||
| 251 : | |||
| 252 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 253 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 254 : | |||
| 255 : | $sql = "SELECT a.*, count(b.bid) AS bid, u.name AS editor" | ||
| 256 : | . "\n FROM #__bannerclient AS a" | ||
| 257 : | . "\n LEFT JOIN #__banner AS b ON a.cid = b.cid" | ||
| 258 : | . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out" | ||
| 259 : | . "\n GROUP BY a.cid" | ||
| 260 : | . "\n LIMIT $pageNav->limitstart,$pageNav->limit"; | ||
| 261 : | $database->setQuery($sql); | ||
| 262 : | |||
| 263 : | if(!$result = $database->query()) { | ||
| 264 : | echo $database->stderr(); | ||
| 265 : | return; | ||
| 266 : | } | ||
| 267 : | $rows = $database->loadObjectList(); | ||
| 268 : | |||
| 269 : | HTML_bannerClient::showClients( $rows, $pageNav, $option ); | ||
| 270 : | } | ||
| 271 : | |||
| 272 : | function editBannerClient( $clientid, $option ) { | ||
| 273 : | global $database, $my; | ||
| 274 : | |||
| 275 : | $row = new mosBannerClient($database); | ||
| 276 : | $row->load($clientid); | ||
| 277 : | |||
| 278 : | // fail if checked out not by 'me' | ||
| 279 : | if ($row->checked_out && $row->checked_out <> $my->id) { | ||
| 280 : | $msg = sprintf(T_('The client [ %s ] is currently being edited by another person.'), $row->name); | ||
| 281 : | mosRedirect( 'index2.php?option='. $option .'&task=listclients', $msg ); | ||
| 282 : | } | ||
| 283 : | |||
| 284 : | if ($clientid) { | ||
| 285 : | // do stuff for existing record | ||
| 286 : | $row->checkout( $my->id ); | ||
| 287 : | } else { | ||
| 288 : | // do stuff for new record | ||
| 289 : | $row->published = 0; | ||
| 290 : | $row->approved = 0; | ||
| 291 : | } | ||
| 292 : | |||
| 293 : | HTML_bannerClient::bannerClientForm( $row, $option ); | ||
| 294 : | } | ||
| 295 : | |||
| 296 : | function saveBannerClient( $option ) { | ||
| 297 : | global $database; | ||
| 298 : | |||
| 299 : | $row = new mosBannerClient( $database ); | ||
| 300 : | if (!$row->bind( $_POST )) { | ||
| 301 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 302 : | exit(); | ||
| 303 : | } | ||
| 304 : | if (!$row->check()) { | ||
| 305 : | mosRedirect( "index2.php?option=$option&task=editclient&cid[]=$row->id", $row->getError() ); | ||
| 306 : | } | ||
| 307 : | |||
| 308 : | if (!$row->store()) { | ||
| 309 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 310 : | exit(); | ||
| 311 : | } | ||
| 312 : | $row->checkin(); | ||
| 313 : | |||
| 314 : | mosRedirect( "index2.php?option=$option&task=listclients" ); | ||
| 315 : | } | ||
| 316 : | |||
| 317 : | function cancelEditClient( $option ) { | ||
| 318 : | global $database; | ||
| 319 : | $row = new mosBannerClient( $database ); | ||
| 320 : | $row->bind( $_POST ); | ||
| 321 : | // sanitize | ||
| 322 : | $row->id = intval($row->id); | ||
| 323 : | $row->checkin(); | ||
| 324 : | mosRedirect( "index2.php?option=$option&task=listclients" ); | ||
| 325 : | } | ||
| 326 : | |||
| 327 : | function removeBannerClients( $cid, $option ) { | ||
| 328 : | global $database; | ||
| 329 : | |||
| 330 : | for ($i = 0; $i < count($cid); $i++) { | ||
| 331 : | $query = "SELECT COUNT(bid) FROM #__banner WHERE cid='".$cid[$i]."'"; | ||
| 332 : | $database->setQuery($query); | ||
| 333 : | |||
| 334 : | if(($count = $database->loadResult()) == null) { | ||
| 335 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | if ($count != 0) { | ||
| 339 : | mosRedirect( "index2.php?option=$option&task=listclients", | ||
| 340 : | T_("Cannot delete client at this time as they have a banner still running") ); | ||
| 341 : | } else { | ||
| 342 : | $query="DELETE FROM #__bannerfinish WHERE `cid`='".$cid[$i]."'"; | ||
| 343 : | $database->setQuery($query); | ||
| 344 : | $database->query(); | ||
| 345 : | |||
| 346 : | $query="DELETE FROM #__bannerclient WHERE `cid`='".$cid[$i]."'"; | ||
| 347 : | $database->setQuery($query); | ||
| 348 : | $database->query(); | ||
| 349 : | } | ||
| 350 : | } | ||
| 351 : | mosRedirect("index2.php?option=$option&task=listclients"); | ||
| 352 : | } | ||
| 353 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

