| 1 | <?php
|
|---|
| 2 | // $Id: functions.php,v 1.1 2004/09/09 05:15:10 onokazu Exp $
|
|---|
| 3 | // ------------------------------------------------------------------------ //
|
|---|
| 4 | // XOOPS - PHP Content Management System //
|
|---|
| 5 | // Copyright (c) 2000 XOOPS.org //
|
|---|
| 6 | // <http://www.xoops.org/> //
|
|---|
| 7 | // ------------------------------------------------------------------------ //
|
|---|
| 8 | // This program is free software; you can redistribute it and/or modify //
|
|---|
| 9 | // it under the terms of the GNU General Public License as published by //
|
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or //
|
|---|
| 11 | // (at your option) any later version. //
|
|---|
| 12 | // //
|
|---|
| 13 | // You may not change or alter any portion of this comment or credits //
|
|---|
| 14 | // of supporting developers from this source code or any supporting //
|
|---|
| 15 | // source code which is considered copyrighted (c) material of the //
|
|---|
| 16 | // original comment or credit authors. //
|
|---|
| 17 | // //
|
|---|
| 18 | // This program is distributed in the hope that it will be useful, //
|
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|---|
| 21 | // GNU General Public License for more details. //
|
|---|
| 22 | // //
|
|---|
| 23 | // You should have received a copy of the GNU General Public License //
|
|---|
| 24 | // along with this program; if not, write to the Free Software //
|
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
|
|---|
| 26 | // ------------------------------------------------------------------------ //
|
|---|
| 27 |
|
|---|
| 28 | function mainheader($mainlink=1) {
|
|---|
| 29 | echo "<br /><br /><p><a href=\"".XOOPS_URL."/modules/mydownloads/index.php\"><img src=\"".XOOPS_URL."/modules/mydownloads/images/logo-en.gif\" border=\"0\" alt\"\" /></a></p><br /><br />";
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | function newdownloadgraphic($time, $status) {
|
|---|
| 33 | $count = 7;
|
|---|
| 34 | $new = '';
|
|---|
| 35 | $startdate = (time()-(86400 * $count));
|
|---|
| 36 | if ($startdate < $time) {
|
|---|
| 37 | if($status==1){
|
|---|
| 38 | $new = " <img src=\"".XOOPS_URL."/modules/mydownloads/images/newred.gif\" alt=\""._MD_NEWTHISWEEK."\" />";
|
|---|
| 39 | }elseif($status==2){
|
|---|
| 40 | $new = " <img src=\"".XOOPS_URL."/modules/mydownloads/images/update.gif\" alt=\""._MD_UPTHISWEEK."\" />";
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 | return $new;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | function popgraphic($hits) {
|
|---|
| 47 | global $xoopsModuleConfig;
|
|---|
| 48 | if ($hits >= $xoopsModuleConfig['popular']) {
|
|---|
| 49 | return " <img src =\"".XOOPS_URL."/modules/mydownloads/images/pop.gif\" alt=\""._MD_POPULAR."\" />";
|
|---|
| 50 | }
|
|---|
| 51 | return '';
|
|---|
| 52 | }
|
|---|
| 53 | //Reusable Link Sorting Functions
|
|---|
| 54 | function convertorderbyin($orderby) {
|
|---|
| 55 | switch (trim($orderby)) {
|
|---|
| 56 | case "titleA":
|
|---|
| 57 | $orderby = "title ASC";
|
|---|
| 58 | break;
|
|---|
| 59 | case "dateA":
|
|---|
| 60 | $orderby = "date ASC";
|
|---|
| 61 | break;
|
|---|
| 62 | case "hitsA":
|
|---|
| 63 | $orderby = "hits ASC";
|
|---|
| 64 | break;
|
|---|
| 65 | case "ratingA":
|
|---|
| 66 | $orderby = "rating ASC";
|
|---|
| 67 | break;
|
|---|
| 68 | case "titleD":
|
|---|
| 69 | $orderby = "title DESC";
|
|---|
| 70 | break;
|
|---|
| 71 | case "hitsD":
|
|---|
| 72 | $orderby = "hits DESC";
|
|---|
| 73 | break;
|
|---|
| 74 | case "ratingD":
|
|---|
| 75 | $orderby = "rating DESC";
|
|---|
| 76 | break;
|
|---|
| 77 | case"dateD":
|
|---|
| 78 | default:
|
|---|
| 79 | $orderby = "date DESC";
|
|---|
| 80 | break;
|
|---|
| 81 | }
|
|---|
| 82 | return $orderby;
|
|---|
| 83 | }
|
|---|
| 84 | function convertorderbytrans($orderby) {
|
|---|
| 85 | if ($orderby == "hits ASC") $orderbyTrans = _MD_POPULARITYLTOM;
|
|---|
| 86 | if ($orderby == "hits DESC") $orderbyTrans = _MD_POPULARITYMTOL;
|
|---|
| 87 | if ($orderby == "title ASC") $orderbyTrans = _MD_TITLEATOZ;
|
|---|
| 88 | if ($orderby == "title DESC") $orderbyTrans = _MD_TITLEZTOA;
|
|---|
| 89 | if ($orderby == "date ASC") $orderbyTrans = _MD_DATEOLD;
|
|---|
| 90 | if ($orderby == "date DESC") $orderbyTrans = _MD_DATENEW;
|
|---|
| 91 | if ($orderby == "rating ASC") $orderbyTrans = _MD_RATINGLTOH;
|
|---|
| 92 | if ($orderby == "rating DESC") $orderbyTrans = _MD_RATINGHTOL;
|
|---|
| 93 | return $orderbyTrans;
|
|---|
| 94 | }
|
|---|
| 95 | function convertorderbyout($orderby) {
|
|---|
| 96 | if ($orderby == "title ASC") $orderby = "titleA";
|
|---|
| 97 | if ($orderby == "date ASC") $orderby = "dateA";
|
|---|
| 98 | if ($orderby == "hits ASC") $orderby = "hitsA";
|
|---|
| 99 | if ($orderby == "rating ASC") $orderby = "ratingA";
|
|---|
| 100 | if ($orderby == "title DESC") $orderby = "titleD";
|
|---|
| 101 | if ($orderby == "date DESC") $orderby = "dateD";
|
|---|
| 102 | if ($orderby == "hits DESC") $orderby = "hitsD";
|
|---|
| 103 | if ($orderby == "rating DESC") $orderby = "ratingD";
|
|---|
| 104 | return $orderby;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | function PrettySize($size) {
|
|---|
| 108 | $mb = 1024*1024;
|
|---|
| 109 | if ( $size > $mb ) {
|
|---|
| 110 | $mysize = sprintf ("%01.2f",$size/$mb) . " MB";
|
|---|
| 111 | }
|
|---|
| 112 | elseif ( $size >= 1024 ) {
|
|---|
| 113 | $mysize = sprintf ("%01.2f",$size/1024) . " KB";
|
|---|
| 114 | }
|
|---|
| 115 | else {
|
|---|
| 116 | $mysize = sprintf(_MD_NUMBYTES,$size);
|
|---|
| 117 | }
|
|---|
| 118 | return $mysize;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | //updates rating data in itemtable for a given item
|
|---|
| 122 | function updaterating($sel_id){
|
|---|
| 123 | global $xoopsDB;
|
|---|
| 124 | $query = "select rating FROM ".$xoopsDB->prefix("mydownloads_votedata")." WHERE lid = ".$sel_id."";
|
|---|
| 125 | $voteresult = $xoopsDB->query($query);
|
|---|
| 126 | $votesDB = $xoopsDB->getRowsNum($voteresult);
|
|---|
| 127 | $totalrating = 0;
|
|---|
| 128 | while(list($rating)=$xoopsDB->fetchRow($voteresult)){
|
|---|
| 129 | $totalrating += $rating;
|
|---|
| 130 | }
|
|---|
| 131 | $finalrating = $totalrating/$votesDB;
|
|---|
| 132 | $finalrating = number_format($finalrating, 4);
|
|---|
| 133 | $sql = sprintf("UPDATE %s SET rating = %u, votes = %u WHERE lid = %u", $xoopsDB->prefix("mydownloads_downloads"), $finalrating, $votesDB, $sel_id);
|
|---|
| 134 | $xoopsDB->query($sql);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | //returns the total number of items in items table that are accociated with a given table $table id
|
|---|
| 138 | function getTotalItems($sel_id, $status=""){
|
|---|
| 139 | global $xoopsDB, $mytree;
|
|---|
| 140 | $count = 0;
|
|---|
| 141 | $arr = array();
|
|---|
| 142 | $query = "select count(*) from ".$xoopsDB->prefix("mydownloads_downloads")." where cid=".$sel_id."";
|
|---|
| 143 | if($status!=""){
|
|---|
| 144 | $query .= " and status>=$status";
|
|---|
| 145 | }
|
|---|
| 146 | $result = $xoopsDB->query($query);
|
|---|
| 147 | list($thing) = $xoopsDB->fetchRow($result);
|
|---|
| 148 | $count = $thing;
|
|---|
| 149 | $arr = $mytree->getAllChildId($sel_id);
|
|---|
| 150 | $size = count($arr);
|
|---|
| 151 | for($i=0;$i<$size;$i++){
|
|---|
| 152 | $query2 = "select count(*) from ".$xoopsDB->prefix("mydownloads_downloads")." where cid=".$arr[$i]."";
|
|---|
| 153 | if($status!=""){
|
|---|
| 154 | $query2 .= " and status>=$status";
|
|---|
| 155 | }
|
|---|
| 156 | $result2 = $xoopsDB->query($query2);
|
|---|
| 157 | list($thing) = $xoopsDB->fetchRow($result2);
|
|---|
| 158 | $count += $thing;
|
|---|
| 159 | }
|
|---|
| 160 | return $count;
|
|---|
| 161 | }
|
|---|
| 162 | ?> |
|---|