/**
  * Generates the HTML to display the user profile tab
  * @param  moscomprofilerTab   $tab       the tab database entry
  * @param  moscomprofilerUser  $user      the user being displayed
  * @param  int                 $ui        1 for front-end, 2 for back-end
  * @return mixed                          either string HTML for tab content, or false if ErrorMSG generated
  */
 function getDisplayTab($tab, $user, $ui)
 {
     global $_CB_framework, $_CB_database, $ueConfig;
     // Display shortest connection path / Degree of relationship:
     $return = "";
     if ($_CB_framework->myId() != $user->id && $_CB_framework->myId() > 0 && isset($ueConfig['connectionPath']) && $ueConfig['connectionPath'] && $ueConfig['allowConnections']) {
         $return .= $this->_writeTabDescription($tab, $user);
         $return .= "\t\t<div class=\"cbConnectionPaths\">";
         $i = 0;
         $cbCon = new cbConnection($_CB_framework->myId());
         $congroups = $cbCon->getDegreeOfSepPath($_CB_framework->myId(), $user->id);
         $directConDetails = $cbCon->getConnectionDetails($_CB_framework->myId(), $user->id);
         if (is_array($congroups) && count($congroups) > 2) {
             cbArrayToInts($congroups);
             $query = "SELECT u.name,u.email,u.username,c.avatar,c.avatarapproved, u.id " . "\n FROM #__comprofiler AS c" . "\n LEFT JOIN #__users AS u ON c.id=u.id" . "\n WHERE c.id IN (" . implode(',', $congroups) . ")" . "\n AND c.approved=1 AND c.confirmed=1 AND c.banned=0 AND u.block=0";
             $_CB_database->setQuery($query);
             $connections = $_CB_database->loadObjectList('id');
             $prevConID = null;
             $prevConName = null;
             if (isset($connections[$user->id])) {
                 $live_site = $_CB_framework->getCfg('live_site');
                 $return .= _UE_CONNECTIONPATH1 . getNameFormat($connections[$user->id]->name, $connections[$user->id]->username, $ueConfig['name_format']) . " ( " . $cbCon->getDegreeOfSep() . _UE_CONNECTIONPATH2;
                 foreach ($congroups as $congroup) {
                     if ($i != 0) {
                         $return .= ' <img src="' . $live_site . '/components/com_comprofiler/images/arrow.png" alt="" /> ';
                     }
                     $conName = getNameFormat($connections[$congroup]->name, $connections[$congroup]->username, $ueConfig['name_format']);
                     if ($congroup != $_CB_framework->myId() && isset($connections[$congroup])) {
                         $conDetail = $cbCon->getConnectionDetails($prevConID, $congroup);
                         $conAvatar = getFieldValue('image', $connections[$congroup]->avatar, $connections[$congroup]);
                         $tipField = "<b>" . _UE_CONNECTEDSINCE . "</b> : " . dateConverter($conDetail->membersince, 'Y-m-d', $ueConfig['date_format']);
                         if (getLangDefinition($conDetail->type) != null) {
                             $tipField .= "<br /><b>" . _UE_CONNECTIONTYPE . "</b> : " . getConnectionTypes($conDetail->type);
                         }
                         if ($conDetail->description != null) {
                             $tipField .= "<br /><b>" . _UE_CONNECTEDCOMMENT . "</b> : " . htmlspecialchars($conDetail->description);
                         }
                         $tipField .= "<div style=\"text-align:center;margin:8px;\">" . htmlspecialchars(preg_replace('/onclick\\s*=\\s*".+"/Uis', "", $conAvatar), ENT_QUOTES) . "</div>";
                         $tipTitle = $prevConName . _UE_DETAILSABOUT . str_replace("'", "&amp;#039;", $conName);
                         $htmltext = $conName;
                         $href = 'javascript:void(0)';
                         if ($congroup != $user->id) {
                             $href = cbSef("index.php?option=com_comprofiler&amp;task=userProfile&amp;user="******"<br />" . sprintf(_UE_DIRECTCONNECTIONPENDINGACCEPTANCE, getNameFormat($user->name, $user->username, $ueConfig['name_format']));
                 }
             } else {
                 $return .= _UE_NOESTABLISHEDCONNECTION . getNameFormat($user->name, $user->username, $ueConfig['name_format']);
             }
         } elseif (is_array($congroups) && count($congroups) == 2) {
             $return .= _UE_DIRECTCONNECTION . getNameFormat($user->name, $user->username, $ueConfig['name_format']);
         } else {
             if ($directConDetails !== false && $directConDetails->pending) {
                 $return .= "<br />" . sprintf(_UE_DIRECTCONNECTIONPENDINGACCEPTANCE, getNameFormat($user->name, $user->username, $ueConfig['name_format']));
             } else {
                 $return .= _UE_NOESTABLISHEDCONNECTION . getNameFormat($user->name, $user->username, $ueConfig['name_format']);
             }
         }
         $return .= "</div>";
     }
     return $return;
 }
 /**
  * Generates the HTML to display the user profile tab
  *
  * @param  \CB\Database\Table\TabTable   $tab       the tab database entry
  * @param  \CB\Database\Table\UserTable  $user      the user being displayed
  * @param  int                           $ui        1 for front-end, 2 for back-end
  * @return string|boolean                           Either string HTML for tab content, or false if ErrorMSG generated
  */
 public function getDisplayTab($tab, $user, $ui)
 {
     global $_CB_framework, $_CB_database, $ueConfig;
     $return = null;
     if ($_CB_framework->myId() != $user->id && $_CB_framework->myId() > 0 && (isset($ueConfig['connectionPath']) && $ueConfig['connectionPath']) && $ueConfig['allowConnections']) {
         $myCBUser = CBuser::getInstance((int) $user->id, false);
         $myName = $myCBUser->getField('formatname', null, 'html', 'none', 'profile', 0, true);
         $myAvatar = $myCBUser->getField('avatar', null, 'html', 'none', 'profile', 0, true, array('_hideApproval' => 1));
         $i = 0;
         $cbCon = new cbConnection($_CB_framework->myId());
         $conGroups = $cbCon->getDegreeOfSepPath($_CB_framework->myId(), $user->id);
         $directConDetails = $cbCon->getConnectionDetails($_CB_framework->myId(), $user->id);
         $addConnURL = $_CB_framework->viewUrl('addconnection', true, array('connectionid' => (int) $user->id));
         $removeConnURL = $_CB_framework->viewUrl('removeconnection', true, array('connectionid' => (int) $user->id));
         $acceptConnURL = $_CB_framework->viewUrl('acceptconnection', true, array('connectionid' => (int) $user->id));
         $denyConnURL = $_CB_framework->viewUrl('denyconnection', true, array('connectionid' => (int) $user->id));
         if ($ueConfig['conNotifyType'] != 0) {
             cbValidator::loadValidation();
             $tooltipTitle = sprintf(CBTxt::T('UE_CONNECTTO', 'Connect to %s'), $myName);
             $ooltipHTML = '<div class="form-group cb_form_line clearfix">' . CBTxt::Th('UE_CONNECTIONINVITATIONMSG', 'Personalize your invitation to connect by adding a message that will be included with your connection.') . '</div>' . '<form action="' . $addConnURL . '" method="post" id="connOverForm" name="connOverForm" class="cb_form cbValidation">' . '<div class="form-group cb_form_line clearfix">' . '<label for="message" class="control-label">' . CBTxt::T('UE_MESSAGE', 'Message') . '</label>' . '<div class="cb_field">' . '<textarea cols="40" rows="8" name="message" class="form-control"></textarea>' . '</div>' . '</div>' . '<div class="form-group cb_form_line clearfix">' . '<input type="submit" class="btn btn-primary cbConnReqSubmit" value="' . htmlspecialchars(CBTxt::Th('UE_SENDCONNECTIONREQUEST', 'Request Connection')) . '"' . cbValidator::getSubmitBtnHtmlAttributes() . ' />' . ' <input type="button" id="cbConnReqCancel" class="btn btn-default cbConnReqCancel cbTooltipClose" value="' . htmlspecialchars(CBTxt::Th('UE_CANCELCONNECTIONREQUEST', 'Cancel')) . '" />' . '</div>' . '</form>';
             $tooltip = cbTooltip($ui, $ooltipHTML, $tooltipTitle, 400, null, null, null, 'data-hascbtooltip="true" data-cbtooltip-modal="true"');
         } else {
             $tooltip = null;
         }
         $connected = '<div class="cbConnectionPaths alert alert-info">' . CBTxt::Th('CONNECTIONS_YOU_ARE_DIRECTLY_CONNECTED_WITH_USER', 'You are directly connected with [user]', array('[user]' => $myAvatar)) . '</div>';
         $requestConnection = '<div class="cbConnectionPaths alert alert-info clearfix">' . '<div class="cbConnPathMessage col-sm-8">' . CBTxt::Th('CONNECTIONS_YOU_HAVE_NO_CONNECTION_WITH_USER', 'You have no established connection with [user]', array('[user]' => $myAvatar)) . '</div>' . '<div class="cbConnPathActions col-sm-4 text-right">' . '<input type="button" value="' . htmlspecialchars(CBTxt::Th('Request Connection')) . '" class="btn btn-success cbConnPathAccept"' . ($tooltip ? ' ' . $tooltip : ' onclick="location.href = \'' . addslashes($addConnURL) . '\';"') . ' />' . '</div>' . '</div>';
         $cancelRequest = '<div class="cbConnectionPaths alert alert-info clearfix">' . '<div class="cbConnPathMessage col-sm-8">' . CBTxt::Th('CONNECTIONS_YOUR_CONNECTION_REQUEST_WITH_USER_IS_PENDING', 'Your connection request with [user] is pending acceptance', array('[user]' => $myAvatar)) . '</div>' . '<div class="cbConnPathActions col-sm-4 text-right">' . '<input type="button" value="' . htmlspecialchars(CBTxt::Th('Cancel Request')) . '" class="btn btn-danger cbConnPathReject" onclick="if ( confirm( \'' . addslashes(CBTxt::T('UE_CONFIRMREMOVECONNECTION', 'Are you sure you want to remove this connection?')) . '\' ) ) { location.href = \'' . addslashes($removeConnURL) . '\'; } else { return false }" />' . '</div>' . '</div>';
         $acceptDenyRequest = '<div class="cbConnectionPaths alert alert-info clearfix">' . '<div class="cbConnPathMessage col-sm-8">' . CBTxt::Th('CONNECTIONS_THE_CONNECTION_WITH_USER_IS_PENDING_YOUR_ACCEPTANCE', 'The connection with [user] is pending your acceptance', array('[user]' => $myAvatar)) . '</div>' . '<div class="cbConnPathActions col-sm-4 text-right">' . '<input type="button" value="' . htmlspecialchars(CBTxt::Th('Accept')) . '" class="btn btn-success cbConnPathAccept" onclick="location.href = \'' . addslashes($acceptConnURL) . '\';" />' . ' <input type="button" value="' . htmlspecialchars(CBTxt::Th('Reject')) . '" class="btn btn-danger cbConnPathReject" onclick="if ( confirm( \'' . addslashes(CBTxt::T('UE_CONFIRMREMOVECONNECTION', 'Are you sure you want to remove this connection?')) . '\' ) ) { location.href = \'' . addslashes($denyConnURL) . '\'; } else { return false }" />' . '</div>' . '</div>';
         $return .= $this->_writeTabDescription($tab, $user);
         if (is_array($conGroups) && count($conGroups) > 2) {
             cbArrayToInts($conGroups);
             $query = "SELECT u.name, u.email, u.username, c.avatar, c.avatarapproved, u.id " . "\n FROM #__comprofiler AS c" . "\n LEFT JOIN #__users AS u ON c.id=u.id" . "\n WHERE c.id IN (" . implode(',', $conGroups) . ")" . "\n AND c.approved=1 AND c.confirmed=1 AND c.banned=0 AND u.block=0";
             $_CB_database->setQuery($query);
             $connections = $_CB_database->loadObjectList('id');
             $prevConID = null;
             $prevConName = null;
             if (isset($connections[$user->id])) {
                 $return .= '<div class="cbConnectionPaths alert alert-info">' . CBTxt::Th('CONNECTIONS_YOUR_CONNECTION_PATH_TO_USER_OF_DEGREE_IS', 'Your connection path to [user] of [degrees] degrees is ', array('[user]' => $myAvatar, '[degrees]' => $cbCon->getDegreeOfSep()));
                 foreach ($conGroups as $conGroup) {
                     $cbUser = CBuser::getInstance((int) $conGroup);
                     if (!$cbUser) {
                         $cbUser = CBuser::getInstance(null);
                     }
                     if ($i != 0) {
                         $return .= ' <span class="fa fa-chevron-right fa-sm"></span> ';
                     }
                     $conName = $cbUser->getField('formatname', null, 'html', 'none', 'profile', 0, true);
                     $conAvatar = $cbUser->getField('avatar', null, 'html', 'none', 'profile', 0, true, array('_hideApproval' => 1));
                     if ($conGroup != $_CB_framework->myId() && isset($connections[$conGroup])) {
                         $conDetail = $cbCon->getConnectionDetails($prevConID, $conGroup);
                         $tipField = getConnectionTab::renderConnectionToolTip($conDetail);
                         $tipField .= '<div style="text-align: center; margin: 8px;">' . $cbUser->getField('avatar', null, 'html', 'none', 'list', 0, true) . '</div>';
                         $tipTitle = $prevConName . CBTxt::T('UE_DETAILSABOUT', ' Details About [PERSON_NAME]', array('[PERSON_NAME]' => htmlspecialchars($conName)));
                         if ($conGroup != $user->id) {
                             $href = $_CB_framework->userProfileUrl((int) $conGroup);
                         } else {
                             $href = null;
                         }
                         $return .= cbTooltip($ui, $tipField, $tipTitle, 300, null, $conAvatar, $href);
                     } else {
                         $return .= $conAvatar;
                     }
                     $i++;
                     $prevConID = $conGroup;
                     $prevConName = $conName;
                 }
                 $return .= '</div>';
                 if ($directConDetails !== false && $directConDetails->pending) {
                     $return .= $cancelRequest;
                 } elseif ($directConDetails !== false && !$directConDetails->accepted) {
                     $return .= $acceptDenyRequest;
                 } elseif ($directConDetails === false) {
                     $return .= $requestConnection;
                 }
             } else {
                 $return .= $requestConnection;
             }
         } elseif (is_array($conGroups) && count($conGroups) == 2) {
             $return .= $connected;
         } else {
             if ($directConDetails !== false && $directConDetails->pending) {
                 $return .= $cancelRequest;
             } elseif ($directConDetails !== false && !$directConDetails->accepted) {
                 $return .= $acceptDenyRequest;
             } else {
                 $return .= $requestConnection;
             }
         }
     }
     return $return;
 }