File: /var/www/html/wp-content/plugins/bsx/inc/camp-overview.php
<?php
function bsx_render_campaign_row($id) {
$c = cc($id);
$kpis = $c['kpis'];
//get and format status
$cstat = getStatus($id);
if($cstat == "n/a") return;
//format status
if($cstat == "Active") {
$statclass="green";
} else if ($cstat == "Closed") {
$statclass="red";
} else if ($cstat == 'Locked' | $cstat == 'Halted') {
$statclass="pink";
} else {
$statclass="grey";
}
// last or close:
if($cstat == 'Active' | $cstat == 'Locked') {
$label = 'Last';
$lcdate = get_date_from_gmt($kpis->cdt);
$lcprc = $kpis->cprc;
} else if($cstat == 'Halted') {
$label = 'Halted';
$lcdate = get_date_from_gmt($kpis->cdt);
$lcprc = $kpis->cprc;
} else if($cstat == 'Closed') {
$label = 'Closed';
$lcdate = get_date_from_gmt($kpis->xdt);
$lcprc = $kpis->xprc;
}
$reg = getRegions($id);
$ct = getTypes($id);
$comp_id = $c['comp_id'];
//company and cssandra objects
$sector = get_field('sector',$comp_id);
$industry = get_field('industry',$comp_id);
$employees = get_field('employees',$comp_id);
$mcap = bsx_format_mcap(get_field('market_cap',$comp_id));
// performance
$cp = $kpis->perf;
$fx = $c['fx'];
// Format performance
$perf_display = '';
$perf_class = '';
if (!empty($cp)) {
$perf_display = sprintf("% 6.1f %%", $cp * 100);
$perf_class = $cp >= 0 ? 'positive' : 'negative';
}
$dif = $c['dif'];
// old data
$dtclass = 'perf-current';
if($cstat == "Closed") {
$dtclass = 'perf-old';
} else {
$a = new DateTimeImmutable($kpis->edt, new DateTimeZone('GMT'));
$b = new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('GMT'));
$diftime = $b->diff($a);
if($diftime->s > 3600) {
$open = date_to_gmt(new DateTime($trd['open_tz']));
$end = date_to_gmt(new DateTime($trd['end_tz']));
$dtclass = current_time() > $open == new DateTime("NOW") < $enddat ? 'perf-old':'perf-current';
}
}
/*
// Initialize the MemberPress user
$current_user = new MeprUser(get_current_user_id());
// Check if user is NOT active on a specific membership (replace 123 with your Membership ID)
// Use $current_user->active_product_subscriptions() to check for ANY active plan
$is_active = $current_user->is_active_on_membership(123);
// Set the class based on status
$container_class = $is_active ? 'premium-content' : 'premium-content blurred-gate';
*/
if(current_user_can('mepr-active','rules:5176')): ?>
<a href="<?php echo get_permalink($id); ?>" class="bsx-campaign-row-link">
<div class="bsx-campaign-row">
<!-- First Row -->
<div class="bsx-row-header">
<div class="bsx-cell bsx-corp"><?php echo esc_attr($c['corp']); ?></div>
<div class="bsx-cell bsx-region">
<?php if (count($reg) > 1) : ?>
<?php echo esc_attr($reg[1]); ?>
<?php endif; ?>
</div>
<div class="bsx-cell bsx-symbol"><?php echo esc_attr($c['sym']); ?></div>
<div class="bsx-date-time-price"><?php echo "Entry:"; ?></div>
<div class="bsx-date-time-price-r"><?php echo esc_attr(get_date_from_gmt($kpis->edt)); ?></div>
<div class="bsx-date-time-price-r"><?php echo sprintf("%8.3f %s",$kpis->eprc,$fx); ?></div>
<div class="bsx-tenure-text"><?php echo "Tenure: "; ?></div>
<div class="bsx-tenure"><?php echo $dif->m . "m " . $dif->d . "d ".$dif->h . "h"; ?></div>
<div class="bsx-cell bsx-source">
<?php echo $c['cs_name']; ?>
</div>
</div>
<!-- Second Row -->
<div class="bsx-row-details">
<div class="bsx-cell bsx-logo">
<?php if (has_post_thumbnail($c['comp'])) : ?>
<?php echo get_the_post_thumbnail($c['comp'], 'medium'); ?>
<?php endif; ?>
</div>
<div class="bsx-cell bsx-status">
<?php if ($cstat) : ?>
<span class = "bsx-status <?php echo esc_attr($statclass); ?>">
<?php echo esc_html($cstat); ?>
</span>
<?php endif; ?>
</div>
<div class="bsx-cell bsx-type">
<?php if ($ct && !is_wp_error($ct)) : ?>
<?php echo esc_attr($ct[0]); ?>
<?php endif; ?>
</div>
<div class="bsx-cell bsx-principle">
<?php if (count($ct) > 1) : ?>
<?php echo esc_attr($ct[1]); ?>
<?php endif; ?>
</div>
<div class="bsx-date-time-price"><?php echo $label; ?></div>
<div class="bsx-perf-last <?php echo esc_attr($dtclass); ?>">
<?php echo esc_attr($lcdate); ?></div>
<div class="bsx-date-time-price-r"><?php echo sprintf("%8.3f %s", $lcprc, $fx); ?></div>
<div class="bsx-cell bsx-performance">
<?php if ($perf_display) : ?>
<span class="bsx-perf-badge <?php echo esc_attr($perf_class); ?>">
<?php echo esc_html($perf_display); ?>
</span>
<?php endif; ?>
</div>
<div class="bsx-cell sl-pic"></div>
<div class="bsx-cell bsx-logo">
<?php if (has_post_thumbnail($c['cass'])) : ?>
<?php echo get_the_post_thumbnail($c['cass'], "medium"); ?>
<?php endif; ?>
</div>
</div>
</div>
</a>
<?php endif;
}