/public_html/sites/all/modules/civicrm/CRM/Contribute/Form/ContributionPage/TabHeader.php

https://github.com/timstephenson/NatureBridge · PHP · 186 lines · 132 code · 18 blank · 36 comment · 18 complexity · c1eed530803d948faf56e35e6362824b MD5 · raw file

  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 4.0 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2011 |
  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. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2011
  31. * $Id$
  32. *
  33. */
  34. /**
  35. * Helper class to build navigation links
  36. */
  37. class CRM_Contribute_Form_ContributionPage_TabHeader
  38. {
  39. static function build( &$form )
  40. {
  41. $tabs = $form->get( 'tabHeader' );
  42. if ( !$tabs || !CRM_Utils_Array::value('reset', $_GET) ) {
  43. $tabs =& self::process( $form );
  44. $form->set( 'tabHeader', $tabs );
  45. }
  46. $form->assign_by_ref( 'tabHeader', $tabs );
  47. $form->assign_by_ref( 'selectedTab', self::getCurrentTab($tabs) );
  48. return $tabs;
  49. }
  50. static function process( &$form )
  51. {
  52. if ( $form->getVar( '_id' ) <= 0 ) {
  53. return null;
  54. }
  55. $tabs = array(
  56. 'settings' => array( 'title' => ts( 'Title' ),
  57. 'link' => null,
  58. 'valid' => false,
  59. 'active' => false,
  60. 'current' => false,
  61. ),
  62. 'amount' => array( 'title' => ts( 'Amounts' ),
  63. 'link' => null,
  64. 'valid' => false,
  65. 'active' => false,
  66. 'current' => false,
  67. ),
  68. 'membership' => array( 'title' => ts( 'Memberships' ),
  69. 'link' => null,
  70. 'valid' => false,
  71. 'active' => false,
  72. 'current' => false,
  73. ),
  74. 'thankYou' => array( 'title' => ts( 'Receipt' ),
  75. 'link' => null,
  76. 'valid' => false,
  77. 'active' => false,
  78. 'current' => false,
  79. ),
  80. 'friend' => array( 'title' => ts( 'Tell a Friend' ),
  81. 'link' => null,
  82. 'valid' => false,
  83. 'active' => false,
  84. 'current' => false,
  85. ),
  86. 'custom' => array( 'title' => ts( 'Profiles' ),
  87. 'link' => null,
  88. 'valid' => false,
  89. 'active' => false,
  90. 'current' => false,
  91. ),
  92. 'premium' => array( 'title' => ts( 'Premiums' ),
  93. 'link' => null,
  94. 'valid' => false,
  95. 'active' => false,
  96. 'current' => false,
  97. ),
  98. 'widget' => array( 'title' => ts( 'Widgets' ),
  99. 'link' => null,
  100. 'valid' => false,
  101. 'active' => false,
  102. 'current' => false,
  103. ),
  104. 'pcp' => array( 'title' => ts( 'Personal Campaigns' ),
  105. 'link' => null,
  106. 'valid' => false,
  107. 'active' => false,
  108. 'current' => false,
  109. ),
  110. );
  111. $contribPageId = $form->getVar( '_id' );
  112. $fullName = $form->getVar( '_name' );
  113. $className = CRM_Utils_String::getClassName( $fullName );
  114. if ( $className == 'ThankYou' ) {
  115. $class = 'thankYou';
  116. } else if ( $className == 'Contribute' ) {
  117. $class = 'friend';
  118. } else if ( $className == 'MembershipBlock' ) {
  119. $class = 'membership';
  120. } else {
  121. $class = strtolower($className) ;
  122. }
  123. $qfKey = $form->get( 'qfKey' );
  124. $form->assign( 'qfKey', $qfKey );
  125. if ( array_key_exists( $class, $tabs ) ) {
  126. $tabs[$class]['current'] = true;
  127. }
  128. if ( $contribPageId ) {
  129. $reset = CRM_Utils_Array::value( 'reset', $_GET ) ? 'reset=1&' : '';
  130. foreach ( $tabs as $key => $value ) {
  131. $tabs[$key]['link'] = CRM_Utils_System::url( "civicrm/admin/contribute/{$key}",
  132. "{$reset}action=update&snippet=4&id={$contribPageId}&qfKey={$qfKey}" );
  133. $tabs[$key]['active'] = $tabs[$key]['valid'] = true;
  134. }
  135. //get all section info.
  136. require_once 'CRM/Contribute/BAO/ContributionPage.php';
  137. $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo( array( $contribPageId ) );
  138. foreach ( $contriPageInfo[$contribPageId] as $section => $info ) {
  139. if ( !$info ) {
  140. $tabs[$section]['valid'] = false;
  141. }
  142. }
  143. }
  144. return $tabs;
  145. }
  146. static function reset( &$form )
  147. {
  148. $tabs =& self::process( $form );
  149. $form->set( 'tabHeader', $tabs );
  150. }
  151. static function getCurrentTab( $tabs )
  152. {
  153. static $current = false;
  154. if ( $current ) {
  155. return $current;
  156. }
  157. if ( is_array($tabs) ) {
  158. foreach ( $tabs as $subPage => $pageVal ) {
  159. if ( $pageVal['current'] === true ) {
  160. $current = $subPage;
  161. break;
  162. }
  163. }
  164. }
  165. $current = $current ? $current : 'settings';
  166. return $current;
  167. }
  168. }