| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.4 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2013 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * Create a page for displaying Contribute Pages |
| 38 | * Contribute Pages are pages that are used to display |
| 39 | * contributions of different types. Pages consist |
| 40 | * of many customizable sections which can be |
| 41 | * accessed. |
| 42 | * |
| 43 | * This page provides a top level browse view |
| 44 | * of all the contribution pages in the system. |
| 45 | * |
| 46 | */ |
| 47 | class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { |
| 48 | |
| 49 | /** |
| 50 | * The action links that we need to display for the browse screen |
| 51 | * |
| 52 | * @var array |
| 53 | */ |
| 54 | private static $_actionLinks; |
| 55 | private static $_contributionLinks; |
| 56 | private static $_configureActionLinks; |
| 57 | private static $_onlineContributionLinks; |
| 58 | |
| 59 | private static $_links = NULL; |
| 60 | |
| 61 | protected $_pager = NULL; |
| 62 | |
| 63 | protected $_sortByCharacter; |
| 64 | |
| 65 | /** |
| 66 | * Get the action links for this page. |
| 67 | * |
| 68 | * @return array $_actionLinks |
| 69 | * |
| 70 | */ function &actionLinks() { |
| 71 | // check if variable _actionsLinks is populated |
| 72 | if (!isset(self::$_actionLinks)) { |
| 73 | // helper variable for nicer formatting |
| 74 | $deleteExtra = ts('Are you sure you want to delete this Contribution page?'); |
| 75 | $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?'); |
| 76 | |
| 77 | self::$_actionLinks = array( |
| 78 | CRM_Core_Action::COPY => array( |
| 79 | 'name' => ts('Make a Copy'), |
| 80 | 'url' => CRM_Utils_System::currentPath(), |
| 81 | 'qs' => 'action=copy&gid=%%id%%', |
| 82 | 'title' => ts('Make a Copy of CiviCRM Contribution Page'), |
| 83 | 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"', |
| 84 | ), |
| 85 | CRM_Core_Action::DISABLE => array( |
| 86 | 'name' => ts('Disable'), |
| 87 | 'title' => ts('Disable'), |
| 88 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Contribute_BAO_ContributionPage' . '\',\'' . 'enable-disable' . '\' );"', |
| 89 | 'ref' => 'disable-action', |
| 90 | ), |
| 91 | CRM_Core_Action::ENABLE => array( |
| 92 | 'name' => ts('Enable'), |
| 93 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Contribute_BAO_ContributionPage' . '\',\'' . 'disable-enable' . '\' );"', |
| 94 | 'ref' => 'enable-action', |
| 95 | 'title' => ts('Enable'), |
| 96 | ), |
| 97 | CRM_Core_Action::DELETE => array( |
| 98 | 'name' => ts('Delete'), |
| 99 | 'url' => CRM_Utils_System::currentPath(), |
| 100 | 'qs' => 'action=delete&reset=1&id=%%id%%', |
| 101 | 'title' => ts('Delete Custom Field'), |
| 102 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', |
| 103 | ), |
| 104 | ); |
| 105 | } |
| 106 | return self::$_actionLinks; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get the configure action links for this page. |
| 111 | * |
| 112 | * @return array $_configureActionLinks |
| 113 | * |
| 114 | */ |
| 115 | function &configureActionLinks() { |
| 116 | // check if variable _actionsLinks is populated |
| 117 | if (!isset(self::$_configureActionLinks)) { |
| 118 | $urlString = 'civicrm/admin/contribute/'; |
| 119 | $urlParams = 'reset=1&action=update&id=%%id%%'; |
| 120 | |
| 121 | self::$_configureActionLinks = array( |
| 122 | CRM_Core_Action::ADD => array( |
| 123 | 'name' => ts('Title and Settings'), |
| 124 | 'title' => ts('Title and Settings'), |
| 125 | 'url' => $urlString . 'settings', |
| 126 | 'qs' => $urlParams, |
| 127 | 'uniqueName' => 'settings', |
| 128 | ), |
| 129 | CRM_Core_Action::UPDATE => array( |
| 130 | 'name' => ts('Contribution Amounts'), |
| 131 | 'title' => ts('Contribution Amounts'), |
| 132 | 'url' => $urlString . 'amount', |
| 133 | 'qs' => $urlParams, |
| 134 | 'uniqueName' => 'amount', |
| 135 | ), |
| 136 | CRM_Core_Action::VIEW => array( |
| 137 | 'name' => ts('Membership Settings'), |
| 138 | 'title' => ts('Membership Settings'), |
| 139 | 'url' => $urlString . 'membership', |
| 140 | 'qs' => $urlParams, |
| 141 | 'uniqueName' => 'membership', |
| 142 | ), |
| 143 | CRM_Core_Action::EXPORT => array( |
| 144 | 'name' => ts('Thank-you and Receipting'), |
| 145 | 'title' => ts('Thank-you and Receipting'), |
| 146 | 'url' => $urlString . 'thankyou', |
| 147 | 'qs' => $urlParams, |
| 148 | 'uniqueName' => 'thankyou', |
| 149 | ), |
| 150 | CRM_Core_Action::BASIC => array( |
| 151 | 'name' => ts('Tell a Friend'), |
| 152 | 'title' => ts('Tell a Friend'), |
| 153 | 'url' => $urlString . 'friend', |
| 154 | 'qs' => $urlParams, |
| 155 | 'uniqueName' => 'friend', |
| 156 | ), |
| 157 | CRM_Core_Action::PROFILE => array( |
| 158 | 'name' => ts('Include Profiles'), |
| 159 | 'title' => ts('Include Profiles'), |
| 160 | 'url' => $urlString . 'custom', |
| 161 | 'qs' => $urlParams, |
| 162 | 'uniqueName' => 'custom', |
| 163 | ), |
| 164 | CRM_Core_Action::MAP => array( |
| 165 | 'name' => ts('Contribution Widget'), |
| 166 | 'title' => ts('Contribution Widget'), |
| 167 | 'url' => $urlString . 'widget', |
| 168 | 'qs' => $urlParams, |
| 169 | 'uniqueName' => 'widget', |
| 170 | ), |
| 171 | CRM_Core_Action::FOLLOWUP => array( |
| 172 | 'name' => ts('Premiums'), |
| 173 | 'title' => ts('Premiums'), |
| 174 | 'url' => $urlString . 'premium', |
| 175 | 'qs' => $urlParams, |
| 176 | 'uniqueName' => 'premium', |
| 177 | ), |
| 178 | CRM_Core_Action::ADVANCED => array( |
| 179 | 'name' => ts('Personal Campaign Pages'), |
| 180 | 'title' => ts('Personal Campaign Pages'), |
| 181 | 'url' => $urlString . 'pcp', |
| 182 | 'qs' => $urlParams, |
| 183 | 'uniqueName' => 'pcp', |
| 184 | ), |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | return self::$_configureActionLinks; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Get the online contribution links. |
| 193 | * |
| 194 | * @return array $_onlineContributionLinks. |
| 195 | * |
| 196 | */ |
| 197 | function &onlineContributionLinks() { |
| 198 | if (!isset(self::$_onlineContributionLinks)) { |
| 199 | $urlString = 'civicrm/contribute/transact'; |
| 200 | $urlParams = 'reset=1&id=%%id%%'; |
| 201 | self::$_onlineContributionLinks = array( |
| 202 | CRM_Core_Action::RENEW => array( |
| 203 | 'name' => ts('Live Page'), |
| 204 | 'title' => ts('Live Page'), |
| 205 | 'url' => $urlString, |
| 206 | 'qs' => $urlParams, |
| 207 | 'fe' => TRUE, |
| 208 | 'uniqueName' => 'live_page', |
| 209 | ), |
| 210 | CRM_Core_Action::PREVIEW => array( |
| 211 | 'name' => ts('Test-drive'), |
| 212 | 'title' => ts('Test-drive'), |
| 213 | 'url' => $urlString, |
| 214 | 'qs' => $urlParams . '&action=preview', |
| 215 | 'uniqueName' => 'test_drive', |
| 216 | ), |
| 217 | ); |
| 218 | } |
| 219 | |
| 220 | return self::$_onlineContributionLinks; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Get the contributions links. |
| 225 | * |
| 226 | * @return array $_contributionLinks |
| 227 | * |
| 228 | */ |
| 229 | function &contributionLinks() { |
| 230 | if (!isset(self::$_contributionLinks)) { |
| 231 | //get contribution dates. |
| 232 | $dates = CRM_Contribute_BAO_Contribution::getContributionDates(); |
| 233 | foreach (array( |
| 234 | 'now', 'yearDate', 'monthDate') as $date) { |
| 235 | $$date = $dates[$date]; |
| 236 | } |
| 237 | $yearNow = $yearDate + 10000; |
| 238 | |
| 239 | $urlString = 'civicrm/contribute/search'; |
| 240 | $urlParams = 'reset=1&pid=%%id%%&force=1&test=0'; |
| 241 | |
| 242 | self::$_contributionLinks = array( |
| 243 | CRM_Core_Action::DETACH => array( |
| 244 | 'name' => ts('Current Month-To-Date'), |
| 245 | 'title' => ts('Current Month-To-Date'), |
| 246 | 'url' => $urlString, |
| 247 | 'qs' => "{$urlParams}&start={$monthDate}&end={$now}", |
| 248 | 'uniqueName' => 'current_month_to_date', |
| 249 | ), |
| 250 | CRM_Core_Action::REVERT => array( |
| 251 | 'name' => ts('Fiscal Year-To-Date'), |
| 252 | 'title' => ts('Fiscal Year-To-Date'), |
| 253 | 'url' => $urlString, |
| 254 | 'qs' => "{$urlParams}&start={$yearDate}&end={$yearNow}", |
| 255 | 'uniqueName' => 'fiscal_year_to_date', |
| 256 | ), |
| 257 | CRM_Core_Action::BROWSE => array( |
| 258 | 'name' => ts('Cumulative'), |
| 259 | 'title' => ts('Cumulative'), |
| 260 | 'url' => $urlString, |
| 261 | 'qs' => "{$urlParams}&start=&end=$now", |
| 262 | 'uniqueName' => 'cumulative', |
| 263 | ), |
| 264 | ); |
| 265 | } |
| 266 | |
| 267 | return self::$_contributionLinks; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Run the page. |
| 272 | * |
| 273 | * This method is called after the page is created. It checks for the |
| 274 | * type of action and executes that action. |
| 275 | * Finally it calls the parent's run method. |
| 276 | * |
| 277 | * @return void |
| 278 | * @access public |
| 279 | * |
| 280 | */ |
| 281 | function run() { |
| 282 | // get the requested action |
| 283 | $action = CRM_Utils_Request::retrieve('action', 'String', |
| 284 | // default to 'browse' |
| 285 | $this, FALSE, 'browse' |
| 286 | ); |
| 287 | |
| 288 | // assign vars to templates |
| 289 | $this->assign('action', $action); |
| 290 | $id = CRM_Utils_Request::retrieve('id', 'Positive', |
| 291 | $this, FALSE, 0 |
| 292 | ); |
| 293 | |
| 294 | // set breadcrumb to append to 2nd layer pages |
| 295 | $breadCrumb = array(array('title' => ts('Manage Contribution Pages'), |
| 296 | 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), |
| 297 | 'reset=1' |
| 298 | ), |
| 299 | )); |
| 300 | |
| 301 | // what action to take ? |
| 302 | if ($action & CRM_Core_Action::ADD) { |
| 303 | $session = CRM_Core_Session::singleton(); |
| 304 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), |
| 305 | 'action=browse&reset=1' |
| 306 | )); |
| 307 | |
| 308 | $controller = new CRM_Contribute_Controller_ContributionPage(NULL, $action); |
| 309 | CRM_Utils_System::setTitle(ts('Manage Contribution Page')); |
| 310 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
| 311 | return $controller->run(); |
| 312 | } |
| 313 | elseif ($action & CRM_Core_Action::UPDATE) { |
| 314 | $config = CRM_Core_Config::singleton(); |
| 315 | |
| 316 | // assign vars to templates |
| 317 | $this->assign('id', $id); |
| 318 | $this->assign('title', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'title')); |
| 319 | $this->assign('is_active', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active')); |
| 320 | if (in_array('CiviMember', $config->enableComponents)) { |
| 321 | $this->assign('CiviMember', TRUE); |
| 322 | } |
| 323 | } |
| 324 | elseif ($action & CRM_Core_Action::COPY) { |
| 325 | $session = CRM_Core_Session::singleton(); |
| 326 | CRM_Core_Session::setStatus(ts('A copy of the contribution page has been created'), ts('Successfully Copied'), 'success'); |
| 327 | $this->copy(); |
| 328 | } |
| 329 | elseif ($action & CRM_Core_Action::DELETE) { |
| 330 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
| 331 | |
| 332 | $session = CRM_Core_Session::singleton(); |
| 333 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), |
| 334 | 'reset=1&action=browse' |
| 335 | )); |
| 336 | |
| 337 | $id = CRM_Utils_Request::retrieve('id', 'Positive', |
| 338 | $this, FALSE, 0 |
| 339 | ); |
| 340 | $query = " |
| 341 | SELECT ccp.title |
| 342 | FROM civicrm_contribution_page ccp |
| 343 | JOIN civicrm_pcp cp ON ccp.id = cp.page_id |
| 344 | WHERE cp.page_id = {$id} |
| 345 | AND cp.page_type = 'contribute' |
| 346 | "; |
| 347 | |
| 348 | if ($pageTitle = CRM_Core_DAO::singleValueQuery($query)) { |
| 349 | CRM_Core_Session::setStatus(ts('The \'%1\' cannot be deleted! You must Delete all Personal Campaign Page(s) related with this contribution page prior to deleting the page.', array(1 => $pageTitle)), ts('Deletion Error'), 'error'); |
| 350 | |
| 351 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1')); |
| 352 | } |
| 353 | |
| 354 | $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionPage_Delete', |
| 355 | 'Delete Contribution Page', |
| 356 | CRM_Core_Action::DELETE |
| 357 | ); |
| 358 | $controller->set('id', $id); |
| 359 | $controller->process(); |
| 360 | return $controller->run(); |
| 361 | } |
| 362 | else { |
| 363 | // finally browse the contribution pages |
| 364 | $this->browse(); |
| 365 | |
| 366 | CRM_Utils_System::setTitle(ts('Manage Contribution Pages')); |
| 367 | } |
| 368 | |
| 369 | return parent::run(); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * This function is to make a copy of a contribution page, including |
| 374 | * all the fields in the page |
| 375 | * |
| 376 | * @return void |
| 377 | * @access public |
| 378 | */ |
| 379 | function copy() { |
| 380 | $gid = CRM_Utils_Request::retrieve('gid', 'Positive', |
| 381 | $this, TRUE, 0, 'GET' |
| 382 | ); |
| 383 | |
| 384 | CRM_Contribute_BAO_ContributionPage::copy($gid); |
| 385 | |
| 386 | CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Browse all contribution pages |
| 391 | * |
| 392 | * @return void |
| 393 | * @access public |
| 394 | * @static |
| 395 | */ |
| 396 | function browse($action = NULL) { |
| 397 | $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', |
| 398 | 'String', |
| 399 | $this |
| 400 | ); |
| 401 | $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', |
| 402 | $this, FALSE, 0 |
| 403 | ); |
| 404 | |
| 405 | if ($this->_sortByCharacter == 1 || |
| 406 | !empty($_POST) |
| 407 | ) { |
| 408 | $this->_sortByCharacter = ''; |
| 409 | $this->set('sortByCharacter', ''); |
| 410 | } |
| 411 | |
| 412 | $this->search(); |
| 413 | |
| 414 | $params = array(); |
| 415 | |
| 416 | $whereClause = $this->whereClause($params, FALSE); |
| 417 | $this->pagerAToZ($whereClause, $params); |
| 418 | |
| 419 | $params = array(); |
| 420 | $whereClause = $this->whereClause($params, TRUE); |
| 421 | $this->pager($whereClause, $params); |
| 422 | |
| 423 | list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); |
| 424 | |
| 425 | //check for delete CRM-4418 |
| 426 | $allowToDelete = CRM_Core_Permission::check('delete in CiviContribute'); |
| 427 | |
| 428 | $query = " |
| 429 | SELECT id |
| 430 | FROM civicrm_contribution_page |
| 431 | WHERE $whereClause |
| 432 | LIMIT $offset, $rowCount"; |
| 433 | $contribPage = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage'); |
| 434 | $contribPageIds = array(); |
| 435 | while ($contribPage->fetch()) { |
| 436 | $contribPageIds[$contribPage->id] = $contribPage->id; |
| 437 | } |
| 438 | //get all section info. |
| 439 | $contriPageSectionInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo($contribPageIds); |
| 440 | |
| 441 | $query = " |
| 442 | SELECT * |
| 443 | FROM civicrm_contribution_page |
| 444 | WHERE $whereClause |
| 445 | ORDER BY title asc |
| 446 | LIMIT $offset, $rowCount"; |
| 447 | |
| 448 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage'); |
| 449 | |
| 450 | //get all campaigns. |
| 451 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); |
| 452 | |
| 453 | //get configure actions links. |
| 454 | $configureActionLinks = self::configureActionLinks(); |
| 455 | |
| 456 | while ($dao->fetch()) { |
| 457 | $contribution[$dao->id] = array(); |
| 458 | CRM_Core_DAO::storeValues($dao, $contribution[$dao->id]); |
| 459 | |
| 460 | // form all action links |
| 461 | $action = array_sum(array_keys($this->actionLinks())); |
| 462 | |
| 463 | //add configure actions links. |
| 464 | $action += array_sum(array_keys($configureActionLinks)); |
| 465 | |
| 466 | //add online contribution links. |
| 467 | $action += array_sum(array_keys(self::onlineContributionLinks())); |
| 468 | |
| 469 | //add contribution search links. |
| 470 | $action += array_sum(array_keys(self::contributionLinks())); |
| 471 | |
| 472 | if ($dao->is_active) { |
| 473 | $action -= CRM_Core_Action::ENABLE; |
| 474 | } |
| 475 | else { |
| 476 | $action -= CRM_Core_Action::DISABLE; |
| 477 | } |
| 478 | |
| 479 | //CRM-4418 |
| 480 | if (!$allowToDelete) { |
| 481 | $action -= CRM_Core_Action::DELETE; |
| 482 | } |
| 483 | |
| 484 | //build the configure links. |
| 485 | $sectionsInfo = CRM_Utils_Array::value($dao->id, $contriPageSectionInfo, array()); |
| 486 | $contribution[$dao->id]['configureActionLinks'] = CRM_Core_Action::formLink(self::formatConfigureLinks($sectionsInfo), |
| 487 | $action, |
| 488 | array('id' => $dao->id), |
| 489 | ts('Configure'), |
| 490 | TRUE |
| 491 | ); |
| 492 | |
| 493 | //build the contributions links. |
| 494 | $contribution[$dao->id]['contributionLinks'] = CRM_Core_Action::formLink(self::contributionLinks(), |
| 495 | $action, |
| 496 | array('id' => $dao->id), |
| 497 | ts('Contributions'), |
| 498 | TRUE |
| 499 | ); |
| 500 | |
| 501 | //build the online contribution links. |
| 502 | $contribution[$dao->id]['onlineContributionLinks'] = CRM_Core_Action::formLink(self::onlineContributionLinks(), |
| 503 | $action, |
| 504 | array('id' => $dao->id), |
| 505 | ts('Links'), |
| 506 | TRUE |
| 507 | ); |
| 508 | |
| 509 | //build the normal action links. |
| 510 | $contribution[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), |
| 511 | $action, |
| 512 | array('id' => $dao->id), |
| 513 | ts('more'), |
| 514 | TRUE |
| 515 | ); |
| 516 | |
| 517 | //show campaigns on selector. |
| 518 | $contribution[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns); |
| 519 | } |
| 520 | |
| 521 | if (isset($contribution)) { |
| 522 | $this->assign('rows', $contribution); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | function search() { |
| 527 | if (isset($this->_action) & |
| 528 | (CRM_Core_Action::ADD | |
| 529 | CRM_Core_Action::UPDATE | |
| 530 | CRM_Core_Action::DELETE |
| 531 | ) |
| 532 | ) { |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | $form = new CRM_Core_Controller_Simple('CRM_Contribute_Form_SearchContribution', |
| 537 | ts('Search Contribution'), |
| 538 | CRM_Core_Action::ADD |
| 539 | ); |
| 540 | $form->setEmbedded(TRUE); |
| 541 | $form->setParent($this); |
| 542 | $form->process(); |
| 543 | $form->run(); |
| 544 | } |
| 545 | |
| 546 | function whereClause(&$params, $sortBy = TRUE) { |
| 547 | $values = $clauses = array(); |
| 548 | $title = $this->get('title'); |
| 549 | $createdId = $this->get('cid'); |
| 550 | |
| 551 | if ($createdId) { |
| 552 | $clauses[] = "(created_id = {$createdId})"; |
| 553 | } |
| 554 | |
| 555 | if ($title) { |
| 556 | $clauses[] = "title LIKE %1"; |
| 557 | if (strpos($title, '%') !== FALSE) { |
| 558 | $params[1] = array(trim($title), 'String', FALSE); |
| 559 | } |
| 560 | else { |
| 561 | $params[1] = array(trim($title), 'String', TRUE); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | $value = $this->get( 'financial_type_id' ); |
| 566 | $val = array(); |
| 567 | if ($value) { |
| 568 | if (is_array($value)) { |
| 569 | foreach ($value as $k => $v) { |
| 570 | if ($v) { |
| 571 | $val[$k] = $k; |
| 572 | } |
| 573 | } |
| 574 | $type = implode(',', $val); |
| 575 | } |
| 576 | |
| 577 | $clauses[] = "financial_type_id IN ({$type})"; |
| 578 | } |
| 579 | |
| 580 | if ($sortBy && |
| 581 | $this->_sortByCharacter !== NULL |
| 582 | ) { |
| 583 | $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'"; |
| 584 | } |
| 585 | |
| 586 | $campainIds = $this->get('campaign_id'); |
| 587 | if (!CRM_Utils_System::isNull($campainIds)) { |
| 588 | if (!is_array($campainIds)) { |
| 589 | $campaignIds = array($campaignIds); |
| 590 | } |
| 591 | $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )'; |
| 592 | } |
| 593 | |
| 594 | if (empty($clauses)) { |
| 595 | // Let template know if user has run a search or not |
| 596 | $this->assign('isSearch', 0); |
| 597 | return 1; |
| 598 | } |
| 599 | else { |
| 600 | $this->assign('isSearch', 1); |
| 601 | } |
| 602 | |
| 603 | return implode(' AND ', $clauses); |
| 604 | } |
| 605 | |
| 606 | function pager($whereClause, $whereParams) { |
| 607 | |
| 608 | $params['status'] = ts('Contribution %%StatusMessage%%'); |
| 609 | $params['csvString'] = NULL; |
| 610 | $params['buttonTop'] = 'PagerTopButton'; |
| 611 | $params['buttonBottom'] = 'PagerBottomButton'; |
| 612 | $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); |
| 613 | if (!$params['rowCount']) { |
| 614 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; |
| 615 | } |
| 616 | |
| 617 | $query = " |
| 618 | SELECT count(id) |
| 619 | FROM civicrm_contribution_page |
| 620 | WHERE $whereClause"; |
| 621 | |
| 622 | $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams); |
| 623 | |
| 624 | $this->_pager = new CRM_Utils_Pager($params); |
| 625 | $this->assign_by_ref('pager', $this->_pager); |
| 626 | } |
| 627 | |
| 628 | function pagerAtoZ($whereClause, $whereParams) { |
| 629 | |
| 630 | $query = " |
| 631 | SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name |
| 632 | FROM civicrm_contribution_page |
| 633 | WHERE $whereClause |
| 634 | ORDER BY LEFT(title, 1) |
| 635 | "; |
| 636 | $dao = CRM_Core_DAO::executeQuery($query, $whereParams); |
| 637 | |
| 638 | $aToZBar = CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE); |
| 639 | $this->assign('aToZ', $aToZBar); |
| 640 | } |
| 641 | |
| 642 | function formatConfigureLinks($sectionsInfo) { |
| 643 | //build the formatted configure links. |
| 644 | $formattedConfLinks = self::configureActionLinks(); |
| 645 | foreach ($formattedConfLinks as $act => & $link) { |
| 646 | $sectionName = CRM_Utils_Array::value('uniqueName', $link); |
| 647 | if (!$sectionName) { |
| 648 | continue; |
| 649 | } |
| 650 | |
| 651 | $classes = array(); |
| 652 | if (isset($link['class'])) { |
| 653 | $classes = $link['class']; |
| 654 | } |
| 655 | |
| 656 | if (!CRM_Utils_Array::value($sectionName, $sectionsInfo)) { |
| 657 | $classes = array(); |
| 658 | if (isset($link['class'])) { |
| 659 | $classes = $link['class']; |
| 660 | } |
| 661 | $link['class'] = array_merge($classes, array('disabled')); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | return $formattedConfLinks; |
| 666 | } |
| 667 | } |
| 668 | |