Your IP : 3.15.17.137
<?php
function countMessage($id){
global $db;
$sql = $db->query("SELECT * FROM msg WHERE senderid='$id' AND active='1'");
return $sql->num_rows;
}
function readMessage($uid){
global $db;
$sql = $db->query("UPDATE msg SET active=0 WHERE receiverid='$uid'");
}
function incentive1($uid,$stage,$level){
global $db;
$sql = $db->query("SELECT * FROM incentive WHERE id='$uid' AND stage='$stage' AND level='$level'");
$row = $sql->fetch_assoc();
if($sql->num_rows > 0){
return true;
}
else {
return false;
}
}
function sumStage2Wallet() {
global $db;
$sql = $db->query("SELECT SUM(wallet) as sum FROM user");
$row = $sql->fetch_object();
return $row->sum;
}
function incentive($uid,$stage,$level){
global $db;
$sql = $db->query("SELECT * FROM incentive WHERE id='$uid' AND stage='$stage' AND level='$level'");
$row = $sql->fetch_assoc();
return $row['status'];
}
function bcrypt($pass){
return password_hash($pass,PASSWORD_BCRYPT);
}
function getTotalContribution($id, $savings, $opt = ''){
global $db;
$sql = $opt == ''
? $db->query("SELECT COUNT(*) as total FROM contributedmoney WHERE savings_id = '$savings' AND user_id = '$id'")
: $db->query("SELECT SUM(amount) as total FROM contributedmoney WHERE savings_id = '$savings' AND user_id = '$id'");
$row = $sql->fetch_object();
return $row->total;
}
function checkParticipant($saving, $paid = '') {
global $db;
if($paid == '') {
$sql = $db->query("SELECT * FROM contributionparticipants WHERE savings_id = '$saving' AND status = 1");
return $sql->num_rows;
} else {
$sql = $db->query("SELECT * FROM contributionparticipants WHERE savings_id = '$saving' AND paid = 1 AND status = 1");
return $sql->num_rows;
}
}
function totalShare($savings, $month){
global $db;
$sql = $db->query("SELECT SUM(amount) as sum FROM contributedmoney WHERE savings_id = '$savings' AND month = '$month'");
$row = $sql->fetch_object();
return $row->sum;
}
function getContributionField($savings, $col = ''){
global $db;
$sql = $db->query("SELECT * FROM contributions WHERE id='$savings'");
$row = $sql->fetch_object();
return $col == '' ? $row->title : $row->$col;
}
function checkCovisEconomy($uid){
global $db2;
$sql = $db2->query("SELECT * FROM users WHERE id = '$uid' LIMIT 1");
if($sql->num_rows > 0){
return true;
}
return false;
}
function participated($id, $savings){
global $db;
$sql = $db->query("SELECT * FROM contributionparticipants WHERE user_id = '$id' AND savings_id='$savings'");
if($sql->num_rows > 0)
return true;
else
return false;
}
function getContributionParticipantsField($id, $savings, $col){
global $db;
$sql = $db->query("SELECT * FROM contributionparticipants WHERE user_id = '$id' AND savings_id='$savings'");
$row = $sql->fetch_object();
return $row->$col;
}
function activeParticipant($id){
global $db;
$sql = $db->query("SELECT * FROM contributionparticipants WHERE savings_id = '$id' AND status = 1");
return $sql->num_rows;
}
function receivedTransfer($uid){
global $db;
$sql = $db->query("SELECT SUM(amount) AS sum FROM transfer WHERE id2='$uid'");
$row = $sql->fetch_assoc();
return $row['sum'];
}
function shaToKey($sn,$col='sn'){
global $db;
$sql = $db->query("SELECT * FROM user WHERE sha1(sn) = '$sn' LIMIT 1");
$row = $sql->fetch_assoc();
$val = $row[$col];
return $val;
}
function get_time_ago($time){
$time_difference = time()-$time;
if($time_difference < 1 ){return "less than 1 second ago";}
$condition = array(12*30*24*60*60 => 'Year',
30*24*60*60 => 'Month',
24*60*60 => 'Day',
60*60 => 'Hour',
60 => 'Second'
);
foreach($condition as $secs => $str){
$d = $time_difference / $secs;
if($d >= 1){
$t = round($d);
return $t.' '.$str.($t> 1?'s':'').' ago';
}
}
}
function totalTransfer($uid){
global $db;
$sql = $db->query("SELECT SUM(amount) AS sum FROM transfer WHERE id='$uid'");
$row = $sql->fetch_assoc();
return $row['sum'];
}
function totalWithdraw($uid){
global $db;
$sql = $db->query("SELECT SUM(amount) AS sum FROM withdraw WHERE id='$uid'");
$row = $sql->fetch_assoc();
return $row['sum'];
}
function IdToSn($id){
global $db;
$sql = $db->query("SELECT * FROM user WHERE id='$id' LIMIT 1");
$row = $sql->fetch_assoc();
$val = $row['sn'];
return $val;
}
function snToName($sn,$col=''){
global $db;
$sql = $db->query("SELECT * FROM user WHERE sn='$sn' LIMIT 1");
$row = $sql->fetch_assoc();
$val = ($col=='')?$row['firstname'].' '.$row['lastname']:$row[$col];
return $val;
}
function userName($id,$col=''){
global $db;
$sql = $db->query("SELECT * FROM user WHERE id ='$id'");
$row = $sql->fetch_assoc();
$val = ($col=='')?$row['firstname'].' '.$row['lastname']:$row[$col];
return $val;
}
function sqL($table){
global $db;
$sql=$db->query("SELECT * FROM $table")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqL1x($table,$col,$val){
global $db2;
$sql=$db2->query("SELECT * FROM $table WHERE $col='$val' ")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqLxx($table,$col,$val,$item){
global $db2;
$sql=$db2->query("SELECT * FROM $table WHERE $col='$val' ");
$row = mysqli_fetch_assoc($sql);
return $row[$item];
}
function sqL1($table,$col,$val){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' ")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqLL1($table,$col,$val){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' AND level>1 ")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqL2($table,$col,$val,$col2,$val2){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' AND $col2='$val2' ")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqL3($table,$col,$val,$col2,$val2,$col3,$val3){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' AND $col2='$val2' AND $col3='$val3' ")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqL4($table,$col,$val,$col2,$val2,$col3,$val3,$col4,$val4){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' AND $col2='$val2' AND $col3='$val3' AND $col4='$val4' ")or die(mysqli_error());
return mysqli_num_rows($sql);
}
function sqLx($table,$col,$val,$item){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' ");
$row = mysqli_fetch_assoc($sql);
return $row[$item];
}
function sqLx2($table,$col,$val,$col2,$val2,$item){
global $db;
$sql=$db->query("SELECT * FROM $table WHERE $col='$val' AND $col2='$val2' ");
$row = mysqli_fetch_assoc($sql);
return $row[$item];
}
function sqLx3($table,$col1,$val1,$col2,$val2,$col3,$val3,$item){
global $db;
$sql=$db->query("SELECT * from $table where $col1='$val1' and $col2='$val2' and $col3='$val3' " );
$row = mysqli_fetch_assoc($sql);
return $row[$item];
}
function sqLx4($table,$col1,$val1,$col2,$val2,$col3,$val3,$col4,$val4,$item){
global $db;
$sql=$db->query("SELECT * from $table where $col1='$val1' and $col2='$val2' and $col3='$val3' and $col4='$val4' " );
$row = mysqli_fetch_assoc($sql);
return $row[$item];
}
function sqLx5($table,$col1,$val1,$col2,$val2,$col3,$val3,$col4,$val4,$col5,$val5,$item){
global $db;
$sql=$db->query("SELECT * from $table where $col1='$val1' and $col2='$val2' and $col3='$val3' and $col4='$val4' and $col5='$val5' " )or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
return $row[$item];
}
function snToId($sn){
global $db;
$sql = $db->query("SELECT * FROM user WHERE sn='$sn' LIMIT 1");
$row = $sql->fetch_assoc();
return $row['id'];
}
function stageNo($stage,$level){
global $db;
$sql = $db->query("SELECT * FROM levels WHERE stg='$stage' AND level='$level' LIMIT 1");
$row = $sql->fetch_assoc();
return $row['sn'];
}
function stageName($stage){
$name = '';
if($stage==1){ $name = "STARTER"; }
elseif($stage==2){$name = "SILVER";}
elseif($stage==3){$name = "GOLD";}
elseif($stage==4){$name = "EMERALD";}
elseif($stage==5){$name = "DIAMOND";}
elseif($stage==6){$name = "DOUBLE DIAMOND";}
else {$name = "INFINITY";}
return $name;
}
function colSum($table,$col){
global $db;
$sql=$db->query("SELECT SUM($col) AS value_sum FROM $table ");
$row = mysqli_fetch_assoc($sql);
return $row['value_sum'];
}
function colSum1($table,$col,$cola,$vala){
global $db;
$sql=$db->query("SELECT SUM($col) AS value_sum FROM $table WHERE $cola = '$vala' ");
$row = mysqli_fetch_assoc($sql);
return $row['value_sum'];
}
function colSum2($table,$col,$cola,$vala,$colb,$valb){
global $db;
$sql=$db->query("SELECT SUM($col) AS value_sum FROM $table WHERE $cola = '$vala' AND $colb = '$valb' ");
$row = mysqli_fetch_assoc($sql);
return $row['value_sum'];
}
function colSum3($table,$col,$cola,$vala,$colb,$valb,$colc,$valc){
global $db;
$sql=$db->query("SELECT SUM($col) AS value_sum FROM $table WHERE $cola = '$vala' AND $colb = '$valb' AND $colc = '$valc' ");
$row = mysqli_fetch_assoc($sql);
return $row['value_sum'];
}
function rangeSum($table,$col,$start,$end){
global $db;
$sql=$db->query("SELECT SUM($col) AS value_sum FROM $table WHERE today between '$start' and '$end' ");
$row = mysqli_fetch_assoc($sql);
return number_format($row['value_sum']);
}
function userLog(){
if($_SESSION['user'] != 'admin'){
header("location: logout.php"); }
return;
}
function checkLogin(){
if(!isset($_SESSION['login'])){
header("location: logout.php"); }
elseif($_SESSION['level_id']<1){ header("location: logout.php"); }
elseif($_SESSION['level_id']>9){ header("location: logout.php"); }
return;
}
function modalHead($name,$title){
echo '<div class="modal modal-default fade" id="modal-class">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"> ×</span></button>
<h4 class="modal-title">'.$title.'</h4>
</div>
<div class="modal-body">'; return;
}
function modalFoot($name,$butt){
echo '</div>
<div class="modal-footer">
<button type="button" class="btn btn-'.$name.'" data-dismiss="modal">Close</button>'.$butt.'
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>'; return;
}
////FORMS
function myInput($name,$place,$width=6,$required){
//name is name of form
//place refers to placeholder
$fm = '<div class="col-xs-12 col-sm-12 col-md-'.$width.'" style="padding-bottom:10px" ><input name="'.$name.'" class="form-control" placeholder="'.$place.'" '.$required.' /></div>';
return $fm;
}
function myInputV($name,$place,$width=6,$value){
//name is name of form
//place refers to placeholder
$fm = '<div class="col-xs-12 col-sm-12 col-md-'.$width.'" style="padding-bottom:10px" >'.$place.'
<input name="'.$name.'" id="'.$name.'" class="form-control js-calc" value="'.$value.'" placeholder="'.$place.'" /></div>';
return $fm;
}
function myBtn($bname,$bvalue,$width=12){
//bname refers to botton name
//bvalue refers to botton value
$btn = '<div class="col-xs-12 col-sm-12 col-md-'.$width.'" style="padding-bottom:10px" ><button style="text-align:center; width:100%" type="submit" class="btn btn-primary" name="'.$bname.'">'.$bvalue.'</button></div>';
return $btn;
}
function myBtn2($bname,$bvalue,$width=12){
//bname refers to botton name
//bvalue refers to botton value
$btn = '<div class="col-xs-12 col-sm-12 col-md-'.$width.'" style="padding-bottom:10px" ><button style="text-align:center; width:100%" type="submit" class="btn btn-success" name="'.$bname.'">'.$bvalue.'</button></div>';
return $btn;
}
function myForm($content){
//content is an array of form contents
$postfm = '<form method="post">'. $content . '</form>';
return $postfm;
}
function arrayForm($names,$places){
//names refers to array of names
//places refers to array of placeholders
$names = explode(' ',$names);
$places = explode(' ',$places);
$n = count($names);
$a = 0;
while($a<$n){ $b = $a++;
$input .= '<div style="float:left; padding:10px; width:100%"><input name="'.$names[$b].'" class="form-control" value="" placeholder="'.$places[$b].'" required />';
}
return $input;
}
///// TABLES
function Table($field,$value,$dbtable){
//field is an array that needs to be exploaded
//dbtable is the name of the database table you want to fetch from
//sumoption make a provision for adding a sum row at the end of the
//table and needs to be defined eternally to contain the exact structure of
//the table row containing sum of column fields.
$field = explode(' ',$field);
$value = explode(' ',$value);
$n = count($field);
$a = 0;
$table .= '<table class="table table-hover" id="dataTables-example">
<thead>
<tr>';
while($a<$n){ $b = $a++;
$table .= '<th>'.strtoupper(str_replace("-"," ",$field[$b])).'</th>';
}
$table .= ' </tr>
</thead>
<tbody> ';
//$qu=mysql_query("select * FROM zone ORDER BY zone " )or die(mysql_error());
while($row = sqL($dbtable)){
$table .= '<tr class="odd gradeX">';
$a = 0;
while($a<$n){ $b = $a++;
$table .= '<td class="center">'.$row->$value[$b].' </td>'; }
$table .= '</tr>';
}
$table .= ' </tbody></table>';
return $table;
}
function dTable($head,$body,$sql,$action=0){
$action1 = $action;
$i=0; $x=0;
$n = count($head);
$m = count($body);
$act = $action==0 ? '' : '<th>Action</th>';
$table='<table id="example1" class="table table-bordered table-striped sm">
<thead>
<tr>';
while($i<$n){ $a = $i++;
$table .= '<th>'.$head[$a].'</th>';
}
$table .= $act.'</tr>
</thead>
<tbody>';
while($row = mysqli_fetch_assoc($sql)) {
$action = $action1==0 ? '' : '<td><form method="POST"><button type="submit" name="'.$action1[0].'" class="btn btn-xs btn-primary" value="'.$row[$action1[2]].'">'.$action1[1].'</button></form></td>';
$table .= ' <tr>';
$x=0;
while($x<$m){ $y = $x++;
$b = $row[$body[$y]];
$table .= '<td>'.$b.'</td>';
}
$table .= $action.'</tr>';
}
$table .= '</tbody>
<tfoot>
<tr>';
$i=0;
while($i<$n){ $a = $i++;
$table .= '<th>'.$head[$a].'</th>';
}
$table .= $act.'</tr>
</tfoot>
</table>';
return $table;
}
/*
function getUserLevel($rep){
global $db,$rep,$user_created;
$sql = $db->query("SELECT * FROM admin WHERE sn = '$rep' ");
$row=mysqli_fetch_assoc($sql);
$user_created = $row['created'];
if($row['usertype']==1){$level = 'Ticket Officer';}elseif($row['usertype']==2){$level = 'Administrator';}
return $level;
}
function getUserN($rep){
global $db,$rep,$user_created;
$sql = $db->query("SELECT * FROM admin WHERE sn = '$rep' ");
$row=mysqli_fetch_assoc($sql);
$userN = $row['surname'].' '.$row['othername'];
return $userN;
}
*/
function chkLogin(){
global $db,$userPhoto,$userLevel;
if($_SERVER['SCRIPT_NAME']=='/profile/login.php'){ }
else{
if(!isset($_SESSION['admin']) OR !isset($_SESSION['rep'])){ header('location: ../'); exit; } else{
$user = $_SESSION['rep'];
$sql = $db->query("SELECT * FROM user WHERE sn = '$user' ");
$row=mysqli_fetch_assoc($sql);
$userPhoto = $row['photo'];
$userLevel = $row['usertype'];
if($userLevel < 1){ header('location: ../'); }
elseif($userLevel > 2){ header('location: ../'); } else{}
}
}
return;
}
function adminAccess(){
if($_SESSION['userLevel'] != 2){ session_destroy(); }
return;
}
function checkExtension($end){
$array = array('jpg','jpeg','gif','png');
if(in_array($end,$array)){
return true;
}
else { return false; }
}
function checkSize($image_size){
if($image_size <= 1048576){
return true;
}
else {
return false;
}
}
function sanitize($str){
global $db;
return mysqli_real_escape_string($db, $str);
}
function sendMail($mail_to,$subject,$message){
$email = "admin@covisclubinternational.com";
# email headers.
$headers = "From: Covis Club International <$email>";
# Send the email.
$success = mail($mail_to, $subject, $message, $headers);
return;
}
?>