<?php

 function main_url($append=null)
{
    echo "https://mali-mart.com"."/".$append;
}


function notifications()
{
  $ci = &get_instance();

  $query = $ci->db->query("SELECT * from notifications WHERE target = 4 ORDER  by created_at DESC LIMIT 3");
  return $query->result();
}

function notify_count()
{
  $ci = &get_instance();

  $query = $ci->db->query("SELECT count(id) as coun FROM `notifications` WHERE viewed = 0 AND target = 4");
  $r = $query->result();
  return $r[0]->coun;
}

function total_withdraw_count()
{
  $ci = &get_instance();

  $query = $ci->db->query("SELECT count(id) total_withdraw_request FROM `withdraw` WHERE status=0");
  $r = $query->result();
  return $r[0]->total_withdraw_request;
}

function total_activ_req_count()
{
  $ci = &get_instance();

  $query = $ci->db->query("SELECT count(id) total_req FROM `activation_reqst` WHERE status=2");
  $r = $query->result();
  return $r[0]->total_req;
}
function time_ago($timestamp)
{
  date_default_timezone_set("Asia/Dhaka");
  $time_ago = strtotime($timestamp);
  $current_time = time();
  $time_difference = $current_time - $time_ago;
  $seconds = $time_difference;

  $minutes = round($seconds / 60); // value 60 is seconds  
  $hours = round($seconds / 3600); //value 3600 is 60 minutes * 60 sec  
  $days = round($seconds / 86400); //86400 = 24 * 60 * 60;  
  $weeks = round($seconds / 604800); // 7*24*60*60;  
  $months = round($seconds / 2629440); //((365+365+365+365+366)/5/12)*24*60*60  
  $years = round($seconds / 31553280); //(365+365+365+365+366)/5 * 24 * 60 * 60

  if ($seconds <= 60) {

    return "Just Now";

  } else if ($minutes <= 60) {

    if ($minutes == 1) {

      return "1 min ago";

    } else {

      return "$minutes min ago";

    }

  } else if ($hours <= 24) {

    if ($hours == 1) {

      return "an hr ago";

    } else {

      return "$hours hrs ago";

    }

  } else if ($days <= 7) {

    if ($days == 1) {

      return "yesterday";

    } else {

      return "$days days ago";

    }

  } else if ($weeks <= 4.3) {

    if ($weeks == 1) {

      return "a week ago";

    } else {

      return "$weeks weeks ago";

    }

  } else if ($months <= 12) {

    if ($months == 1) {

      return "a month ago";

    } else {

      return "$months months ago";

    }

  } else {

    if ($years == 1) {

      return "one year ago";

    } else {

      return "$years years ago";

    }
  }
}
