/modules/contributions/civicrm/CRM/Contact/Page/View/Relationship.php

https://github.com/bhirsch/voipdrupal-4.7-1.0 · PHP · 210 lines · 106 code · 24 blank · 80 comment · 9 complexity · f569b0f46f3ada5a3644ada588637f9e MD5 · raw file

  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 1.4 |
  5. +--------------------------------------------------------------------+
  6. | Copyright (c) 2005 Donald A. Lobo |
  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 Affero General Public License Version 1, |
  12. | March 2002. |
  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 Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the Affero General Public |
  20. | License along with this program; if not, contact the Social Source |
  21. | Foundation at info[AT]socialsourcefoundation[DOT]org. If you have |
  22. | questions about the Affero General Public License or the licensing |
  23. | of CiviCRM, see the Social Source Foundation CiviCRM license FAQ |
  24. | at http://www.openngo.org/faqs/licensing.html |
  25. +--------------------------------------------------------------------+
  26. */
  27. /**
  28. * This class contains functions for managing Relationship(s) of a Contact.
  29. *
  30. * @package CRM
  31. * @author Donald A. Lobo <lobo@yahoo.com>
  32. * @copyright Donald A. Lobo (c) 2005
  33. * $Id$
  34. *
  35. */
  36. $GLOBALS['_CRM_CONTACT_PAGE_VIEW_RELATIONSHIP']['_links'] = null;
  37. require_once 'CRM/Contact/Page/View.php';
  38. class CRM_Contact_Page_View_Relationship extends CRM_Contact_Page_View {
  39. /**
  40. * The action links that we need to display for the browse screen
  41. *
  42. * @var array
  43. * @static
  44. */
  45. /**
  46. * View details of a relationship
  47. *
  48. * @return void
  49. *
  50. * @access public
  51. */
  52. function view( )
  53. {
  54. $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship( $this->_contactId, null, null, null, $this->_id );
  55. $this->assign( 'viewRelationship', $viewRelationship );
  56. }
  57. /**
  58. * This function is called when action is browse
  59. *
  60. * return null
  61. * @access public
  62. */
  63. function browse( ) {
  64. $links =& CRM_Contact_Page_View_Relationship::links( );
  65. $mask = CRM_Core_Action::mask( $this->_permission );
  66. $currentRelationships = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId,
  67. CRM_CONTACT_BAO_RELATIONSHIP_CURRENT ,
  68. 0, 0, 0,
  69. $links, $mask );
  70. $pastRelationships = CRM_Contact_BAO_Relationship::getRelationship( $this->_contactId,
  71. CRM_CONTACT_BAO_RELATIONSHIP_PAST ,
  72. 0, 0, 0,
  73. $links, $mask );
  74. $disableRelationships = CRM_Contact_BAO_Relationship::getRelationship( $this->_contactId,
  75. CRM_CONTACT_BAO_RELATIONSHIP_DISABLED ,
  76. 0, 0, 0,
  77. $links, $mask );
  78. $this->assign( 'currentRelationships', $currentRelationships );
  79. $this->assign( 'pastRelationships' , $pastRelationships );
  80. $this->assign( 'disableRelationships', $disableRelationships );
  81. }
  82. /**
  83. * This function is called when action is update or new
  84. *
  85. * return null
  86. * @access public
  87. */
  88. function edit( ) {
  89. $controller =& new CRM_Core_Controller_Simple( 'CRM_Contact_Form_Relationship', ts('Contact Relationships'), $this->_action );
  90. $controller->setEmbedded( true );
  91. // set the userContext stack
  92. $session =& CRM_Core_Session::singleton();
  93. $url = CRM_Utils_System::url('civicrm/contact/view/rel', 'action=browse' );
  94. $session->pushUserContext( $url );
  95. if (CRM_Utils_Request::retrieve('confirmed', $form, '', '', 'GET') ) {
  96. CRM_Contact_BAO_Relationship::del( $this->_id);
  97. CRM_Utils_System::redirect($url);
  98. }
  99. $controller->set( 'contactId', $this->_contactId );
  100. $controller->set( 'id' , $this->_id );
  101. $controller->process( );
  102. $controller->run( );
  103. }
  104. /**
  105. * This function is the main function that is called when the page loads,
  106. * it decides the which action has to be taken for the page.
  107. *
  108. * return null
  109. * @access public
  110. */
  111. function run( ) {
  112. $this->preProcess( );
  113. if ( $this->_action & CRM_CORE_ACTION_VIEW ) {
  114. $this->view( );
  115. } else if ( $this->_action & ( CRM_CORE_ACTION_UPDATE | CRM_CORE_ACTION_ADD | CRM_CORE_ACTION_DELETE ) ) {
  116. $this->edit( );
  117. } else if ( $this->_action & CRM_CORE_ACTION_DISABLE ) {
  118. CRM_Contact_BAO_Relationship::setIsActive( $this->_id, 0 ) ;
  119. } else if ( $this->_action & CRM_CORE_ACTION_ENABLE ) {
  120. CRM_Contact_BAO_Relationship::setIsActive( $this->_id, 1 ) ;
  121. }
  122. $this->browse( );
  123. return parent::run( );
  124. }
  125. /**
  126. * This function is called to delete the relationship of a contact
  127. *
  128. * return null
  129. * @access public
  130. */
  131. function delete( ) {
  132. // calls a function to delete relationship
  133. CRM_Contact_BAO_Relationship::del($this->_id);
  134. }
  135. /**
  136. * Get action links
  137. *
  138. * @return array (reference) of action links
  139. * @static
  140. */
  141. function &links()
  142. {
  143. if (!($GLOBALS['_CRM_CONTACT_PAGE_VIEW_RELATIONSHIP']['_links'])) {
  144. $deleteExtra = ts('Are you sure you want to delete this relationship?');
  145. $disableExtra = ts('Are you sure you want to disable this relationship?');
  146. $enableExtra = ts('Are you sure you want to re-enable this relationship?');
  147. $GLOBALS['_CRM_CONTACT_PAGE_VIEW_RELATIONSHIP']['_links'] = array(
  148. CRM_CORE_ACTION_VIEW => array(
  149. 'name' => ts('View'),
  150. 'url' => 'civicrm/contact/view/rel',
  151. 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
  152. 'title' => ts('View Relationship')
  153. ),
  154. CRM_CORE_ACTION_UPDATE => array(
  155. 'name' => ts('Edit'),
  156. 'url' => 'civicrm/contact/view/rel',
  157. 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
  158. 'title' => ts('Edit Relationship')
  159. ),
  160. CRM_CORE_ACTION_ENABLE => array(
  161. 'name' => ts('Enable'),
  162. 'url' => 'civicrm/contact/view/rel',
  163. 'qs' => 'action=enable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
  164. 'extra' => 'onclick = "return confirm(\'' . $enableExtra . '\');"',
  165. 'title' => ts('Enable Relationship')
  166. ),
  167. CRM_CORE_ACTION_DISABLE => array(
  168. 'name' => ts('Disable'),
  169. 'url' => 'civicrm/contact/view/rel',
  170. 'qs' => 'action=disable&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
  171. 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
  172. 'title' => ts('Disable Relationship')
  173. ),
  174. CRM_CORE_ACTION_DELETE => array(
  175. 'name' => ts('Delete'),
  176. 'url' => 'civicrm/contact/view/rel',
  177. 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
  178. 'extra' => 'onclick = "if (confirm(\'' . $deleteExtra . '\') ) this.href+=\'&amp;confirmed=1\'; else return false;"',
  179. 'title' => ts('Delete Relationship')
  180. ),
  181. );
  182. }
  183. return $GLOBALS['_CRM_CONTACT_PAGE_VIEW_RELATIONSHIP']['_links'];
  184. }
  185. }
  186. ?>