<commit_before><?php

require_once 'CRM/Core/Page.php';

class CRM_Pcpteams_Form_PCP_Manage extends CRM_Core_Form {
  
  function preProcess(){
    CRM_Core_Resources::singleton()
      ->addStyleFile('uk.co.vedaconsulting.pcpteams', 'css/manage.css');

    $session = CRM_Core_Session::singleton();
    $this->_userID = $session->get('userID');
    if (!$this->_userID) {
      CRM_Core_Error::fatal(ts('You must be logged in to view this page.'));
    } 
    else {
      $pcpId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, TRUE); 
      if(!CRM_Pcpteams_Utils::hasPermission($pcpId, $this->_userID, CRM_Core_Permission::VIEW)) {
        CRM_Core_Error::fatal(ts('You do not have permission to view this Page'));
      }
    }
  }

  function buildQuickForm() {
    //get params from URL
    $state = NULL;
    $pcpId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, TRUE); 
    $state = CRM_Utils_Request::retrieve('state', 'String');
    $pcpContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'contact_id');
    
    $aContactTypes   = CRM_Contact_BAO_Contact::getContactTypes( $pcpContactId );
    if (in_array('Team', $aContactTypes) && self::checkTeamAdmin($pcpContactId,  $this->_userID)) {
      $pcpContactId = $this->_userID ;
    }
    
    if ($this->_userID != $pcpContactId) {
      CRM_Core_Error::fatal(ts('You do not have permission to view this Page'));
    }
    
    //Image URL
    $getPcpImgURl   = self::getPcpImageURl($pcpId);
    if(!empty($getPcpImgURl)) {
      $this->assign('profilePicUrl', $getPcpImgURl);
    }
    
    //Pcp Details
    $pcpDetails  = self::getPcpDetails($pcpId);
    $this->assign('pcpinfo', $pcpDetails);
    
    //check User is Team Admin
    if(!isset($pcpDetails['contact_id'])){
      $pcpDetails['contact_id']   = CRM_Pcpteams_Utils::getcontactIdbyPcpId($pcpId);
    }
    $isTeamAdmin = FALSE;
    if(isset($pcpDetails['team_pcp_id'])){
      $teamPcpcontactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpDetails['team_pcp_id'], 'contact_id');
      $isTeamAdmin      = self::checkTeamAdmin($teamPcpcontactId,  $this->_userID);
    }
    $this->assign('isTeamAdmin', $isTeamAdmin);<commit_msg>remove these line., already checking has permission in preProcess., this is repeated code<commit_after><?php

require_once 'CRM/Core/Page.php';

class CRM_Pcpteams_Form_PCP_Manage extends CRM_Core_Form {
  
  function preProcess(){
    CRM_Core_Resources::singleton()
      ->addStyleFile('uk.co.vedaconsulting.pcpteams', 'css/manage.css');

    $session = CRM_Core_Session::singleton();
    $this->_userID = $session->get('userID');
    if (!$this->_userID) {
      CRM_Core_Error::fatal(ts('You must be logged in to view this page.'));
    } 
    else {
      $pcpId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, TRUE); 
      if(!CRM_Pcpteams_Utils::hasPermission($pcpId, $this->_userID, CRM_Core_Permission::VIEW)) {
        CRM_Core_Error::fatal(ts('You do not have permission to view this Page'));
      }
    }
  }

  function buildQuickForm() {
    //get params from URL
    $state = NULL;
    $pcpId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, TRUE); 
    $state = CRM_Utils_Request::retrieve('state', 'String');
    $pcpContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'contact_id');
    
    //Image URL
    $getPcpImgURl   = self::getPcpImageURl($pcpId);
    if(!empty($getPcpImgURl)) {
      $this->assign('profilePicUrl', $getPcpImgURl);
    }
    
    //Pcp Details
    $pcpDetails  = self::getPcpDetails($pcpId);
    $this->assign('pcpinfo', $pcpDetails);
    
    //check User is Team Admin
    if(!isset($pcpDetails['contact_id'])){
      $pcpDetails['contact_id']   = CRM_Pcpteams_Utils::getcontactIdbyPcpId($pcpId);
    }
    $isTeamAdmin = FALSE;
    if(isset($pcpDetails['team_pcp_id'])){
      $teamPcpcontactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpDetails['team_pcp_id'], 'contact_id');
      $isTeamAdmin      = self::checkTeamAdmin($teamPcpcontactId,  $this->_userID);
    }
    $this->assign('isTeamAdmin', $isTeamAdmin);
{'fraction_non_alphanumeric': 0.15568862275449102, 'fraction_numerical': 0.0, 'mean_word_length': 4.161928306551298, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3723039', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1502, 'n_words': 229}