Annotation of /mambo/branches/4.6/administrator/components/com_poll/admin.poll.php
Parent Directory
|
Revision Log
Revision 1756 - (view) (download)
| 1 : | elpie | 1756 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo | ||
| 4 : | * @subpackage Polls | ||
| 5 : | * @author Mambo Foundation Inc see README.php | ||
| 6 : | * @copyright (C) 2000 - 2009 Mambo Foundation Inc. | ||
| 7 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 8 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 9 : | * | ||
| 10 : | * Redistributions of files must retain the above copyright notice. | ||
| 11 : | * | ||
| 12 : | * Mambo is free software; you can redistribute it and/or | ||
| 13 : | * modify it under the terms of the GNU General Public License | ||
| 14 : | * as published by the Free Software Foundation; version 2 of the License. | ||
| 15 : | */ | ||
| 16 : | |||
| 17 : | /** ensure this file is being included by a parent file */ | ||
| 18 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 19 : | |||
| 20 : | // ensure user has access to this function | ||
| 21 : | if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) | ||
| 22 : | | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_poll' ))) { | ||
| 23 : | mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); | ||
| 24 : | } | ||
| 25 : | |||
| 26 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 27 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 28 : | |||
| 29 : | $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); | ||
| 30 : | if (!is_array( $cid )) { | ||
| 31 : | $cid = array(0); | ||
| 32 : | } | ||
| 33 : | |||
| 34 : | switch( $task ) { | ||
| 35 : | case 'new': | ||
| 36 : | editPoll( 0, $option ); | ||
| 37 : | break; | ||
| 38 : | |||
| 39 : | case 'edit': | ||
| 40 : | editPoll( $cid[0], $option ); | ||
| 41 : | break; | ||
| 42 : | |||
| 43 : | case 'editA': | ||
| 44 : | editPoll( $id, $option ); | ||
| 45 : | break; | ||
| 46 : | |||
| 47 : | case 'save': | ||
| 48 : | savePoll( $option ); | ||
| 49 : | break; | ||
| 50 : | |||
| 51 : | case 'remove': | ||
| 52 : | removePoll( $cid, $option ); | ||
| 53 : | break; | ||
| 54 : | |||
| 55 : | case 'publish': | ||
| 56 : | publishPolls( $cid, 1, $option ); | ||
| 57 : | break; | ||
| 58 : | |||
| 59 : | case 'unpublish': | ||
| 60 : | publishPolls( $cid, 0, $option ); | ||
| 61 : | break; | ||
| 62 : | |||
| 63 : | case 'cancel': | ||
| 64 : | cancelPoll( $option ); | ||
| 65 : | break; | ||
| 66 : | |||
| 67 : | default: | ||
| 68 : | showPolls( $option ); | ||
| 69 : | break; | ||
| 70 : | } | ||
| 71 : | |||
| 72 : | function showPolls( $option ) { | ||
| 73 : | global $database, $mainframe, $mosConfig_list_limit; | ||
| 74 : | |||
| 75 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 76 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); | ||
| 77 : | |||
| 78 : | // @RawSQLUse, trivial_implementation, SELECT | ||
| 79 : | $database->setQuery( "SELECT COUNT(*) FROM #__polls" ); | ||
| 80 : | $total = $database->loadResult(); | ||
| 81 : | |||
| 82 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 83 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 84 : | |||
| 85 : | $query = "SELECT m.*, u.name AS editor," | ||
| 86 : | . "\n COUNT(d.id) AS numoptions" | ||
| 87 : | . "\n FROM #__polls AS m" | ||
| 88 : | . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out" | ||
| 89 : | . "\n LEFT JOIN #__poll_data AS d ON d.pollid = m.id AND d.text <> ''" | ||
| 90 : | . "\n GROUP BY m.id" | ||
| 91 : | . "\n LIMIT $pageNav->limitstart,$pageNav->limit" | ||
| 92 : | ; | ||
| 93 : | $database->setQuery( $query ); | ||
| 94 : | $rows = $database->loadObjectList(); | ||
| 95 : | |||
| 96 : | if ($database->getErrorNum()) { | ||
| 97 : | echo $database->stderr(); | ||
| 98 : | return false; | ||
| 99 : | } | ||
| 100 : | |||
| 101 : | HTML_poll::showPolls( $rows, $pageNav, $option ); | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | function editPoll( $uid=0, $option='com_poll' ) { | ||
| 105 : | global $database, $my; | ||
| 106 : | |||
| 107 : | $row = new mosPoll( $database ); | ||
| 108 : | // load the row from the db table | ||
| 109 : | $row->load( $uid ); | ||
| 110 : | |||
| 111 : | // fail if checked out not by 'me' | ||
| 112 : | if ($row->checked_out && $row->checked_out <> $my->id) { | ||
| 113 : | $msg = sprintf(T_('The poll %s is currently being edited by another administrator.'),$row->title); | ||
| 114 : | mosRedirect( 'index2.php?option='. $option, $msg); | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | $options = array(); | ||
| 118 : | |||
| 119 : | if ($uid) { | ||
| 120 : | $row->checkout( $my->id ); | ||
| 121 : | // @RawSQLUse, trivial_implementation, SELECT | ||
| 122 : | $query = "SELECT id, text FROM #__poll_data" | ||
| 123 : | . "\n WHERE pollid='$uid'" | ||
| 124 : | . "\n ORDER BY id" | ||
| 125 : | ; | ||
| 126 : | $database->setQuery($query); | ||
| 127 : | $options = $database->loadObjectList(); | ||
| 128 : | } else { | ||
| 129 : | $row->lag = 3600*24; | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | // get selected pages | ||
| 133 : | if ( $uid ) { | ||
| 134 : | // @RawSQLUse, trivial_implementation, SELECT | ||
| 135 : | $database->setQuery( "SELECT menuid AS value FROM #__poll_menu WHERE pollid='$row->id'" ); | ||
| 136 : | $lookup = $database->loadObjectList(); | ||
| 137 : | } else { | ||
| 138 : | $lookup = array( mosHTML::makeOption( 0, 'All' ) ); | ||
| 139 : | } | ||
| 140 : | |||
| 141 : | // build the html select list | ||
| 142 : | $lists['select'] = mosAdminMenus::MenuLinks( $lookup, 1, 1 ); | ||
| 143 : | |||
| 144 : | HTML_poll::editPoll($row, $options, $lists ); | ||
| 145 : | } | ||
| 146 : | |||
| 147 : | function savePoll( $option ) { | ||
| 148 : | global $database, $my; | ||
| 149 : | |||
| 150 : | // save the poll parent information | ||
| 151 : | $row = new mosPoll( $database ); | ||
| 152 : | if (!$row->bind( $_POST )) { | ||
| 153 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 154 : | exit(); | ||
| 155 : | } | ||
| 156 : | $isNew = ($row->id == 0); | ||
| 157 : | |||
| 158 : | if (!$row->check()) { | ||
| 159 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 160 : | exit(); | ||
| 161 : | } | ||
| 162 : | |||
| 163 : | if (!$row->store()) { | ||
| 164 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 165 : | exit(); | ||
| 166 : | } | ||
| 167 : | $row->checkin(); | ||
| 168 : | // save the poll options | ||
| 169 : | $options = mosGetParam( $_POST, 'polloption', array() ); | ||
| 170 : | |||
| 171 : | foreach ($options as $i=>$text) { | ||
| 172 : | // 'slash' the options | ||
| 173 : | if (!get_magic_quotes_gpc()) { | ||
| 174 : | $text = addslashes( $text ); | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | if ($isNew) { | ||
| 178 : | // @RawSQLUse, trivial_implementation, INSERT | ||
| 179 : | $database->setQuery( "INSERT INTO #__poll_data (pollid,text) VALUES ($row->id,'$text')" ); | ||
| 180 : | $database->query(); | ||
| 181 : | } else { | ||
| 182 : | // @RawSQLUse, trivial_implementation, UPDATE | ||
| 183 : | $database->setQuery( "UPDATE #__poll_data SET text='$text' WHERE id='$i' AND pollid='$row->id'" ); | ||
| 184 : | $database->query(); | ||
| 185 : | } | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | // update the menu visibility | ||
| 189 : | $selections = mosGetParam( $_POST, 'selections', array() ); | ||
| 190 : | |||
| 191 : | // @RawSQLUse, trivial_implementation, DELETE | ||
| 192 : | $database->setQuery( "DELETE from #__poll_menu where pollid='$row->id'" ); | ||
| 193 : | $database->query(); | ||
| 194 : | |||
| 195 : | for ($i=0, $n=count($selections); $i < $n; $i++) { | ||
| 196 : | // @RawSQLUse, trivial_implementation, INSERT | ||
| 197 : | $database->setQuery( "INSERT INTO #__poll_menu SET pollid='$row->id', menuid='$selections[$i]'" ); | ||
| 198 : | $database->query(); | ||
| 199 : | } | ||
| 200 : | |||
| 201 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 202 : | } | ||
| 203 : | |||
| 204 : | function removePoll( $cid, $option ) { | ||
| 205 : | global $database; | ||
| 206 : | $msg = ''; | ||
| 207 : | for ($i=0, $n=count($cid); $i < $n; $i++) { | ||
| 208 : | $poll = new mosPoll( $database ); | ||
| 209 : | if (!$poll->delete( $cid[$i] )) { | ||
| 210 : | $msg .= $poll->getError(); | ||
| 211 : | } | ||
| 212 : | } | ||
| 213 : | mosRedirect( 'index2.php?option='. $option .'&mosmsg='. $msg ); | ||
| 214 : | } | ||
| 215 : | |||
| 216 : | /** | ||
| 217 : | * Publishes or Unpublishes one or more records | ||
| 218 : | * @param array An array of unique category id numbers | ||
| 219 : | * @param integer 0 if unpublishing, 1 if publishing | ||
| 220 : | * @param string The current url option | ||
| 221 : | */ | ||
| 222 : | function publishPolls( $cid=null, $publish=1, $option ) { | ||
| 223 : | global $database, $my; | ||
| 224 : | |||
| 225 : | $catid = mosGetParam( $_POST, 'catid', array(0) ); | ||
| 226 : | |||
| 227 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 228 : | $action = $publish ? T_('publish') : T_('unpublish'); | ||
| 229 : | echo "<script> alert('".sprintf(T_('Select an item to %s'), $action)."'); window.history.go(-1);</script>\n"; | ||
| 230 : | exit; | ||
| 231 : | } | ||
| 232 : | |||
| 233 : | $cids = implode( ',', $cid ); | ||
| 234 : | |||
| 235 : | $query = "UPDATE #__polls SET published='$publish'" | ||
| 236 : | . "\n WHERE id IN ($cids)" | ||
| 237 : | . "\n AND ( checked_out=0 OR ( checked_out='$my->id' ) )" | ||
| 238 : | ; | ||
| 239 : | $database->setQuery( $query ); | ||
| 240 : | if (!$database->query()) { | ||
| 241 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 242 : | exit(); | ||
| 243 : | } | ||
| 244 : | |||
| 245 : | if (count( $cid ) == 1) { | ||
| 246 : | $row = new mosPoll( $database ); | ||
| 247 : | $row->checkin( $cid[0] ); | ||
| 248 : | } | ||
| 249 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 250 : | } | ||
| 251 : | |||
| 252 : | function cancelPoll( $option ) { | ||
| 253 : | global $database; | ||
| 254 : | $row = new mosPoll( $database ); | ||
| 255 : | $row->bind( $_POST ); | ||
| 256 : | // sanitize | ||
| 257 : | $row->id = intval($row->id); | ||
| 258 : | $row->checkin(); | ||
| 259 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 260 : | } | ||
| 261 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

