<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.3 www.exoops.info 2006/03 
// $Id: functions.php,v 1.2 2004/03/20 18:35:12 greyhead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
// Passed on      : My Downloads
// New module name: My Sections
// Version        : 1.1
// Modified by    : Faisal
// Website        : < http://www.a-xoops.com >
// Email          : info@a-xoops.com
// ------------------------------------------------------------------------- //
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function mainheader() {
echo "<div align='left'><b>"._MI_MYSECTIONS_NAME."</b></div><br />";
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function newdownloadgraphic($time, $status) {
global$bcoosConfig;
$count     = 7;
$startdate = ( time() - (86400 * $count) );
if ($startdate < $time) {
        if ($status == 1) {
                echo "&nbsp;<img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."newred.gif' alt='"._NEWTHISWEEK."' /> ";
                } elseif ($status == 2) {
                        echo "&nbsp;<img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."update.gif' alt='"._UPDATEDTHISWEEK."' /> ";
                }
        }
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function popgraphic($counter) {
global $mysectionsConfig,$bcoosConfig;
if ($counter >= $mysectionsConfig['popular']) {
        echo "&nbsp;<img src ='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."pop.gif' alt='"._POPULAR."' />";
        }
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
//Reusable Link Sorting Functions
function convertorderbyin($orderby) {
if ($orderby == "titleA")  { $orderby = "BINARY title ASC";   }
if ($orderby == "dateA")   { $orderby = "date ASC";    }
if ($orderby == "counterA")   { $orderby = "counter ASC";    }
if ($orderby == "ratingA") { $orderby = "rating ASC";  }
if ($orderby == "titleD")  { $orderby = "BINARY title DESC";  }
if ($orderby == "dateD")   { $orderby = "date DESC";   }
if ($orderby == "counterD")   { $orderby = "counter DESC";   }
if ($orderby == "ratingD") { $orderby = "rating DESC"; }
return $orderby;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function convertorderbytrans($orderby) {
if ($orderby == "counter ASC")    { $orderbyTrans = _HITSLEASTMOST; }
if ($orderby == "counter DESC")   { $orderbyTrans = _HITSMOSTLEAST; }
if ($orderby == "BINARY title ASC")   { $orderbyTrans = _TITLEATOZ;      }
if ($orderby == "BINARY title DESC")  { $orderbyTrans = _TITLEZTOA;      }
if ($orderby == "date ASC")    { $orderbyTrans = _OLDDATEFIRST;        }
if ($orderby == "date DESC")   { $orderbyTrans = _NEWDATEFIRST;        }
if ($orderby == "rating ASC")  { $orderbyTrans = _RATINGLOWESTHIGHEST;     }
if ($orderby == "rating DESC") { $orderbyTrans = _RATINGHIGHESTLOWEST;     }
return $orderbyTrans;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function convertorderbyout($orderby) {
if ($orderby == "BINARY title ASC")   { $orderby = "titleA";  }
if ($orderby == "date ASC")    { $orderby = "dateA";   }
if ($orderby == "counter ASC")    { $orderby = "counterA";   }
if ($orderby == "rating ASC")  { $orderby = "ratingA"; }
if ($orderby == "BINARY title DESC")  { $orderby = "titleD";  }
if ($orderby == "date DESC")   { $orderby = "dateD";   }
if ($orderby == "counter DESC")   { $orderby = "counterD";   }
if ($orderby == "rating DESC") { $orderby = "ratingD"; }
return $orderby;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function PrettySize($size) {
$mb = (1024*1024);
if ( $size > $mb ) {
        $mysize = sprintf ("%01.2f", ($size/$mb)) . ""._MD_NUMMB."";
        } elseif ( $size >= 1024 ) {
                $mysize = sprintf ("%01.2f", ($size/1024)) . ""._MD_NUMKB."";
                } else {
                        $mysize = sprintf(_MD_NUMBYTES, $size);
                }
return $mysize;
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
//updates rating data in itemtable for a given item
function updaterating($sel_id) {
global $db;
$sql    = "SELECT rating FROM ".$db->prefix("mysections_votedata")." WHERE lid=".$sel_id."";
$result = $db->query($sql);
$num_votes   = intval($db->getRowsNum($result));
$totalrating = 0;
while (list($rating) = @$db->fetchRow($result)) {
        $totalrating += intval($rating);
}
if ($result) {
        $finalrating = ($totalrating/$num_votes);
        $finalrating = number_format($finalrating, 2);
        } else {
                $finalrating = 0;
        }
$sql = "UPDATE ".$db->prefix("mysections_articles")." SET rating=$finalrating, votes=$num_votes WHERE lid = $sel_id";
$db->query($sql) or print($db->error());
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
//returns the total number of items in items table that are accociated with a given table $table id
function _getTotalItems($sel_id, $status="") {
global $db, $mytree;
$count = 0;
$arr   = array();
$query = "SELECT COUNT(*) FROM ".$db->prefix("mysections_articles")." WHERE cid=".$sel_id."";
if ($status!="") {
        $query .= " AND status>=$status";
}
$result      = $db->query($query);
list($thing) = $db->fetchRow($result);
$count = $thing;
$arr   = $mytree->getAllChildId($sel_id);
$size  = count($arr);
for ($i=0; $i<$size; $i++) {
        $query2 = "SELECT COUNT(*) FROM ".$db->prefix("mysections_articles")." WHERE cid=".$arr[$i]."";
        if ($status != "") {
                $query2 .= " AND status>=$status";
        }
        $result2     = $db->query($query2);
        list($thing) = $db->fetchRow($result2);
        $count += $thing;
}
return $count;
}
//---------------------------------------------------------------------------------------//
/**
* returns the total number of items in table that
* are accociated with a given table $table id
*
* @param type $var description
* @return type description
*/
function getTotalItems($sel_id, $status='') {
global $db, $mytree;
$query = 'SELECT SUM(cid='.intval($sel_id).')';
$arr   = array();
$arr   = $mytree->getAllChildId($sel_id);
$size  = count($arr);
for ($i=0; $i<$size; $i++) {
        $query .= ', SUM(cid='.intval($arr[$i]).')';
}
$query .= ' FROM '.$db->prefix('mysections_articles').'';
if ($status != '') {
        $query .= ' WHERE status >= '.intval($status).'';
}
$result = $db->query($query);
$count  = $db->fetchRow($result);
if (!empty($count)) {
        foreach ($count as $key => $value) {
                $out += $value;
        }
}
return $out;
}
?>