PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/CRM/Contribute/Page/Tab.php

https://github.com/ksecor/civicrm
PHP | 344 lines | 212 code | 51 blank | 81 comment | 30 complexity | 087154000f3673f1074dbdcf067df395 MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.1 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2009 |
  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. |
  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 along with this program; if not, contact CiviCRM LLC |
  21. | at info[AT]civicrm[DOT]org. If you have questions about the |
  22. | GNU Affero General Public License or the licensing of CiviCRM, |
  23. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  24. +--------------------------------------------------------------------+
  25. */
  26. /**
  27. *
  28. * @package CRM
  29. * @copyright CiviCRM LLC (c) 2004-2009
  30. * $Id$
  31. *
  32. */
  33. require_once 'CRM/Contact/Page/View.php';
  34. class CRM_Contribute_Page_Tab extends CRM_Contact_Page_View
  35. {
  36. /**
  37. * The action links that we need to display for the browse screen
  38. *
  39. * @var array
  40. * @static
  41. */
  42. static $_links = null;
  43. /**
  44. * This method returns the links that are given for honor search row.
  45. * currently the links added for each row are
  46. *
  47. * - View
  48. * - Edit
  49. *
  50. * @return array
  51. * @access public
  52. *
  53. */
  54. static function &honorLinks()
  55. {
  56. if (!(self::$_links)) {
  57. self::$_links = array(
  58. CRM_Core_Action::VIEW => array(
  59. 'name' => ts('View'),
  60. 'url' => 'civicrm/contact/view/contribution',
  61. 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&action=view&context=%%cxt%%&selectedChild=contribute',
  62. 'title' => ts('View Contribution'),
  63. ),
  64. CRM_Core_Action::UPDATE => array(
  65. 'name' => ts('Edit'),
  66. 'url' => 'civicrm/contact/view/contribution',
  67. 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&context=%%cxt%%&subType=%%contributionType%%',
  68. 'title' => ts('Edit Contribution'),
  69. ),
  70. CRM_Core_Action::DELETE => array(
  71. 'name' => ts('Delete'),
  72. 'url' => 'civicrm/contact/view/contribution',
  73. 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&context=%%cxt%%',
  74. 'title' => ts('Delete Contribution'),
  75. ),
  76. );
  77. }
  78. return self::$_links;
  79. } //end of function
  80. /**
  81. * This function is called when action is browse
  82. *
  83. * return null
  84. * @access public
  85. */
  86. function browse( )
  87. {
  88. require_once 'CRM/Contribute/BAO/Contribution.php';
  89. // add annual contribution
  90. $annual = array( );
  91. list( $annual['count'],
  92. $annual['amount'],
  93. $annual['avg'] ) =
  94. CRM_Contribute_BAO_Contribution::annual( $this->_contactId );
  95. $this->assign( 'annual', $annual );
  96. $controller =& new CRM_Core_Controller_Simple( 'CRM_Contribute_Form_Search', ts('Contributions'), $this->_action );
  97. $controller->setEmbedded( true );
  98. $controller->reset( );
  99. $controller->set( 'cid' , $this->_contactId );
  100. $controller->set( 'id' , $this->_id );
  101. $controller->set( 'context', 'contribution' );
  102. $controller->process( );
  103. $controller->run( );
  104. //add honor block
  105. // form all action links
  106. $action = array_sum(array_keys($this->honorLinks( )));
  107. $params = array( );
  108. $params = CRM_Contribute_BAO_Contribution::getHonorContacts( $this->_contactId );
  109. if ( ! empty($params) ) {
  110. foreach( $params as $ids => $honorId ) {
  111. $params[$ids]['action'] = CRM_Core_Action::formLink(self::honorLinks( ), $action,
  112. array('cid' => $honorId['honorId'],
  113. 'id' => $ids,
  114. 'cxt' => 'contribution',
  115. 'contributionType' => $honorId['type_id'],
  116. 'honorId' => $this->_contactId )
  117. );
  118. }
  119. // assign vars to templates
  120. $this->assign('action', $this->_action);
  121. $this->assign('honorRows', $params);
  122. $this->assign('honor', true);
  123. }
  124. //enable/disable soft credit records for test contribution
  125. $isTest = 0;
  126. if ( CRM_Utils_Request::retrieve( 'isTest', 'Positive', $this ) ) {
  127. $isTest = 1;
  128. }
  129. $this->assign( 'isTest', $isTest );
  130. $softCreditList = CRM_Contribute_BAO_Contribution::getSoftContributionList( $this->_contactId, $isTest );
  131. if( !empty( $softCreditList ) ) {
  132. $softCreditTotals = array();
  133. list( $softCreditTotals['amount'],
  134. $softCreditTotals['avg'],
  135. $softCreditTotals['currency'] ) =
  136. CRM_Contribute_BAO_Contribution::getSoftContributionTotals( $this->_contactId, $isTest );
  137. $this->assign('softCredit', true);
  138. $this->assign('softCreditRows', $softCreditList );
  139. $this->assign('softCreditTotals', $softCreditTotals );
  140. }
  141. }
  142. /**
  143. * This function is called when action is view
  144. *
  145. * return null
  146. * @access public
  147. */
  148. function view( )
  149. {
  150. $controller =& new CRM_Core_Controller_Simple( 'CRM_Contribute_Form_ContributionView',
  151. 'View Contribution',
  152. $this->_action );
  153. $controller->setEmbedded( true );
  154. $controller->set( 'id' , $this->_id );
  155. $controller->set( 'cid', $this->_contactId );
  156. return $controller->run( );
  157. }
  158. /**
  159. * This function is called when action is update or new
  160. *
  161. * return null
  162. * @access public
  163. */
  164. function edit( )
  165. {
  166. // set https for offline cc transaction
  167. $mode = CRM_Utils_Request::retrieve( 'mode', 'String', $this );
  168. if ( $mode == 'test' || $mode == 'live' ) {
  169. CRM_Utils_System::redirectToSSL( );
  170. }
  171. $controller =& new CRM_Core_Controller_Simple( 'CRM_Contribute_Form_Contribution',
  172. 'Create Contribution',
  173. $this->_action );
  174. $controller->setEmbedded( true );
  175. $controller->set( 'id' , $this->_id );
  176. $controller->set( 'cid', $this->_contactId );
  177. return $controller->run( );
  178. }
  179. /**
  180. * This function is the main function that is called when the page
  181. * loads, it decides the which action has to be taken for the page.
  182. *
  183. * return null
  184. * @access public
  185. */
  186. function run( )
  187. {
  188. $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullArray );
  189. $context = CRM_Utils_Request::retrieve('context', 'String', $this );
  190. if ( $context == 'standalone' && !$contactID ) {
  191. $this->_action = CRM_Core_Action::ADD;
  192. $this->assign('action', $this->_action );
  193. } else {
  194. // we should call contact view, preprocess only for contribution in contact summary
  195. $this->preProcess( );
  196. }
  197. if ( $this->_permission == CRM_Core_Permission::EDIT && ! CRM_Core_Permission::check( 'edit contributions' ) ) {
  198. $this->_permission = CRM_Core_Permission::VIEW; // demote to view since user does not have edit contrib rights
  199. $this->assign( 'permission', 'view' );
  200. }
  201. // check if we can process credit card contribs
  202. $processors = CRM_Core_PseudoConstant::paymentProcessor( false, false,
  203. "billing_mode IN ( 1, 3 )" );
  204. if ( count( $processors ) > 0 ) {
  205. $this->assign( 'newCredit', true );
  206. } else {
  207. $this->assign( 'newCredit', false );
  208. }
  209. $this->setContext( );
  210. if ( $this->_action & CRM_Core_Action::VIEW ) {
  211. $this->view( );
  212. } else if ( $this->_action & ( CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE ) ) {
  213. $this->edit( );
  214. } else {
  215. $this->browse( );
  216. }
  217. return parent::run( );
  218. }
  219. function setContext( )
  220. {
  221. $context = CRM_Utils_Request::retrieve( 'context', 'String',
  222. $this, false, 'search' );
  223. $session =& CRM_Core_Session::singleton( );
  224. switch ( $context ) {
  225. case 'user':
  226. $url = CRM_Utils_System::url( 'civicrm/user', 'reset=1' );
  227. break;
  228. case 'dashboard':
  229. $url = CRM_Utils_System::url( 'civicrm/contribute',
  230. 'reset=1' );
  231. break;
  232. case 'contribution':
  233. $honorId = CRM_Utils_Request::retrieve( 'honorId', 'Positive', $this, false );
  234. if ($honorId) {
  235. $cid = $honorId;
  236. } else {
  237. $cid = $this->_contactId;
  238. }
  239. $url = CRM_Utils_System::url( 'civicrm/contact/view',
  240. "reset=1&force=1&cid={$cid}&selectedChild=contribute" );
  241. break;
  242. case 'search':
  243. $url = CRM_Utils_System::url( 'civicrm/contribute/search', 'force=1' );
  244. break;
  245. case 'home':
  246. $url = CRM_Utils_System::url( 'civicrm/dashboard', 'reset=1' );
  247. break;
  248. case 'activity':
  249. $url = CRM_Utils_System::url( 'civicrm/contact/view',
  250. "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity" );
  251. break;
  252. case 'membership':
  253. $componentId = CRM_Utils_Request::retrieve( 'compId', 'Positive', $this);
  254. $componentAction = CRM_Utils_Request::retrieve( 'compAction', 'Integer', $this );
  255. if ( $componentAction & CRM_Core_Action::VIEW ) {
  256. $action = 'view';
  257. } else {
  258. $action = 'update';
  259. }
  260. $url = CRM_Utils_System::url( 'civicrm/contact/view/membership',
  261. "reset=1&action={$action}&cid={$this->_contactId}&id={$componentId}&context=membership&selectedChild=member" );
  262. break;
  263. case 'participant':
  264. $componentId = CRM_Utils_Request::retrieve( 'compId', 'Positive', $this );
  265. $componentAction = CRM_Utils_Request::retrieve( 'compAction', 'Integer', $this );
  266. if ( $componentAction == CRM_Core_Action::VIEW ) {
  267. $action = 'view';
  268. } else {
  269. $action = 'update';
  270. }
  271. $url = CRM_Utils_System::url( 'civicrm/contact/view/participant',
  272. "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context=participant&selectedChild=event" );
  273. break;
  274. case 'pledge':
  275. $url = CRM_Utils_System::url( 'civicrm/contact/view',
  276. "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge" );
  277. break;
  278. case 'standalone':
  279. $url = CRM_Utils_System::url( 'civicrm/dashboard', 'reset=1' );
  280. break;
  281. default:
  282. $cid = null;
  283. if ( $this->_contactId ) {
  284. $cid = '&cid=' . $this->_contactId;
  285. }
  286. $url = CRM_Utils_System::url( 'civicrm/contribute/search',
  287. 'reset=1&force=1' . $cid );
  288. break;
  289. }
  290. $session =& CRM_Core_Session::singleton( );
  291. $session->pushUserContext( $url );
  292. }
  293. }