00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: features_boxes.php 5476 2006-02-23 10:46:33Z yeupou $
00006 #
00007 # Copyright 1999-2000 (c) The SourceForge Crew
00008 # Copyright 2000-2003 (c) Free Software Foundation
00009 # Mathieu Roy <yeupou--gnu.org>
00010 #
00011 # Copyright 2004-2006 (c) Mathieu Roy <yeupou--gnu.org>
00012 #
00013 # The Savane project is free software; you can redistribute it and/or
00014 # modify it under the terms of the GNU General Public License
00015 # as published by the Free Software Foundation; either version 2
00016 # of the License, or (at your option) any later version.
00017 #
00018 # The Savane project is distributed in the hope that it will be useful,
00019 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 # GNU General Public License for more details.
00022 #
00023 # You should have received a copy of the GNU General Public License
00024 # along with the Savane project; if not, write to the Free Software
00025 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00026
00027
00028 function show_features_boxes()
00029 {
00030 GLOBAL $HTML;
00031
00032 #### General Stats
00033
00034 $return .= $HTML->box_top(utils_link($GLOBALS['sys_home']."stats/", sprintf(_("%s Statistics"),$GLOBALS['sys_name']),"sortbutton"));
00035
00036 $return .= show_sitestats();
00037 $return .= $HTML->box_bottom();
00038
00039
00040 #### Job offers Stats
00041 $jobs = people_show_category_list();
00042
00043 if ($jobs)
00044 {
00045 $return .= "<br />\n";
00046 $return .= $HTML->box_top(_("Help Wanted"),'',1);
00047 $return .= $jobs;
00048 $return .= $HTML->box_bottom(1);
00049 }
00050
00051
00052 ### Popular items
00053 $votes = show_votes();
00054
00055 if ($votes)
00056 {
00057 $return .= "<br />\n";
00058 $return .= $HTML->box_top(_("Most Popular Items"),'',1);
00059 $return .= $votes;
00060 $return .= $HTML->box_bottom(1);
00061 }
00062
00063
00064 #### Group Type Stats
00065
00066 $result = db_query("SELECT type_id,name FROM group_type ORDER BY type_id");
00067 # try to find out how many latest registered groups per group type
00068 # we should print, depending on how many groups we have.
00069 $limit = 10;
00070 $count = db_numrows($result);
00071 # If count of group types > 25, print 2 latest groups per type
00072 # If count of group types < 2, print 25 latest groups per type
00073 # Else, print (35/count of groups) latest groups per type
00074 if ($count > 25)
00075 { $limit = 2; }
00076 elseif ($count < 2)
00077 { $limit = 25; }
00078 else
00079 {
00080 $limit = round(35 / $count);
00081 }
00082
00083 while ($eachtype = db_fetch_array($result))
00084 {
00085 $return .= "<br />\n";
00086 $return .= $HTML->box_top(sprintf(_("Newest %s Projects"),$eachtype['name']),'',1);
00087 $return .= show_newest_projects($group_type=$eachtype['type_id'], $limit);
00088 global $j;
00089 $return .= '<div class="'.utils_get_alt_row_color($j).'"><span class="smaller"><a href="'.$GLOBALS['sys_home'].'search/?type_of_search=soft&words=%%%&type='.$eachtype['type_id'].'">[';
00090 $return .= sprintf( _("all %s projects"),$eachtype['name'] ) ;
00091 $return .= ']</a></span></div>';
00092 $return .= $HTML->box_bottom(1);
00093 }
00094 return $return;
00095 }
00096
00097
00098 function show_sitestats()
00099 {
00100 $return .= '<span class="smaller">';
00101 $users = stats_getusers();
00102 $return .= sprintf(ngettext("%s registered user", "%s registered users", $users), "<strong>$users</strong>");
00103 $return .= '</span></div>';
00104 $return .= '<div class="'.utils_get_alt_row_color(0).'"><span class="smaller">';
00105 $projects = stats_getprojects_active();
00106 $return .= sprintf(ngettext("%s hosted project", "%s hosted projects", $projects), "<strong>$projects</strong>").'</span></div>';
00107 $result = db_query("SELECT type_id,name FROM group_type ORDER BY type_id");
00108 while ($eachtype = db_fetch_array($result))
00109 {
00110 $i++;
00111 $return .= '<div class="'.utils_get_alt_row_color($i).'"><span class="smaller">';
00112 $return .= ' - <a href="'.$GLOBALS['sys_home'].'search/?type_of_search=soft&words=%%%&type='.$eachtype['type_id'].'" class="center">';
00113 $return .= stats_getprojects_bytype_active($eachtype['type_id']);
00114 $return .= ' '.$eachtype['name'].'</a>';
00115 $return .= '</span></div>';
00116 }
00117 $pending = stats_getprojects_pending();
00118 $return .= '<div class="'.utils_get_alt_row_color(($i+1)).'"><span class="smaller"> ';
00119 $return .= sprintf(ngettext("+ %s registration pending", "+ %s registrations pending", $pending), $pending).'</span>';
00120
00121 return $return;
00122 }
00123
00124 function show_newest_projects($group_type, $limit)
00125 {
00126 global $j;
00127
00128 $sql = "SELECT group_id,unix_group_name,group_name,register_time FROM groups " .
00129 "WHERE is_public=1 AND status='A' AND type=$group_type " .
00130 "ORDER BY register_time DESC LIMIT $limit";
00131 $res_newproj = db_query( $sql );
00132 $sql_type = "SELECT type_id,base_host FROM group_type WHERE type_id=$group_type";
00133 $res_newproj_type = db_query($sql_type);
00134 $row_newproj_type = db_fetch_array($res_newproj_type);
00135 if ($row_newproj_type['base_host'])
00136 {
00137 $base_url = 'http'.(session_issecure()?'s':'').':
00138 }
00139
00140 if (!$res_newproj || db_numrows($res_newproj) < 1)
00141 {
00142 return db_error();
00143 }
00144 else
00145 {
00146 while ( $row_newproj = db_fetch_array($res_newproj) )
00147 {
00148 if ( $row_newproj['register_time'] )
00149 {
00150 # It would be best to have only Month + Day, but php locale
00151 # implementations cant do that, apparently. Feel free to
00152 # improve.
00153 $return .= '<div class="'.utils_get_alt_row_color($j).'"><span class="smaller"> - <a href="'.$base_url.$GLOBALS['sys_home']."projects/$row_newproj[unix_group_name]/\">"
00154 . $row_newproj[group_name].'</a>, '.format_date('minimal',$row_newproj['register_time']).'</span></div>';
00155 $j++;
00156 }
00157 }
00158 }
00159 return $return;
00160 }
00161
00162 function show_votes ($limit=10)
00163 {
00164 # Find out interesting bugs and store them in a hash
00165 # Closed and private items are ignored.
00166 $trackers = array("bugs", "task", "support", "patch");
00167
00168 $item_vote = array();
00169 $item_summary = array();
00170 # not enough space!
00171 #$item_group_id = array();
00172
00173 while (list(,$tracker) = each($trackers))
00174 {
00175 $sql = "SELECT bug_id,group_id,summary,vote FROM $tracker WHERE vote >=35 AND privacy=1 AND status_id=1 ORDER BY vote DESC LIMIT $limit";
00176
00177 $result=db_query($sql);
00178 $rows=db_numrows($result);
00179 if ($result && $rows > 0)
00180 {
00181 $results = 1;
00182 for ($j=0; $j<$rows; $j++)
00183 {
00184
00185 # Create item unique name
00186 $thisitem = $tracker.'#'.db_result($result,$j,'bug_id');
00187
00188 # Store data
00189 $item_vote[$thisitem] = db_result($result,$j,'vote');
00190 $item_summary[$thisitem] = db_result($result,$j,'summary');
00191 # not enough space!
00192 #$item_group_id[$thisitem] = db_result($result,$j,'group_id');
00193
00194 }
00195 }
00196 }
00197
00198 # Break here if we have no results
00199 if (!$results)
00200 { return false; }
00201
00202 # Otherwise, sort items in rank and print the first 10 ones
00203 unset($return, $count);
00204 arsort($item_vote);
00205 foreach ($item_vote as $thisitem => $vote)
00206 {
00207 $count++;
00208 if ($count > $limit)
00209 { break; }
00210
00211 list($tracker, $item_id) = explode("#", $thisitem);
00212 $prefix = utils_get_tracker_prefix($tracker);
00213
00214
00215 # if the summar item is large (>30), only show the first
00216 # 30 characters of the story
00217 if (strlen($item_summary[$thisitem]) > 30)
00218 {
00219 $item_summary[$thisitem] = substr($item_summary[$thisitem], 0, 30);
00220 $item_summary[$thisitem] = substr($item_summary[$thisitem], 0, strrpos($item_summary[$thisitem], ' '));
00221 $item_summary[$thisitem] .= "...";
00222 }
00223
00224 $return .= '<div class="'.utils_get_alt_row_color($count).'">'.
00225 '<span class="smaller"> - '.
00226 '<a href="'.$GLOBALS['sys_home'].$tracker.'/?func=detailitem&item_id='.$item_id.'">'.
00227 $prefix .' #'.$item_id.'</a>'.
00228 _(": ").' '.
00229 '<a href="'.$GLOBALS['sys_home'].$tracker.'/?func=detailitem&item_id='.$item_id.'">'.stripslashes($item_summary[$thisitem]).'</a>,'.
00230 ' '.sprintf(ngettext("%s vote", "%s votes", $vote), $vote).
00231 # not enough space!
00232 #', '.group_getname($item_group_id[$thisitem]).
00233 '</span></div>';
00234
00235 }
00236
00237 return $return;
00238 }
00239
00240
00241 ?>