Initial revision
This commit is contained in:
2
include/.cvsignore
Normal file
2
include/.cvsignore
Normal file
@@ -0,0 +1,2 @@
|
||||
stderr
|
||||
|
||||
58
include/appbyvendor_inc.php
Normal file
58
include/appbyvendor_inc.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
|
||||
function create_appbyvendorsearch_url($vName)
|
||||
{
|
||||
global $fields, $orderby, $join;
|
||||
|
||||
$orderby = "appId";
|
||||
$fields[] = "vendor.vendorId";
|
||||
$fields[] = "appFamily.appId";
|
||||
$fields[] = "appFamily.appName";
|
||||
$fields[] = "appFamily.webPage";
|
||||
$join = "appFamily.vendorId=vendor.vendorId";
|
||||
|
||||
$searchwhat = "vendor.vendorId";
|
||||
|
||||
$url = "stdquery.php";
|
||||
$url .= "?orderby=$orderby";
|
||||
$url .= "&searchfor=$vName";
|
||||
$url .= "&searchwhat=$searchwhat";
|
||||
$url .= "&join=$join";
|
||||
|
||||
foreach($fields as $aField)
|
||||
{
|
||||
$url .= "&fields[]=$aField";
|
||||
}
|
||||
|
||||
$url .= "&linesPerPage=$linesPerPage";
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
function output_appbyvendor_forminputs()
|
||||
{
|
||||
global $fields, $orderby, $join;
|
||||
|
||||
$orderby = "appId";
|
||||
$fields[] = "vendor.vendorId";
|
||||
$fields[] = "appFamily.appId";
|
||||
$fields[] = "appFamily.appName";
|
||||
$fields[] = "appFamily.webPage";
|
||||
$join = "appFamily.vendorId=vendor.vendorId";
|
||||
|
||||
|
||||
$searchwhat = "vendor.vendorName";
|
||||
|
||||
echo "<input TYPE=\"HIDDEN\" NAME=\"orderby\" VALUE=\"$orderby\">
|
||||
<input TYPE=\"HIDDEN\" NAME=\"searchwhat\" VALUE=\"$searchwhat\">";
|
||||
|
||||
foreach($fields as $aField)
|
||||
{
|
||||
echo "<input TYPE=\"HIDDEN\" NAME=\"fields[]\" VALUE=\"$aField\">";
|
||||
}
|
||||
|
||||
echo "<input TYPE=\"HIDDEN\" NAME=\"join\" VALUE=\"$join\">";
|
||||
}
|
||||
|
||||
?>
|
||||
35
include/appdb.php
Normal file
35
include/appdb.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?
|
||||
|
||||
function log_category_visit($catId)
|
||||
{
|
||||
global $REMOTE_ADDR;
|
||||
|
||||
$result = mysql_query("SELECT * FROM catHitStats WHERE ip = '$REMOTE_ADDR' AND catId = $catId");
|
||||
if($result && mysql_num_rows($result) == 1)
|
||||
{
|
||||
$stats = mysql_fetch_object($result);
|
||||
mysql_query("UPDATE catHitStats SET count = count + 1 WHERE catHitId = $stats->catHitId");
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("INSERT INTO catHitStats VALUES(null, null, '$REMOTE_ADDR', $catId, 1)");
|
||||
}
|
||||
}
|
||||
|
||||
function log_application_visit($appId)
|
||||
{
|
||||
global $REMOTE_ADDR;
|
||||
|
||||
$result = mysql_query("SELECT * FROM appHitStats WHERE ip = '$REMOTE_ADDR' AND appId = $appId");
|
||||
if($result && mysql_num_rows($result) == 1)
|
||||
{
|
||||
$stats = mysql_fetch_object($result);
|
||||
mysql_query("UPDATE appHitStats SET count = count + 1 WHERE appHitId = $stats->appHitId");
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("INSERT INTO appHitStats VALUES(null, null, '$REMOTE_ADDR', $appId, 1)");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
78
include/application.php
Normal file
78
include/application.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?
|
||||
|
||||
/* this class represents an application incl. all versions */
|
||||
class Application {
|
||||
|
||||
var $data;
|
||||
|
||||
function Application($id)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appFamily WHERE appId = $id");
|
||||
if(!$result)
|
||||
return; // Oops
|
||||
if(mysql_num_rows($result) != 1)
|
||||
return; // Not found
|
||||
|
||||
$this->data = mysql_fetch_object($result);
|
||||
}
|
||||
|
||||
|
||||
function getAppVersionList()
|
||||
{
|
||||
$list = array();
|
||||
|
||||
$result = mysql_query("SELECT * FROM appVersion ".
|
||||
"WHERE appId = ". $this->data->appId . " " .
|
||||
"ORDER BY versionName");
|
||||
if(!$result)
|
||||
return $list;
|
||||
|
||||
while($row = mysql_fetch_object($result))
|
||||
{
|
||||
if($row->versionName == "NONAME")
|
||||
continue;
|
||||
$list[] = $row;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
function getAppVersion($versionId)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appVersion ".
|
||||
"WHERE appId = ". $this->data->appId ." AND ".
|
||||
"versionId = $versionId");
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return 0;
|
||||
|
||||
return mysql_fetch_object($result);
|
||||
}
|
||||
|
||||
function getVendor()
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM vendor ".
|
||||
"WHERE vendorId = ". $this->data->vendorId);
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return array("vendorName" => "Unknown");
|
||||
|
||||
$vendor = mysql_fetch_object($result);
|
||||
return $vendor;
|
||||
}
|
||||
|
||||
function getComments($versionId = 0)
|
||||
{
|
||||
$list = array();
|
||||
|
||||
$result = mysql_query("SELECT * FROM appComments ".
|
||||
"WHERE appId = ". $this->data->appId . " AND " .
|
||||
"versionId = $versionId " .
|
||||
"ORDER BY time");
|
||||
if(!$result)
|
||||
return $list;
|
||||
|
||||
while($row = mysql_fetch_object($result))
|
||||
$list[] = $row;
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
61
include/appversion_inc.php
Normal file
61
include/appversion_inc.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
|
||||
$fields = "";
|
||||
$join = "";
|
||||
$orderby = "";
|
||||
$searchfor = "";
|
||||
$searchwhat = "";
|
||||
|
||||
|
||||
|
||||
function create_appversionsearch_url($vName)
|
||||
{
|
||||
global $fields, $orderby, $searchwhat, $join;
|
||||
|
||||
$orderby = "appId";
|
||||
$searchwhat = "appVersion.appId";
|
||||
$fields[] = "appVersion.appId";
|
||||
$fields[] = "appVersion.versionId";
|
||||
$fields[] = "appVersion.versionName";
|
||||
|
||||
|
||||
$url = "stdquery.php";
|
||||
$url .= "?orderby=$orderby";
|
||||
$url .= "&searchfor=$vName";
|
||||
$url .= "&searchwhat=$searchwhat";
|
||||
|
||||
foreach($fields as $aField)
|
||||
{
|
||||
$url .= "&fields[]=$aField";
|
||||
}
|
||||
|
||||
$url .= "&join=$join";
|
||||
$url .= "&linesPerPage=$linesPerPage";
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
function output_appversion_forminputs()
|
||||
{
|
||||
global $fields, $orderby, $searchwhat, $join;
|
||||
|
||||
$orderby = "appId";
|
||||
$searchwhat = "appVersion.versionId";
|
||||
$fields[] = "appVersion.appId";
|
||||
$fields[] = "appVersion.versionId";
|
||||
$fields[] = "appVersion.versionName";
|
||||
|
||||
|
||||
echo "<input TYPE=\"HIDDEN\" NAME=\"orderby\" VALUE=\"$orderby\">
|
||||
<input TYPE=\"HIDDEN\" NAME=\"searchwhat\" VALUE=\"$searchwhat\">";
|
||||
|
||||
foreach($fields as $aField)
|
||||
{
|
||||
echo "<input TYPE=\"HIDDEN\" NAME=\"fields[]\" VALUE=\"$aField\">";
|
||||
}
|
||||
|
||||
echo "<input TYPE=\"HIDDEN\" NAME=\"join\" VALUE=\"$join\">";
|
||||
}
|
||||
|
||||
?>
|
||||
55
include/banner.php
Normal file
55
include/banner.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* Banner Ad Library
|
||||
* by Jeremy Newman <jnewman@codeweavers.com>
|
||||
* last modified: 2001.10.08
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Path for Banner Ads
|
||||
*/
|
||||
|
||||
function banner_display ()
|
||||
{
|
||||
// import banner paths from config
|
||||
global $apidb_root;
|
||||
$banner_path_468x60 = $apidb_root."banner/468x60/";
|
||||
$banner_path_xml = $apidb_root."banner/xml/";
|
||||
|
||||
// opening html
|
||||
$banner = "";
|
||||
$banner .= "\n\n".'<!-- START BANNER AD -->'."\n";
|
||||
$banner .= '<div align=center>'."\n";
|
||||
|
||||
// read dir and get list of banners
|
||||
$ads = array();
|
||||
$d = opendir($banner_path_468x60);
|
||||
while($entry = readdir($d))
|
||||
{
|
||||
if(!ereg("(.+)\\.gif$", $entry, $arr))
|
||||
continue; //"
|
||||
array_push($ads, $arr[1]);
|
||||
}
|
||||
closedir($d);
|
||||
|
||||
// randomly select a banner and display it
|
||||
$img = $ads[(rand(1,count($ads))-1)];
|
||||
$url = get_xml_tag($banner_path_xml.$img.'.xml','url');
|
||||
$alt = get_xml_tag($banner_path_xml.$img.'.xml','alt');
|
||||
|
||||
// da banner
|
||||
$banner .= '<a href="'.$url.'">';
|
||||
$banner .= '<img src="'.$banner_path_468x60.$img.'.gif" border=0 width=468 height=60 alt="'.$alt.'">';
|
||||
$banner .= '</a>'."\n";
|
||||
|
||||
// closing html
|
||||
$banner .= '</div>'."\n";
|
||||
$banner .= '<!-- END BANNER AD -->'."\n\n";
|
||||
|
||||
return $banner;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
208
include/category.php
Normal file
208
include/category.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?
|
||||
|
||||
/* this class represents a category + its children */
|
||||
class Category {
|
||||
|
||||
var $name;
|
||||
var $id;
|
||||
var $subcat;
|
||||
|
||||
|
||||
/*
|
||||
* the special name "ROOT" is the top category
|
||||
*/
|
||||
function Category($id = 0)
|
||||
{
|
||||
$this->load($id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* load the category data into this class
|
||||
*/
|
||||
function load($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
if($id == 0)
|
||||
{
|
||||
$this->name = "ROOT";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appCategory WHERE catId = $id");
|
||||
if(!$result) {
|
||||
// category not found!
|
||||
errorpage("Internal Error: Category not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
$ob = mysql_fetch_object($result);
|
||||
$this->name = $ob->catName;
|
||||
}
|
||||
|
||||
$result = mysql_query("SELECT catId, catName, catDescription FROM ".
|
||||
"appCategory WHERE catParent = $this->id " .
|
||||
"ORDER BY catName");
|
||||
if(mysql_num_rows($result) == 0)
|
||||
return; // no sub categories
|
||||
|
||||
$this->subcat = array();
|
||||
while($row = mysql_fetch_object($result))
|
||||
{
|
||||
// Ignore NONAME categories
|
||||
if($row->catName == "NONAME")
|
||||
continue;
|
||||
$this->subcat[$row->catId] = array($row->catName, $row->catDescription);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* resolve the category id by name
|
||||
*/
|
||||
function getCategoryId($name)
|
||||
{
|
||||
if($name == "ROOT")
|
||||
return 0;
|
||||
|
||||
$result = mysql_query("SELECT catId FROM appCategory WHERE ".
|
||||
"catName = '$name'");
|
||||
if(!$result)
|
||||
return -1;
|
||||
if(mysql_num_rows($result) != 1)
|
||||
return -1;
|
||||
$row = mysql_fetch_object($result);
|
||||
return $row->catId;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* returns the list of sub categories
|
||||
*
|
||||
* category list has the following format:
|
||||
*
|
||||
* { { catId => { catName, catDescription } }, ... }
|
||||
*/
|
||||
function getCategoryList()
|
||||
{
|
||||
return $this->subcat;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a path like:
|
||||
*
|
||||
* { ROOT, Games, Simulation }
|
||||
*/
|
||||
function getCategoryPath()
|
||||
{
|
||||
$path = array();
|
||||
$id = $this->id;
|
||||
while(1)
|
||||
{
|
||||
$result = mysql_query("SELECT catName, catId, catParent FROM appCategory WHERE catId = $id");
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
break;
|
||||
$cat = mysql_fetch_object($result);
|
||||
$path[] = array($cat->catId, $cat->catName);
|
||||
$id = $cat->catParent;
|
||||
}
|
||||
$path[] = array(0, "ROOT");
|
||||
return array_reverse($path);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* returns a list of applications in the specified category
|
||||
*/
|
||||
function getAppList($id)
|
||||
{
|
||||
$result = mysql_query("SELECT appId, appName, description FROM ".
|
||||
"appFamily WHERE catId = $id ".
|
||||
"ORDER BY appName");
|
||||
if(!$result || mysql_num_rows($result) == 0)
|
||||
return array();
|
||||
|
||||
$list = array();
|
||||
while($row = mysql_fetch_object($result))
|
||||
{
|
||||
if($row->appName == "NONAME")
|
||||
continue;
|
||||
$list[$row->appId] = array($row->appName, $row->description);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* returns the number of apps in the specified category
|
||||
*/
|
||||
function getAppCount($id, $recurse = 1)
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
$result = mysql_query("SELECT appId FROM appFamily WHERE catId = $id");
|
||||
if($result)
|
||||
$total += mysql_num_rows($result);
|
||||
|
||||
if($recurse)
|
||||
{
|
||||
$result = mysql_query("SELECT catId FROM appCategory WHERE catParent = $id");
|
||||
if($result)
|
||||
{
|
||||
while($ob = mysql_fetch_object($result))
|
||||
$total += $this->getAppCount($ob->catId, 1);
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
};
|
||||
|
||||
function appIdToName($appId)
|
||||
{
|
||||
$result = mysql_query("SELECT appName FROM appFamily WHERE appId = $appId");
|
||||
if(!$result || !mysql_num_rows($result))
|
||||
return "<unknown>"; // shouldn't normally happen
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->appName;
|
||||
}
|
||||
|
||||
function versionIdToName($versionId)
|
||||
{
|
||||
$result = mysql_query("SELECT versionName FROM appVersion WHERE versionId = $versionId");
|
||||
if(!$result || !mysql_num_rows($result))
|
||||
return "<unknown>"; // shouldn't normally happen
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->versionName;
|
||||
}
|
||||
|
||||
// create the Category: line at the top of appdb pages
|
||||
function make_cat_path($path)
|
||||
{
|
||||
global $appId;
|
||||
global $versionId;
|
||||
|
||||
$str = "";
|
||||
$catCount = 0;
|
||||
while(list($idx, list($id, $name)) = each($path))
|
||||
{
|
||||
if($name == "ROOT")
|
||||
$catname = "Main";
|
||||
else
|
||||
$catname = $name;
|
||||
|
||||
if ($catCount > 0) { $str .= " > "; }
|
||||
$str .= html_ahref($catname,"appbrowse.php?catId=$id");
|
||||
$catCount++;
|
||||
}
|
||||
|
||||
if($appId)
|
||||
$str .= " > ".html_ahref(appIdToName($appId),"appview.php?appId=$appId");
|
||||
|
||||
if($versionId)
|
||||
$str .= " > ".html_ahref(versionIdToName($versionId),"appview.php?appId=$appId&versionId=$versionId");
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
?>
|
||||
251
include/comments.php
Normal file
251
include/comments.php
Normal file
@@ -0,0 +1,251 @@
|
||||
<?
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* display a single comment (in $ob)
|
||||
*
|
||||
*/
|
||||
function view_app_comment($ob)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
if ($ob->email)
|
||||
{
|
||||
$mailto = '<a href="mailto:' . $ob->email . '">' . $ob->username . '</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$mailto = $ob->username;
|
||||
}
|
||||
|
||||
echo html_frame_start('','98%');
|
||||
echo '<table width="100%" border=0 cellpadding=2 cellspacing=1">',"\n";
|
||||
|
||||
$ob->subject = stripslashes($ob->subject);
|
||||
$ob->body = stripslashes($ob->body);
|
||||
|
||||
// message header
|
||||
echo "<tr bgcolor=#E0E0E0><td>\n";
|
||||
echo " <b>$ob->subject</b><br>\n";
|
||||
echo " by $mailto on $ob->time<br>\n";
|
||||
echo "</td></tr><tr><td>\n";
|
||||
|
||||
// body
|
||||
echo htmlify_urls($ob->body), "<br><br>\n";
|
||||
|
||||
// only add RE: once
|
||||
if(eregi("RE:", $ob->subject))
|
||||
$subject = $ob->subject;
|
||||
else
|
||||
$subject = "RE: $ob->subject";
|
||||
|
||||
// reply post buttons
|
||||
echo " [<a href='addcomment.php?appId=$ob->appId&versionId=$ob->versionId'><small>post new</small></a>] \n";
|
||||
echo " [<a href='addcomment.php?appId=$ob->appId&versionId=$ob->versionId&subject=".
|
||||
urlencode("$subject")."&thread=$ob->commentId'><small>reply to this</small></a>] \n";
|
||||
|
||||
echo "</td></tr></table>\n";
|
||||
echo html_frame_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* grab comments for appId / versionId
|
||||
* if parentId is not -1 only comments for that thread are returned
|
||||
*/
|
||||
function grab_comments($appId, $versionId, $parentId = -1)
|
||||
{
|
||||
$extra = "";
|
||||
if($parentId != -1)
|
||||
$extra = "AND parentId = $parentId ";
|
||||
|
||||
$qstring = "SELECT from_unixtime(unix_timestamp(time), \"%W %M %D %Y, %k:%i\") as time, ".
|
||||
"commentId, parentId, appId, versionId, username, email, subject, body ".
|
||||
"FROM appComments, user_list WHERE appComments.userId = user_list.userid ".
|
||||
$extra .
|
||||
"AND appId = $appId AND versionId = $versionId ".
|
||||
"ORDER BY appComments.time ASC";
|
||||
|
||||
$result = mysql_query($qstring);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* grab comments for appId / versionId
|
||||
* if parentId is not -1 only comments for that thread are returned
|
||||
*/
|
||||
function count_comments($appId, $versionId)
|
||||
{
|
||||
|
||||
$qstring = "SELECT count(commentId) as hits FROM appComments WHERE appId = $appId AND versionId = $versionId";
|
||||
$result = mysql_query($qstring);
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->hits;
|
||||
}
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* display nested comments
|
||||
*
|
||||
* handle is a db result set
|
||||
*
|
||||
*/
|
||||
function do_display_comments_nested($handle)
|
||||
{
|
||||
while($ob = mysql_fetch_object($handle))
|
||||
{
|
||||
view_app_comment($ob);
|
||||
$result = grab_comments($ob->appId, $ob->versionId, $ob->commentId);
|
||||
if($result && mysql_num_rows($result))
|
||||
{
|
||||
echo "<blockquote>\n";
|
||||
do_display_comments_nested($result);
|
||||
echo "</blockquote>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function display_comments_nested($appId, $versionId, $threadId)
|
||||
{
|
||||
$result = grab_comments($appId, $versionId, $threadId);
|
||||
|
||||
do_display_comments_nested($result);
|
||||
}
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* display threaded comments
|
||||
*
|
||||
* handle is a db result set
|
||||
*
|
||||
*/
|
||||
function do_display_comments_threaded($handle, $is_main)
|
||||
{
|
||||
if(!$is_main)
|
||||
echo "<ul>\n";
|
||||
|
||||
while($ob = mysql_fetch_object($handle))
|
||||
{
|
||||
if($is_main)
|
||||
view_app_comment($ob);
|
||||
else
|
||||
echo "<li> <a href='commentview.php?appId=$ob->appId&versionId=$ob->versionId&threadId=$ob->commentId'> ".
|
||||
" $ob->subject </a> by $ob->username on $ob->time </li>\n";
|
||||
$result = grab_comments($ob->appId, $ob->versionId, $ob->commentId);
|
||||
if($result && mysql_num_rows($result))
|
||||
{
|
||||
echo "<blockquote>\n";
|
||||
do_display_comments_threaded($result, 0);
|
||||
echo "</blockquote>\n";
|
||||
}
|
||||
}
|
||||
if(!$is_main)
|
||||
echo "</ul>\n";
|
||||
}
|
||||
|
||||
function display_comments_threaded($appId, $versionId, $threadId = 0)
|
||||
{
|
||||
$result = grab_comments($appId, $versionId, $threadId);
|
||||
|
||||
do_display_comments_threaded($result, 1);
|
||||
}
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* display flat comments
|
||||
*
|
||||
*/
|
||||
function display_comments_flat($appId, $versionId)
|
||||
{
|
||||
$result = grab_comments($appId, $versionId);
|
||||
|
||||
while($ob = mysql_fetch_object($result))
|
||||
{
|
||||
view_app_comment($ob);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function view_app_comments($appId, $versionId, $threadId = 0)
|
||||
{
|
||||
opendb();
|
||||
|
||||
global $current;
|
||||
global $cmode;
|
||||
|
||||
|
||||
$result = mysql_query("SELECT commentId FROM appComments WHERE appId = $appId AND versionId = $versionId");
|
||||
$messageCount = mysql_num_rows($result);
|
||||
|
||||
|
||||
//start comment format table
|
||||
echo html_frame_start("","98%",'',0);
|
||||
echo '<table width="100%" border=0 cellpadding=1 cellspacing=0">',"\n";
|
||||
|
||||
echo '<tr><td bgcolor=#C0C0C0 align=center><table border=0 cellpadding=0 cellspacing=0><tr bgcolor=#C0C0C0>',"\n";
|
||||
|
||||
// message display mode changer
|
||||
if (loggedin())
|
||||
{
|
||||
//FIXME we need to change this so not logged in users can change current view as well
|
||||
if ($cmode)
|
||||
$current->setpref("comments:mode", $cmode);
|
||||
|
||||
$sel[$current->getpref("comments:mode")] = 'selected';
|
||||
echo '<td><form method=get name=smode action="appview.php">',"\n";
|
||||
echo "<b>Application Comments</b> $messageCount total comments ";
|
||||
echo '<b>Mode</b> <select name="cmode" onchange="document.smode.submit();">',"\n";
|
||||
echo ' <option value=flat '.$sel['flat'].'>Flat</option>',"\n";
|
||||
echo ' <option value=threaded '.$sel['threaded'].'>Threaded</option>',"\n";
|
||||
echo ' <option value=nested '.$sel['nested'].'>Nested</option>',"\n";
|
||||
echo ' <option value=off '.$sel['off'].'>No Comments</option>',"\n";
|
||||
echo '</select><input type=hidden name="appId" value="'.$appId.'">',"\n";
|
||||
echo '<input type=hidden name="versionId" value="'.$versionId.'"></form></td>',"\n";
|
||||
}
|
||||
|
||||
// blank space
|
||||
echo '<td> </td>',"\n";
|
||||
|
||||
// post new message button
|
||||
echo '<td><form method=get name=message action="addcomment.php"><input type=submit value=" post new comment " class=button> ',"\n";
|
||||
echo '<input type=hidden name="appId" value="'.$appId.'"><input type=hidden name="versionId" value="'.$versionId.'"></form></td>',"\n";
|
||||
|
||||
//end comment format table
|
||||
echo '</tr></table></td></tr>',"\n";
|
||||
echo '</table>',"\n";
|
||||
echo html_frame_end("The following comments are owned by whoever posted them. CodeWeavers is not responsible for what they say.");
|
||||
|
||||
//start comments
|
||||
echo '<table width="100%" border=0 cellpadding=2 cellspacing=1"><tr><td>',"\n";
|
||||
|
||||
//hide or display depending on pref
|
||||
if (loggedin())
|
||||
$mode = $current->getpref("comments:mode");
|
||||
else
|
||||
$mode = "flat";
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case "flat":
|
||||
display_comments_flat($appId, $versionId);
|
||||
break;
|
||||
case "nested":
|
||||
display_comments_nested($appId, $versionId, $threadId);
|
||||
break;
|
||||
case "threaded":
|
||||
display_comments_threaded($appId, $versionId, $threadId);
|
||||
break;
|
||||
}
|
||||
|
||||
echo '</td></tr></table>',"\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
27
include/config.php
Normal file
27
include/config.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?
|
||||
/* config file for apidb */
|
||||
|
||||
|
||||
/*
|
||||
* global params
|
||||
*/
|
||||
$apidb_debug = 0; //turns debugging on/off
|
||||
|
||||
/*
|
||||
* api database info
|
||||
*/
|
||||
$apidb_dbuser = "wineowner";
|
||||
$apidb_dbpass = "password";
|
||||
$apidb_dbhost = "localhost";
|
||||
$apidb_db = "winehq_appdb";
|
||||
|
||||
|
||||
/*
|
||||
* user database info
|
||||
*/
|
||||
$userdb_dbuser = "wineowner";
|
||||
$userdb_dbpass = "password";
|
||||
$userdb_dbhost = "localhost";
|
||||
$userdb_db = "winehq_appdb";
|
||||
|
||||
?>
|
||||
35
include/db.php
Normal file
35
include/db.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?
|
||||
|
||||
|
||||
$public_link = null;
|
||||
$private_link = null;
|
||||
|
||||
|
||||
function apidb_query($query)
|
||||
{
|
||||
global $public_link;
|
||||
|
||||
if(!$public_link)
|
||||
{
|
||||
$public_link = mysql_pconnect($db_public_host, $db_public_user, $db_public_pass);
|
||||
mysql_select_db($db_public_db);
|
||||
}
|
||||
|
||||
return mysql_query($query, $public_link);
|
||||
}
|
||||
|
||||
|
||||
function userdb_query($query)
|
||||
{
|
||||
global $private_link;
|
||||
|
||||
if(!$private_link)
|
||||
{
|
||||
$private_link = mysql_pconnect($db_private_host, $db_private_user, $db_private_pass);
|
||||
mysql_select_db($db_private_db);
|
||||
}
|
||||
|
||||
return mysql_query($query, $private_link);
|
||||
}
|
||||
|
||||
?>
|
||||
8
include/footer.php
Normal file
8
include/footer.php
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
<!-- start of footer.inc -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!-- end of footer.inc -->
|
||||
|
||||
41
include/form_edit.php
Normal file
41
include/form_edit.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* Edit Account Form
|
||||
*
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<!-- start of edit account form -->
|
||||
|
||||
<tr>
|
||||
<td> User Name </td>
|
||||
<td> <b> <?=$ext_username?> </b> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Password </td>
|
||||
<td> <input type="password" name="ext_password"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Password (again) </td>
|
||||
<td> <input type="password" name="ext_password2"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Real Name </td>
|
||||
<td> <input type="text" name="ext_realname" value="<?=$ext_realname?>"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Email Address </td>
|
||||
<td> <input type="text" name="ext_email" value="<?=$ext_email?>"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=2> </td>
|
||||
</tr>
|
||||
|
||||
<!-- end of edit account form -->
|
||||
|
||||
<?
|
||||
|
||||
|
||||
?>
|
||||
61
include/form_login.php
Normal file
61
include/form_login.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* Login Form
|
||||
*
|
||||
*/
|
||||
|
||||
echo '<form method="post" name="flogin" action="account.php">',"\n";
|
||||
echo html_frame_start("Login to Application DB","400","",0)
|
||||
|
||||
?>
|
||||
|
||||
<!-- start of login form -->
|
||||
|
||||
<script language="javascript">
|
||||
<!--//
|
||||
function cmd_send_passwd() {
|
||||
document.flogin.cmd.value = "send_passwd";
|
||||
document.flogin.submit();
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
|
||||
<table border="0" width="100%" cellspacing=0 cellpadding="10">
|
||||
<tr>
|
||||
<td class=color1> User Name </td>
|
||||
<td class=color0> <input type="text" name="ext_username" value='<?=$ext_username?>'> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=color1> Password </td>
|
||||
<td class=color0> <input type="password" name="ext_password"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=2 align=center class=color3>
|
||||
<input type="submit" name="login" value=" Login " class=button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- end of login form -->
|
||||
|
||||
<?
|
||||
|
||||
echo html_frame_end(" ");
|
||||
echo '<input type="hidden" name="cmd" value="do_login">',"\n";
|
||||
echo '<input type="hidden" name="ext_referer" value="'.$HTTP_REFERER.'">',"\n";
|
||||
echo '</form>',"\n";
|
||||
|
||||
?>
|
||||
|
||||
<p align=center>Don't have an account yet?<br>
|
||||
[<a href="account.php?cmd=new" onMouseOver="document.status='';return true;">Create a New Account</a>]</p>
|
||||
|
||||
<p align=center>Lost your password?<br>
|
||||
[<a href="javascript:cmd_send_passwd();" onMouseOver="document.status='';return true;">Email a New Password</a>]</p>
|
||||
|
||||
<?
|
||||
|
||||
echo p(),p(),p();
|
||||
|
||||
?>
|
||||
53
include/form_new.php
Normal file
53
include/form_new.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* New Account Form
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
echo '<form method="post" action="account.php">',"\n";
|
||||
echo html_frame_start("Create New Application DB Account","400","",0)
|
||||
|
||||
?>
|
||||
|
||||
<!-- start of new account form -->
|
||||
<table border=0 width="100%" cellspacing=0 cellpadding=20>
|
||||
<tr>
|
||||
<td class=color1> User Name </td>
|
||||
<td class=color0> <input type="text" name="ext_username" value='<?=$ext_username?>'> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=color1> Password </td>
|
||||
<td class=color0> <input type="password" name="ext_password"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=color1> Password (again) </td>
|
||||
<td class=color0> <input type="password" name="ext_password2"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=color1> Real Name </td>
|
||||
<td class=color0> <input type="text" name="ext_realname" value='<?=$ext_realname?>'> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class=color1> Email Address </td>
|
||||
<td class=color0> <input type="text" name="ext_email" value='<?=$ext_email?>'> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan=2 align=center class=color3>
|
||||
<input type="submit" name="create" value=" Create Account " class=button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end of new account form -->
|
||||
|
||||
<?
|
||||
|
||||
echo html_frame_end(" ");
|
||||
echo '<input type="hidden" name="cmd" value="do_new">',"\n";
|
||||
echo '</form>',"\n";
|
||||
|
||||
echo p(),p(),p();
|
||||
|
||||
?>
|
||||
51
include/header.php
Normal file
51
include/header.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* Application Database - Header
|
||||
*
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<!-- start of header.inc -->
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Wine Application DB <?=$title?></title>
|
||||
<meta HTTP-EQUIV="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT">
|
||||
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" href="<?=$apidb_root?>apidb.css" type="text/css">
|
||||
<script language="JavaScript" src="<?=$apidb_root?>scripts.js" type="text/javascript"></script>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#E2E2E2" text="#000000">
|
||||
|
||||
<table width="100%" border=0 cellpadding=0 cellspacing=0>
|
||||
<tr>
|
||||
<td>
|
||||
<table width="100%" border=0 cellpadding=0 cellspacing=0>
|
||||
<tr>
|
||||
<td width="100%"><a href="<?=$apidb_root?>"><img src="<?=$apidb_root?>images/winehq_top_logo.gif" width=300 height=99 border=0 alt="Wine HQ"></a></td>
|
||||
<td>
|
||||
<img src="<?=$apidb_root?>images/blank.gif" border=0 width=10 height=1 alt="">
|
||||
</td>
|
||||
<td width="100%" align="center" valign="middle">
|
||||
<!-- BANNER AD -->
|
||||
<table border=0 cellpadding=1 cellspacing=0>
|
||||
<tr><td valign="middle" align="center" class="black"
|
||||
><?=$banner_ad?></td
|
||||
></tr>
|
||||
</table>
|
||||
<!-- END BANNER AD -->
|
||||
</td>
|
||||
<td>
|
||||
<img src="<?=$apidb_root?>images/blank.gif" border=0 width=10 height=1 alt="">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end of header.inc -->
|
||||
351
include/html.php
Normal file
351
include/html.php
Normal file
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
|
||||
$_indent_level = 0;
|
||||
|
||||
function do_indent($str, $v = 0)
|
||||
{
|
||||
global $_indent_level;
|
||||
|
||||
if($v < 0)
|
||||
$_indent_level += $v;
|
||||
|
||||
if($_indent_level > 0)
|
||||
$str = str_repeat(" ", $_indent_level) . $str;
|
||||
|
||||
if($v > 0)
|
||||
$_indent_level += $v;
|
||||
|
||||
return $str . "\n";
|
||||
}
|
||||
|
||||
function do_html_tr($t, $arr, $class, $extra)
|
||||
{
|
||||
if(strlen($class))
|
||||
$class = " class=\"$class\"";
|
||||
|
||||
$str = do_indent("<tr$class>", 1);
|
||||
for($i = 0; $i < sizeof($arr); $i++)
|
||||
{
|
||||
if(is_array($arr[$i]))
|
||||
{
|
||||
$val = $arr[$i][0];
|
||||
$extra = " ".$arr[$i][1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$val = $arr[$i];
|
||||
$extra = "";
|
||||
}
|
||||
|
||||
if (! $val)
|
||||
{
|
||||
$val = " ";
|
||||
}
|
||||
|
||||
if(stristr($val, "<$t"))
|
||||
{
|
||||
$str .= do_indent($val);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= do_indent("<$t$class$extra> ".trim($val)." </$t>", 0);
|
||||
}
|
||||
}
|
||||
$str .= do_indent("</tr>", -1);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// HTML TH
|
||||
function html_th($arr, $class = "", $extra = "")
|
||||
{
|
||||
return do_html_tr("th", $arr, $class, $extra);
|
||||
}
|
||||
|
||||
// HTML TR
|
||||
function html_tr($arr, $class = "", $extra = "")
|
||||
{
|
||||
return do_html_tr("td", $arr, $class, $extra);
|
||||
}
|
||||
|
||||
// HTML TABLE
|
||||
function html_table_begin($extra = "")
|
||||
{
|
||||
return do_indent("<table $extra>", 1);
|
||||
}
|
||||
|
||||
function html_table_end()
|
||||
{
|
||||
return do_indent("</table>", -1);
|
||||
}
|
||||
|
||||
|
||||
// HTML HTML
|
||||
function html_begin()
|
||||
{
|
||||
return do_indent("<html>", 1);
|
||||
}
|
||||
|
||||
function html_end()
|
||||
{
|
||||
return do_indent("</html>", -1);
|
||||
}
|
||||
|
||||
|
||||
// HTML HEAD
|
||||
function html_head($title, $stylesheet = 0)
|
||||
{
|
||||
$str = do_indent("<head>", 1);
|
||||
$str .= do_indent("<title> $title </title>", 0);
|
||||
if($stylesheet)
|
||||
$str .= do_indent("<link rel=\"stylesheet\" ".
|
||||
"href=\"$stylesheet\" type=\"text/css\">", 0);
|
||||
$str .= do_indent("</head>", -1);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
// HTML BODY
|
||||
function html_body_begin()
|
||||
{
|
||||
return do_indent("<body>", 1);
|
||||
}
|
||||
|
||||
function html_body_end()
|
||||
{
|
||||
return do_indent("</body>", -1);
|
||||
}
|
||||
|
||||
|
||||
// HTML BR
|
||||
function html_br($count = 1)
|
||||
{
|
||||
return do_indent(str_repeat("<br>", $count));
|
||||
}
|
||||
|
||||
// HTML A HREF
|
||||
function html_ahref($label, $url, $extra = "")
|
||||
{
|
||||
$label = stripslashes($label);
|
||||
if (!$label and $url)
|
||||
{
|
||||
return do_indent(" <a href=\"$url\" $extra>$url</a> ");
|
||||
}
|
||||
else if (!$label)
|
||||
{
|
||||
return do_indent(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
return do_indent(" <a href=\"$url\" $extra>$label</a> ");
|
||||
}
|
||||
}
|
||||
|
||||
// HTML echo a string
|
||||
function html_echo($str)
|
||||
{
|
||||
return do_indent($str);
|
||||
}
|
||||
|
||||
// HTML B (bold)
|
||||
function html_b($str)
|
||||
{
|
||||
return do_indent("<b>$str</b>");
|
||||
}
|
||||
|
||||
// HTML SMALL (small text)
|
||||
function html_small($str)
|
||||
{
|
||||
return do_indent("<small>$str</small>");
|
||||
}
|
||||
|
||||
// HTML P
|
||||
function html_p()
|
||||
{
|
||||
return do_indent("<p>");
|
||||
}
|
||||
|
||||
function html_line($thickness = 1, $colspan = 1, $color = "#000000")
|
||||
{
|
||||
return do_indent("<tr><td bgcolor=\"$color\" colspan=$colspan> ".
|
||||
"<img src=\"/images/blank.gif\" height=$thickness ".
|
||||
"vspace=0> </td></tr>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
function html_imagebutton($text, $url, $extra = "")
|
||||
{
|
||||
static $i = 1;
|
||||
|
||||
$i++;
|
||||
$img1 = apidb_url("util/button.php?text=".urlencode($text)."&pressed=0");
|
||||
$img2 = apidb_url("util/button.php?text=".urlencode($text)."&pressed=1");
|
||||
|
||||
$java = "onMouseDown = 'document.img$i.src = \"$img2\"; return true;' ";
|
||||
$java .= "onMouseUp = 'document.img$i.src = \"$img1\"; return true;' ";
|
||||
|
||||
return "\n<a href='$url' $extra $java>\n <img src='$img1' name='img$i' alt='$text' border=0> </a>\n";
|
||||
}
|
||||
|
||||
|
||||
function html_frame_start($title = "", $width = "", $extra = "", $innerPad = 5)
|
||||
{
|
||||
|
||||
global $apidb_root;
|
||||
|
||||
if ($width) { $width = 'width="'.$width.'"'; }
|
||||
|
||||
$str .= '<table '.$width.' border=0 cellpadding=0 cellspacing=0 align=center>'."\n";
|
||||
|
||||
if ($title)
|
||||
{
|
||||
$str .= '
|
||||
<tr><td colspan=3><table width="100%" border=0 cellpadding=0 cellspacing=0>
|
||||
<tr><td>
|
||||
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="topMenu">
|
||||
<tr>
|
||||
<td valign="top" align="left"><img src="'.$apidb_root.'images/winehq_border_top_left.gif" border="0" alt=""></td>
|
||||
<td rowspan="3" valign="middle" align="left"><img src="'.$apidb_root.'images/winehq_border_dot_left.gif" border="0" alt=""></td>
|
||||
<td width="100%" rowspan="3" align="center"><span class="menuTitle">'.$title.'</span></td>
|
||||
<td rowspan="3" valign="middle" align="right"><img src="'.$apidb_root.'images/winehq_border_dot_right.gif" border="0" alt=""></td>
|
||||
<td valign="top" align="left"><img src="'.$apidb_root.'images/winehq_border_top_right.gif" border="0" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="'.$apidb_root.'images/blank.gif" width="1" height="1" border="0" alt=""></td>
|
||||
<td><img src="'.$apidb_root.'images/blank.gif" width="1" height="1" border="0" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="bottom" align="right"><img src="'.$apidb_root.'images/winehq_border_bottom_left.gif" border="0" alt=""></td>
|
||||
<td valign="bottom" align="right"><img src="'.$apidb_root.'images/winehq_border_bottom_right.gif" border="0" alt=""></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table></td></tr>
|
||||
';
|
||||
}
|
||||
|
||||
$str .= '
|
||||
<tr>
|
||||
<td><img src="'.$apidb_root.'images/blank.gif" border=0 width=5 height=1 alt="-"></td>
|
||||
<td width="100%"><table width="100%" border=0 cellpadding=0 cellspacing=0>
|
||||
<tr><td class=topMenu>
|
||||
<table width="100%" border=0 cellpadding="'.$innerPad.'" cellspacing="1" '.$extra.'><tr><td class=white>
|
||||
';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
function html_frame_end($text = "")
|
||||
{
|
||||
global $apidb_root;
|
||||
|
||||
$str = '
|
||||
</td></tr></table></td></tr>
|
||||
</table>
|
||||
</td>
|
||||
<td><img src="'.$apidb_root.'images/blank.gif" border=0 width=5 height=1 alt="-"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
function html_select($name, $values, $default = null, $descs = null)
|
||||
{
|
||||
$str = "<select name='$name'>\n";
|
||||
while(list($idx, $value) = each($values))
|
||||
{
|
||||
$desc = $value;
|
||||
if($descs)
|
||||
$desc = $descs[$idx];
|
||||
|
||||
if($value == $default)
|
||||
$str .= " <option selected value='$value'>$desc\n";
|
||||
else
|
||||
$str .= " <option value='$value'>$desc\n";
|
||||
}
|
||||
$str .= "</select>\n";
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
function html_back_link($howmany = 1, $url = "")
|
||||
{
|
||||
if (!$url)
|
||||
{
|
||||
$url = 'javascript:history.back('.$howmany.');';
|
||||
}
|
||||
return '<p> <a href="'.$url.'"><< Back</a></p>'."\n";
|
||||
}
|
||||
|
||||
|
||||
function p()
|
||||
{
|
||||
return "\n<p> </p>\n";
|
||||
}
|
||||
|
||||
function add_br($text = "")
|
||||
{
|
||||
$text = ereg_replace("\n","<br>\n",$text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
function make_dll_option_list($varname, $dllid = -1)
|
||||
{
|
||||
$db = new ApiDB();
|
||||
|
||||
echo "<select name='$varname'>\n";
|
||||
//echo "<option value='ALL'>ALL\n";
|
||||
$list = $db->get_dll_names();
|
||||
while(list($name, $id) = each($list))
|
||||
{
|
||||
if($dllid == $id)
|
||||
echo "<option value=$id selected>$name ($id)\n";
|
||||
else
|
||||
echo "<option value=$id>$name ($id)\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
}
|
||||
|
||||
|
||||
function make_inx_option_list($varname, $inx = null)
|
||||
{
|
||||
$list = array("yes", "no", "stub", "unknown");
|
||||
echo "<select name='$varname'>\n";
|
||||
while(list($idx, $value) = each($list))
|
||||
{
|
||||
if($value == $inx)
|
||||
echo "<option value=$value selected>$value\n";
|
||||
else
|
||||
echo "<option value=$value>$value\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
function make_quality_option_list($varname, $quality)
|
||||
{
|
||||
$list = array(-1, 1, 2, 3, 4, 5);
|
||||
echo "<select name='$varname'>\n";
|
||||
while(list($idx, $value) = each($list))
|
||||
{
|
||||
if($value == -1)
|
||||
$label = "unknown";
|
||||
else
|
||||
$label = $value;
|
||||
|
||||
if($quality == $value)
|
||||
echo "<option value=$value selected>$label\n";
|
||||
else
|
||||
echo "<option value=$value>$label\n";
|
||||
}
|
||||
echo "</select>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
241
include/incl.php
Normal file
241
include/incl.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* Main Include Library for Application Database
|
||||
*
|
||||
*/
|
||||
|
||||
//set global path
|
||||
global $apidb_root;
|
||||
$apidb_root = BASE;
|
||||
|
||||
//get modules
|
||||
require(BASE."include/"."config.php");
|
||||
require(BASE."include/"."util.php");
|
||||
require(BASE."include/"."user.php");
|
||||
require(BASE."include/"."session.php");
|
||||
require(BASE."include/"."menu.php");
|
||||
require(BASE."include/"."html.php");
|
||||
|
||||
// create arrays
|
||||
$sidebar_func_list = array();
|
||||
$help_list = array();
|
||||
|
||||
// Start session ...
|
||||
apidb_session_start();
|
||||
|
||||
|
||||
function apidb_help_add($desc, $id)
|
||||
{
|
||||
global $help_list;
|
||||
$help_list[] = array($desc, $id);
|
||||
}
|
||||
|
||||
|
||||
//return url with docroot prepended
|
||||
//
|
||||
function apidb_url($path)
|
||||
{
|
||||
global $apidb_root;
|
||||
return $apidb_root.$path;
|
||||
}
|
||||
|
||||
//return FULL url with docroot prepended
|
||||
function apidb_fullurl($path = "")
|
||||
{
|
||||
global $apidb_root;
|
||||
return $apidb_root.$path;
|
||||
}
|
||||
|
||||
function apidb_fullpath($path)
|
||||
{
|
||||
global $apidb_root;
|
||||
global $DOCUMENT_ROOT;
|
||||
return $DOCUMENT_ROOT.$apidb_root.$path;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* output the common apidb header
|
||||
*/
|
||||
function apidb_header($title = 0)
|
||||
{
|
||||
global $apidb_root, $current;
|
||||
|
||||
$username = $current->username;
|
||||
|
||||
// Set Page Title
|
||||
$page_title = $title;
|
||||
if ($title)
|
||||
$title = " - $title";
|
||||
|
||||
// banner ad
|
||||
include(BASE."include/"."banner.php");
|
||||
$banner_ad = banner_display();
|
||||
|
||||
// Display Header
|
||||
include(BASE."include/"."header.php");
|
||||
|
||||
// Display Sidebar
|
||||
echo "<table width='100%' border=0 cellspacing=0 cellpadding=0>\n";
|
||||
echo "<tr valign='top'>\n";
|
||||
echo "<td width=150>\n";
|
||||
apidb_sidebar();
|
||||
echo "</td>\n";
|
||||
echo "<td width='100%'>\n";
|
||||
|
||||
echo html_frame_start($page_title, '98%');
|
||||
|
||||
// Display Status Messages
|
||||
dumpmsgbuffer();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* output the common apidb footer
|
||||
*/
|
||||
function apidb_footer()
|
||||
{
|
||||
global $apidb_root;
|
||||
global $current;
|
||||
|
||||
echo html_frame_end();
|
||||
|
||||
//Close Sidebar and Content Well
|
||||
echo "<br></td>\n";
|
||||
|
||||
// Display Footer
|
||||
if(!$header_disabled)
|
||||
include(BASE."include/"."footer.php");
|
||||
}
|
||||
|
||||
/*
|
||||
* output the sidebar, calls all functions registered with apidb_sidebar_add
|
||||
*/
|
||||
function apidb_sidebar()
|
||||
{
|
||||
global $apidb_root;
|
||||
global $sidebar_func_list;
|
||||
|
||||
//TURN on GLOBAL ADMIN MENU
|
||||
if (havepriv("admin"))
|
||||
{
|
||||
include(BASE."include/"."sidebar_admin.php");
|
||||
apidb_sidebar_add("global_admin_menu");
|
||||
}
|
||||
|
||||
// Login Menu
|
||||
include(BASE."include/"."sidebar_login.php");
|
||||
apidb_sidebar_add("global_sidebar_login");
|
||||
|
||||
// Main Menu
|
||||
include(BASE."include/"."sidebar.php");
|
||||
apidb_sidebar_add("global_sidebar_menu");
|
||||
|
||||
//LOOP and display menus
|
||||
for($i = 0; $i < sizeof($sidebar_func_list); $i++)
|
||||
{
|
||||
$func = $sidebar_func_list[$i];
|
||||
$func();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* register a sidebar menu function
|
||||
* the supplied function is called when the sidebar is built
|
||||
*/
|
||||
function apidb_sidebar_add($funcname)
|
||||
{
|
||||
global $sidebar_func_list;
|
||||
array_unshift($sidebar_func_list, $funcname);
|
||||
}
|
||||
|
||||
|
||||
function apidb_image($name)
|
||||
{
|
||||
global $apidb_root;
|
||||
return $apidb_root."images/$name";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* display an error page
|
||||
*/
|
||||
function errorpage($text = null, $message = null)
|
||||
{
|
||||
if (!$text) {
|
||||
$text = "You must be logged in to perform that operation.";
|
||||
}
|
||||
apidb_header("Oops");
|
||||
echo "<div align=center><font color=red><b>$text</b></font></div>\n";
|
||||
echo "<p>$message</p>\n";
|
||||
apidb_footer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* redirect to $url
|
||||
*/
|
||||
function redirect($url)
|
||||
{
|
||||
header("Location: ".$url);
|
||||
}
|
||||
|
||||
/*
|
||||
* redirect back to referer, or else to the main page
|
||||
*/
|
||||
function redirectref($url = null)
|
||||
{
|
||||
global $HTTP_REFERER;
|
||||
|
||||
if(!$url)
|
||||
$url = $HTTP_REFERER;
|
||||
if(!$url)
|
||||
$url = apidb_fullurl();
|
||||
redirect($url);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* msgs will be displayed on the Next page view of the same user
|
||||
*/
|
||||
function addmsg($text, $color = "black")
|
||||
{
|
||||
global $current;
|
||||
global $PHPSESSID;
|
||||
|
||||
if($color)
|
||||
$text = "<font color='$color'> $text </font>\n";
|
||||
|
||||
$text = str_replace("'", "\\'", $text);
|
||||
mysql_query("INSERT INTO sessionMessages VALUES (null, null, '$PHPSESSID', '$text')");
|
||||
echo mysql_error();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* output msg_buffer and clear it.
|
||||
*/
|
||||
function dumpmsgbuffer()
|
||||
{
|
||||
global $current;
|
||||
global $PHPSESSID;
|
||||
|
||||
$result = mysql_query("SELECT * FROM sessionMessages WHERE sessionId = '$PHPSESSID'");
|
||||
if(!$result)
|
||||
return;
|
||||
|
||||
while($r = mysql_fetch_object($result))
|
||||
{
|
||||
echo html_frame_start("","300","",5);
|
||||
echo "<div align=center> $r->message </div>";
|
||||
echo html_frame_end(" ");
|
||||
echo "<br>\n";
|
||||
}
|
||||
|
||||
mysql_query("DELETE FROM sessionMessages WHERE sessionId = '$PHPSESSID'");
|
||||
}
|
||||
|
||||
?>
|
||||
77
include/menu.php
Normal file
77
include/menu.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?
|
||||
class htmlmenu {
|
||||
|
||||
function htmlmenu($name, $form = null)
|
||||
{
|
||||
global $apidb_root;
|
||||
|
||||
if ($form)
|
||||
echo "<form action='$form' method=get>\n";
|
||||
|
||||
echo '
|
||||
<div align=left>
|
||||
<table width="150" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td colspan=2>
|
||||
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="topMenu">
|
||||
<tr>
|
||||
<td width="100%" rowspan="3" align="left"><span class="menuTitle"> '.$name.'</span></td>
|
||||
<td rowspan="3" valign="middle" align="right"><img src="'.$apidb_root.'images/winehq_border_dot_right.gif" border="0" alt=""></td>
|
||||
<td valign="top" align="left"><img src="'.$apidb_root.'images/winehq_border_top_right.gif" border="0" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="'.$apidb_root.'images/blank.gif" width="1" height="1" border="0" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="bottom" align="right"><img src="'.$apidb_root.'images/winehq_border_bottom_right.gif" border="0" alt=""></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table width="145" border="0" cellspacing="0" cellpadding="1">
|
||||
<tr class="topMenu"><td>
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="5">
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
/* add a table row */
|
||||
function add($name, $url = null)
|
||||
{
|
||||
if($url)
|
||||
{
|
||||
echo " <tr class=sideMenu><td width='100%'><span class=menuItem> <a href='$url' class=menuItem>$name</a></span></td></tr>\n";
|
||||
} else {
|
||||
echo " <tr class=sideMenu><td width='100%'><span class=menuItem> $name</span></td></tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function addmisc($stuff, $align = "left")
|
||||
{
|
||||
echo " <tr class=sideMenu><td width='100%' align=$align><span class=menuItem> $stuff</span></td></tr>\n";
|
||||
}
|
||||
|
||||
function done($form = null)
|
||||
{
|
||||
global $apidb_root;
|
||||
|
||||
echo '
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
<td><img src="'.$apidb_root.'images/blank.gif" border=0 width=5 height=1 alt="-"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<br>
|
||||
';
|
||||
|
||||
if ($form)
|
||||
echo "</form>\n";
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
81
include/parsedate.php
Normal file
81
include/parsedate.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?
|
||||
|
||||
function parsedate($datestr)
|
||||
{
|
||||
$daynames = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday");
|
||||
$monthnames = array("jan" => 1, "feb" => 2, "mar" => 3, "apr" => 4, "may" => 5, "jun" => 6,
|
||||
"jul" => 7, "aug" => 8, "sep" => 9, "oct" => 10, "nov" => 11, "dec" => 12);
|
||||
$ampm = array("am" => 00, "pm" => 12);
|
||||
|
||||
if(!$datestr)
|
||||
return -1;
|
||||
|
||||
$datestr = strtolower($datestr);
|
||||
$datestr = ereg_replace("[,]", "", $datestr);
|
||||
$dp = explode(' ', $datestr);
|
||||
while(list($idx, $part) = each($dp))
|
||||
{
|
||||
//echo "PART($part)<br>";
|
||||
|
||||
/* 23:59:59 */
|
||||
if(ereg("^([0-9]+):([0-9]+):([0-9]+)$", $part, $arr))
|
||||
{
|
||||
$hour = $arr[1];
|
||||
$minute = $arr[2];
|
||||
$second = $arr[3];
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 23:59 */
|
||||
if(ereg("^([0-9]+):([0-9]+)$", $part, $arr))
|
||||
{
|
||||
$hour = $arr[1];
|
||||
$minute = $arr[2];
|
||||
$second = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 2000-12-31 (mysql date format) */
|
||||
if(ereg("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$", $part, $arr))
|
||||
{
|
||||
$year = $arr[1];
|
||||
$month = $arr[2];
|
||||
$day = $arr[3];
|
||||
continue;
|
||||
}
|
||||
|
||||
if(defined($ampm[$part]))
|
||||
{
|
||||
$hour += $ampm[$part];
|
||||
continue;
|
||||
}
|
||||
if($monthnames[substr($part, 0, 3)])
|
||||
{
|
||||
$month = $monthnames[substr($part, 0, 3)];
|
||||
continue;
|
||||
}
|
||||
|
||||
if($part > 1900)
|
||||
{
|
||||
$year = $part;
|
||||
continue;
|
||||
}
|
||||
if($part > 31)
|
||||
{
|
||||
$year = 1900 + $part;
|
||||
continue;
|
||||
}
|
||||
if($part >= 1 && $part <= 31)
|
||||
{
|
||||
$day = $part;
|
||||
continue;
|
||||
}
|
||||
|
||||
//echo "Unparsed: '$part'<br>\n";
|
||||
|
||||
}
|
||||
|
||||
return mktime($hour, $minute, $second, $month, $day, $year);
|
||||
}
|
||||
|
||||
?>
|
||||
76
include/pn_buttons.php
Normal file
76
include/pn_buttons.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* add previous/next buttons
|
||||
*/
|
||||
function add_pn_buttons($vars, $endpos)
|
||||
{
|
||||
extract($vars);
|
||||
|
||||
if($linesPerPage == "ALL")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$curPage = $curPos / $linesPerPage;
|
||||
$numRows = $endpos - $curPos;
|
||||
$numButtons = $totalCount / $linesPerPage;
|
||||
$buttonCount = 1;
|
||||
|
||||
$prev_url = 0;
|
||||
$next_url = 0;
|
||||
|
||||
// define previous/next buttons
|
||||
if($curPos > 0)
|
||||
{
|
||||
$vars["curPos"] = $curPos - $linesPerPage;
|
||||
$prev_url = "stdquery.php?".build_urlarg($vars);
|
||||
}
|
||||
|
||||
if($endpos < $totalCount)
|
||||
{
|
||||
$vars["curPos"] = $curPos + $linesPerPage;
|
||||
$next_url = "stdquery.php?".build_urlarg($vars);
|
||||
}
|
||||
|
||||
// show prev button if nessessary
|
||||
if($prev_url)
|
||||
{
|
||||
echo html_b(html_ahref("<< Prev", $prev_url));
|
||||
}
|
||||
|
||||
// show numbered links
|
||||
if(!$useNextOnly && $endpos <= $totalCount)
|
||||
{
|
||||
while($buttonCount <= $numButtons + 1)
|
||||
{
|
||||
if($curPage == ($buttonCount - 1))
|
||||
{
|
||||
echo html_b("$buttonCount");
|
||||
}
|
||||
else
|
||||
{
|
||||
$vars["curPos"] = ($buttonCount - 1) * $linesPerPage;
|
||||
$url = "stdquery.php?".build_urlarg($vars);
|
||||
echo " ".html_ahref("$buttonCount", $url)." ";
|
||||
}
|
||||
|
||||
if(!($buttonCount % 40))
|
||||
{
|
||||
echo html_p();
|
||||
}
|
||||
$buttonCount++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// show next button if nessessary
|
||||
if($next_url)
|
||||
{
|
||||
echo html_b(html_ahref("Next >>", $next_url));
|
||||
}
|
||||
|
||||
echo "<br>".html_small("listing $numRows record".($numRows == 1 ? "" : "s")." ".($curPos+1)." to $endpos of $totalCount total");
|
||||
}
|
||||
|
||||
?>
|
||||
246
include/qclass.php
Normal file
246
include/qclass.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?
|
||||
// query class
|
||||
// (de)compose/exec queries
|
||||
// this should have query_inc.php's query preprocessing etc.
|
||||
|
||||
class qclass {
|
||||
|
||||
var $fields;
|
||||
var $tables;
|
||||
var $where;
|
||||
var $limit;
|
||||
var $order;
|
||||
|
||||
var $table_ids = array("apimsdefinition" => "apiid",
|
||||
"apimslinks" => "apiid",
|
||||
"dlldefinition" => "dllid",
|
||||
"implementation" => "apiid",
|
||||
"user_list" => "userid",
|
||||
"project_list" => "id",
|
||||
"appFamily" => "appId",
|
||||
"appVersion" => "versionId",
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
function qclass()
|
||||
{
|
||||
$this->clear();
|
||||
}
|
||||
|
||||
|
||||
function clear()
|
||||
{
|
||||
$this->fields = array();
|
||||
$this->tables = array();
|
||||
$this->where = array();
|
||||
$this->limit = 10;
|
||||
$this->order = "";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* resolve used tables from fields
|
||||
*/
|
||||
function resolve_tables($fields)
|
||||
{
|
||||
$tables = array();
|
||||
while(list($idx, $field) = each($fields))
|
||||
{
|
||||
//echo "Field: $field <br>\n";
|
||||
if(!ereg("^(.+)\\.(.+)$", $field, $arr))
|
||||
continue;
|
||||
$tables[$arr[1]] = $arr[1];
|
||||
}
|
||||
return values($tables);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function get_id($table)
|
||||
{
|
||||
$id = $this->table_ids[$table];
|
||||
if($id)
|
||||
return $id;
|
||||
if(ereg("^impl_.*$", $table))
|
||||
return "apiid";
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_rel($table1, $table2)
|
||||
{
|
||||
$id1 = $this->get_id($table1);
|
||||
$id2 = $this->get_id($table2);
|
||||
|
||||
if($id1 == "dllid" && $table2 == "apimsdefinition")
|
||||
return $id1;
|
||||
if($id2 == "dllid" && $table1 == "apimsdefinition")
|
||||
return $id2;
|
||||
|
||||
if($id1 == $id2)
|
||||
return $id1;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolve_where($tables)
|
||||
{
|
||||
$tables = values($tables);
|
||||
$arr = array();
|
||||
$have = array();
|
||||
while(list($idx, $table) = each($tables))
|
||||
{
|
||||
for($i = 0; $i < sizeof($tables); $i++)
|
||||
{
|
||||
//echo "Checking $table - $tables[$i] <br>\n";
|
||||
if($table == $tables[$i])
|
||||
continue;
|
||||
$id = $this->get_rel($table, $tables[$i]);
|
||||
if(!$id)
|
||||
continue;
|
||||
if($have[$id][$table])
|
||||
continue;
|
||||
$have[$id][$table] = 1;
|
||||
$have[$id][$tables[$i]] = 1;
|
||||
$arr[] = "$table.$id = $tables[$i].$id";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
apidb_header();
|
||||
echo "RESULT: ".implode(" AND ", $arr);
|
||||
apidb_footer();
|
||||
exit;
|
||||
*/
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function process($vars)
|
||||
{
|
||||
extract($vars);
|
||||
//var_dump($vars);
|
||||
|
||||
$sfields = $fields;
|
||||
|
||||
if(!$implementations)
|
||||
$implementations = array("wine"); //FIXME
|
||||
|
||||
while(list($idx, $impl) = each($implementations))
|
||||
{
|
||||
|
||||
// Check for quality?
|
||||
if($quality[$idx] && $quality[$idx] != "ALL")
|
||||
{
|
||||
if($quality[$idx] == "UNKNOWN")
|
||||
$this->where[] = "impl_$impl.quality IS NULL";
|
||||
else
|
||||
$this->where[] = "impl_$impl.quality >= $quality[$idx]";
|
||||
$sfields[] = "impl_$impl.quality";
|
||||
}
|
||||
|
||||
// Check for presence?
|
||||
if($presence[$idx] && $presence[$idx] != "ALL")
|
||||
{
|
||||
$this->where[] = "impl_$impl.presence = '$presence[$idx]'";
|
||||
$sfields[] = "impl_$impl.presence";
|
||||
}
|
||||
|
||||
// Check last modified?
|
||||
if($lastmod[$idx] > 0)
|
||||
{
|
||||
$time = time() - ($lastmod[$idx] * 24 * 3600);
|
||||
$this->where[] = "impl_$impl.lastmod > from_unixtime($time)";
|
||||
$sfields[] = "impl_$impl.lastmod";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Search in a specific DLL?
|
||||
if($dllid && $dllid != "ALL")
|
||||
$this->where[] = "dlldefinition.dllid = $dllid";
|
||||
|
||||
// Check for rating? (APPDB)
|
||||
if($rating && $rating != "ANY")
|
||||
{
|
||||
|
||||
$q = "";
|
||||
if($system == "ANY" || $system == "windows")
|
||||
{
|
||||
$q .= " appVersion.rating_windows >= $rating ";
|
||||
$sfields[] = "appVersion.rating_windows";
|
||||
}
|
||||
if($system == "ANY" || $system == "fake")
|
||||
{
|
||||
if($system == "ANY")
|
||||
$q .= " OR ";
|
||||
$q .= " appVersion.rating_fake >= $rating ";
|
||||
$sfields[] = "appVersion.rating_fake";
|
||||
}
|
||||
$this->where[] = "appVersion.appId = appFamily.appId AND ($q)";
|
||||
}
|
||||
|
||||
// Are we searching?
|
||||
if($searchfor)
|
||||
{
|
||||
if(ereg("^[0-9]+$", $searchfor))
|
||||
// exact match if we're searching for a number
|
||||
$this->where[] = "$searchwhat = $searchfor";
|
||||
else
|
||||
// patterns are case insensitive in MySQL
|
||||
$this->where[] = "$searchwhat LIKE '%$searchfor%'";
|
||||
}
|
||||
|
||||
// Must we join?
|
||||
if($join)
|
||||
{
|
||||
$this->where[] = $join;
|
||||
}
|
||||
|
||||
$this->fields = $fields;
|
||||
$this->tables = $this->resolve_tables($sfields);
|
||||
$this->where = array_merge($this->resolve_where($this->tables), $this->where);
|
||||
|
||||
}
|
||||
|
||||
function add_where($str)
|
||||
{
|
||||
$this->where[] = $str;
|
||||
}
|
||||
|
||||
function add_field($field)
|
||||
{
|
||||
$this->fields[] = $field;
|
||||
}
|
||||
|
||||
function add_fields($arr)
|
||||
{
|
||||
$this->fields = array_merge($this->fields, $arr);
|
||||
}
|
||||
|
||||
function resolve()
|
||||
{
|
||||
$this->tables = $this->resolve_tables($this->fields);
|
||||
$this->where = array_merge($this->resolve_where($this->tables), $this->where);
|
||||
}
|
||||
|
||||
|
||||
function get_query()
|
||||
{
|
||||
$query = array();
|
||||
$query[] = "SELECT";
|
||||
$query[] = implode(", ", $this->fields);
|
||||
$query[] = "FROM";
|
||||
$query[] = implode(", ", $this->tables);
|
||||
if(sizeof($this->where))
|
||||
{
|
||||
$query[] = "WHERE";
|
||||
$query[] = implode(" AND ", $this->where);
|
||||
}
|
||||
// add LIMIT etc.
|
||||
|
||||
return implode(" ", $query);
|
||||
}
|
||||
}
|
||||
37
include/query_appbyvendor.php
Normal file
37
include/query_appbyvendor.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<!-- start of App query -->
|
||||
<table border=1 width="100%" cellspacing=0 cellpadding=3 bordercolor=black>
|
||||
<tr>
|
||||
<th class="box-title">Search Apps by Vendor
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="box-body">
|
||||
<form ACTION="stdquery.php" METHOD="get">
|
||||
Vendor Name:
|
||||
<input TYPE="TEXT" NAME="searchfor"> (leave blank to match all)
|
||||
<?
|
||||
include(BASE."include/"."appbyvendor_inc.php");
|
||||
|
||||
output_appbyvendor_forminputs();
|
||||
|
||||
?>
|
||||
<br><br>
|
||||
<input type=checkbox name=verbose value=yes> Verbose query results <br>
|
||||
<? if(havepriv("admin")) echo "<input type=checkbox name=mode value=edit> Edit mode <br>\n"; ?>
|
||||
|
||||
<br>Entries Per Page:
|
||||
<select NAME="linesPerPage">
|
||||
<option>50
|
||||
<option>100
|
||||
<option>150
|
||||
<option>200
|
||||
<option>500
|
||||
<option>ALL
|
||||
</select>
|
||||
<br> <input TYPE="SUBMIT" VALUE="List Apps">
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end of App query -->
|
||||
|
||||
53
include/query_apps.php
Normal file
53
include/query_apps.php
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
<!-- start of App query -->
|
||||
<table border=1 width="100%" cellspacing=0 cellpadding=3 bordercolor=black>
|
||||
<tr>
|
||||
<th class="box-title">Search Apps
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="box-body">
|
||||
<form ACTION="stdquery.php" METHOD="get">
|
||||
<input TYPE="HIDDEN" NAME="orderby" VALUE="appId">
|
||||
App Name:
|
||||
<input TYPE="TEXT" NAME="searchfor"> (leave blank to match all)
|
||||
<input TYPE="HIDDEN" NAME="searchwhat" VALUE="appFamily.appName">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="appFamily.appId">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="appFamily.appName">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="appFamily.webPage">
|
||||
<br><br>
|
||||
<input type=checkbox name=verbose value=yes> Verbose query results <br>
|
||||
<? if(havepriv("admin")) echo "<input type=checkbox name=mode value=edit> Edit mode <br>\n"; ?>
|
||||
|
||||
<br>Rating
|
||||
<select NAME="rating">
|
||||
<option>ANY
|
||||
<option>1
|
||||
<option>2
|
||||
<option>3
|
||||
<option>4
|
||||
<option>5
|
||||
</select> or higher
|
||||
|
||||
<select NAME="system">
|
||||
<option>ANY
|
||||
<option value=windows> Windows
|
||||
<option value=fake> Fake Windows
|
||||
</select>
|
||||
|
||||
<br>Entries Per Page:
|
||||
<select NAME="linesPerPage">
|
||||
<option>50
|
||||
<option>100
|
||||
<option>150
|
||||
<option>200
|
||||
<option>500
|
||||
<option>ALL
|
||||
</select>
|
||||
<br> <input TYPE="SUBMIT" VALUE="List Apps">
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end of App query -->
|
||||
|
||||
189
include/query_inc.php
Normal file
189
include/query_inc.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
|
||||
include(BASE."include/"."appversion_inc.php");
|
||||
include(BASE."include/"."appbyvendor_inc.php");
|
||||
|
||||
function initFields()
|
||||
{
|
||||
global $fields, $orderby, $join, $searchfor, $searchwhat;
|
||||
|
||||
$fields = "";
|
||||
$searchfor = "";
|
||||
$searchwhat = "";
|
||||
$join = "";
|
||||
$orderby = "";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* perform a sql query
|
||||
*/
|
||||
function twinedb_query($query, $vars)
|
||||
{
|
||||
// imports vars into symbol table
|
||||
extract($vars);
|
||||
|
||||
if(debugging())
|
||||
echo "QUERY: $query <p>";
|
||||
|
||||
// Only permit sql SELECT statements
|
||||
if(!eregi("^select .*$", $query))
|
||||
{
|
||||
echo "<b> Invalid SQL Query </b>";
|
||||
echo "<br> $query <br>";
|
||||
return;
|
||||
}
|
||||
|
||||
opendb();
|
||||
|
||||
$tmpq = str_replace("\\", "", $query);
|
||||
|
||||
$endPos=$curPos+$linesPerPage;
|
||||
$tcurpos = $curPos+$startapi;
|
||||
$tendpos = $endPos+$startapi;
|
||||
|
||||
// set a limit if not already set
|
||||
if(!stristr($query, "limit"))
|
||||
$tmpq .= " LIMIT $tcurpos,$linesPerPage";
|
||||
|
||||
// execute the db query
|
||||
$tstamp = time();
|
||||
$result = mysql_query($tmpq);
|
||||
$tstamp = time() - $tstamp;
|
||||
|
||||
if(debugging())
|
||||
echo "<b> QUERY TIME: $tstamp seconds </b><br>\n";
|
||||
|
||||
// query error!
|
||||
if(!$result)
|
||||
{
|
||||
echo "$query <br><br>\n";
|
||||
echo "A QUERY error occurred: ".mysql_error()."\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$numRows = mysql_num_rows($result);
|
||||
$numCols = mysql_num_fields($result);
|
||||
|
||||
$curPage = $curPos/$linesPerPage;
|
||||
$tmendpos = $curPos + $numRows;
|
||||
$explain = "stdquery.php?query=".urlencode("EXPLAIN $tmpq");
|
||||
|
||||
|
||||
echo html_br(2);
|
||||
|
||||
// set $debug to enable query debugging
|
||||
if($debug || stristr($tmpq, "explain"))
|
||||
{
|
||||
$str = eregi_replace("(SELECT|EXPLAIN|DISTINCT|FROM|WHERE|AND".
|
||||
"|OR |IS NULL|IS NOT NULL|LIMIT|ORDER BY".
|
||||
"|GROUP BY)",
|
||||
"<br><b>\\1</b><br>", $tmpq);
|
||||
echo "<br>$str<br>\n";
|
||||
}
|
||||
|
||||
echo html_echo("<div align=center>");
|
||||
|
||||
add_pn_buttons($vars, $tmendpos);
|
||||
echo html_br(2);
|
||||
|
||||
// output table header
|
||||
echo html_table_begin("width='80%' cellspacing=1 border=0 rules=rows frame=hsides");
|
||||
$helems = array();
|
||||
for($k = 0; $k < $numCols; $k++)
|
||||
{
|
||||
$name = mysql_field_name($result, $k);
|
||||
$helems[] = $name;
|
||||
if($name == "apiid")
|
||||
$have_apiid = 1;
|
||||
}
|
||||
echo html_th($helems, "title");
|
||||
|
||||
$curapiid=0;
|
||||
$curName="[NONAME]";
|
||||
|
||||
for($i = 0; $i < $numRows; $i++)
|
||||
{
|
||||
$row = mysql_fetch_array($result, MYSQL_BOTH);
|
||||
$color = ($i % 2);
|
||||
$arr = array();
|
||||
|
||||
for($k = 0; $k < $numCols; $k++)
|
||||
{
|
||||
$fname = mysql_field_name($result, $k);
|
||||
|
||||
|
||||
if($fname == "username")
|
||||
{
|
||||
$username = $row[$k];
|
||||
$userid = $row["userid"];
|
||||
$arr[] = html_ahref($username." ", apidb_url("edituser.php?userid=$userid&username=$username"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if($fname == "vendorName")
|
||||
{
|
||||
initFields();
|
||||
$url = "vendorview.php?vendorId=".$row["vendorId"];
|
||||
$arr[] = html_ahref($row[$k], $url);
|
||||
continue;
|
||||
}
|
||||
|
||||
if($fname == "appName")
|
||||
{
|
||||
initFields();
|
||||
$url = "appview.php?appId=".$row["appId"];
|
||||
$arr[] = html_ahref($row[$k], $url);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if($fname == "versionName")
|
||||
{
|
||||
$versionId = $row["versionId"];
|
||||
$url = "admin/editAppVersion.php?versionId=$versionId";
|
||||
$arr[] = html_ahref($row[$k], $url);
|
||||
continue;
|
||||
}
|
||||
|
||||
if($fname == "webPage")
|
||||
{
|
||||
|
||||
$url = $row[$k];
|
||||
$theLink = "$url";
|
||||
$arr[] = html_ahref($url, $theLink);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(mysql_field_type($result, $k) == "int")
|
||||
{
|
||||
$val = (int)$row[$k];
|
||||
$arr[] = "<div align=right>$val</div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$row[$k])
|
||||
$arr[] = " ";
|
||||
else
|
||||
$arr[] = "$row[$k]";
|
||||
}
|
||||
}
|
||||
|
||||
echo html_tr($arr, "color$color");
|
||||
}
|
||||
|
||||
echo html_table_end();
|
||||
echo html_br();
|
||||
|
||||
add_pn_buttons($vars, $tmendpos);
|
||||
echo html_echo("</div>");
|
||||
|
||||
mysql_free_result($result);
|
||||
closedb();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!-- end of query.php -->
|
||||
59
include/query_users.php
Normal file
59
include/query_users.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* User List
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
echo html_frame_start("List Users","400","",0)
|
||||
|
||||
?>
|
||||
|
||||
<!-- start of users query -->
|
||||
|
||||
<form ACTION="<?=$apidb_root?>stdquery.php" METHOD="get">
|
||||
|
||||
<table width="100%" border=0 cellpadding=0 cellspacing=0>
|
||||
|
||||
<tr>
|
||||
<td class=color1>Pattern</td>
|
||||
<td><input TYPE="TEXT" NAME="searchfor"><br><small>(leave blank to match all)</small></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class=color1>Entries Per Page</td>
|
||||
<td>
|
||||
<select NAME="linesPerPage">
|
||||
<option>100</option>
|
||||
<option>200</option>
|
||||
<option>500</option>
|
||||
<option>ALL</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan=2 class=color3 align=center><input TYPE="SUBMIT" VALUE="List Users" class=button></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<input TYPE="HIDDEN" NAME="orderby" VALUE="userid">
|
||||
<input TYPE="HIDDEN" NAME="searchwhat" VALUE="user_list.username">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="user_list.userid">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="user_list.username">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="user_list.email">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="user_list.realname">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="user_list.created">
|
||||
</form>
|
||||
|
||||
<!-- end of users query -->
|
||||
|
||||
<?
|
||||
|
||||
echo html_frame_end();
|
||||
|
||||
echo p(),p(),p();
|
||||
|
||||
?>
|
||||
37
include/query_vendors.php
Normal file
37
include/query_vendors.php
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
<!-- start of Vendor query -->
|
||||
<table border=1 width="100%" cellspacing=0 cellpadding=3 bordercolor=black>
|
||||
<tr>
|
||||
<th class="box-title">Search Vendors
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="box-body">
|
||||
<form ACTION="stdquery.php" METHOD="get">
|
||||
<input TYPE="HIDDEN" NAME="orderby" VALUE="vendorId">
|
||||
Pattern:
|
||||
<input TYPE="TEXT" NAME="searchfor"> (leave blank to match all)
|
||||
<input TYPE="HIDDEN" NAME="searchwhat" VALUE="vendor.vendorName">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="vendor.vendorId">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="vendor.vendorName">
|
||||
<input TYPE="HIDDEN" NAME="fields[]" VALUE="vendor.vendorURL">
|
||||
<br><br>
|
||||
<input type=checkbox name=verbose value=yes> Verbose query results <br>
|
||||
<? if(havepriv("admin")) echo "<input type=checkbox name=mode value=edit> Edit mode <br>\n"; ?>
|
||||
|
||||
<br>Entries Per Page:
|
||||
<select NAME="linesPerPage">
|
||||
<option>50
|
||||
<option>100
|
||||
<option>150
|
||||
<option>200
|
||||
<option>500
|
||||
<option>ALL
|
||||
</select>
|
||||
<br> <input TYPE="SUBMIT" VALUE="List Vendors">
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- end of Vendor query -->
|
||||
|
||||
210
include/rating.php
Normal file
210
include/rating.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
*
|
||||
* App Compatibility Rating
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function rating_current_for_user($versionId, $system)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!loggedin())
|
||||
return 0;
|
||||
|
||||
$userId = $current->userid;
|
||||
|
||||
$result = mysql_query("SELECT score FROM appRating WHERE versionId = $versionId AND system = '$system' AND userId = $userId");
|
||||
if(!$result)
|
||||
return 0;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->score;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* Display the app(-version) rating menu
|
||||
*
|
||||
*/
|
||||
function rating_menu()
|
||||
{
|
||||
global $versionId;
|
||||
global $apidb_root;
|
||||
|
||||
$s = '<img src="'.$apidb_root.'images/s1.gif" border=0 alt="s1">';
|
||||
$n = '<img src="'.$apidb_root.'images/s0.gif" border=0 alt="s0">';
|
||||
|
||||
$j = new htmlmenu("Compatibility Rating","updaterating.php");
|
||||
|
||||
$r_win = rating_current_for_user($versionId, "windows");
|
||||
$r_fake = rating_current_for_user($versionId, "fake");
|
||||
|
||||
$wchk = array('checked',' ',' ',' ',' ',' ');
|
||||
$fchk = array('checked',' ',' ',' ',' ',' ');
|
||||
|
||||
if($r_win)
|
||||
{
|
||||
$wchk[0] = ' ';
|
||||
$wchk[$r_win] = 'checked';
|
||||
}
|
||||
|
||||
if($r_fake)
|
||||
{
|
||||
$fchk[0] = ' ';
|
||||
$fchk[$r_fake] = 'checked';
|
||||
}
|
||||
|
||||
$j->addmisc("<table width='100%' border=0 cellpadding=2 cellspacing=0><tr align=center valign=top>".
|
||||
"<td width='50%'><small><img src='images/w1.gif' alt='With Windows'> With Windows</small></td>".
|
||||
"<td width='50%'><small><img src='images/w0.gif' alt='Without Windows'> Without Windows</small></td>".
|
||||
"</tr></table>");
|
||||
|
||||
$j->addmisc("<input type=radio name=score_w value='0' ".$wchk[0].">".$n.$n.$n.$n.$n."<input type=radio name=score_f value='0' ".$fchk[0].">","center");
|
||||
$j->addmisc("<input type=radio name=score_w value='1' ".$wchk[1].">".$s.$n.$n.$n.$n."<input type=radio name=score_f value='1' ".$fchk[1].">","center");
|
||||
$j->addmisc("<input type=radio name=score_w value='2' ".$wchk[2].">".$s.$s.$n.$n.$n."<input type=radio name=score_f value='2' ".$fchk[2].">","center");
|
||||
$j->addmisc("<input type=radio name=score_w value='3' ".$wchk[3].">".$s.$s.$s.$n.$n."<input type=radio name=score_f value='3' ".$fchk[3].">","center");
|
||||
$j->addmisc("<input type=radio name=score_w value='4' ".$wchk[4].">".$s.$s.$s.$s.$n."<input type=radio name=score_f value='4' ".$fchk[4].">","center");
|
||||
$j->addmisc("<input type=radio name=score_w value='5' ".$wchk[5].">".$s.$s.$s.$s.$s."<input type=radio name=score_f value='5' ".$fchk[5].">","center");
|
||||
|
||||
|
||||
$j->addmisc("<input type=submit value=' Rate it! ' class=ratebutton>","center");
|
||||
$j->addmisc("<input type=hidden name=versionId value=$versionId>");
|
||||
|
||||
$j->add("Rating Help", $apidb_root."help/?topic=ratings");
|
||||
|
||||
$j->done(1);
|
||||
}
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* returns the avg rating for versionId
|
||||
*
|
||||
*/
|
||||
function rating_for_version($versionId, $system)
|
||||
{
|
||||
$result = mysql_query("SELECT avg(score) as rating, count(id) as hits FROM appRating ".
|
||||
"WHERE versionId = $versionId and system = '$system'");
|
||||
if(!$result)
|
||||
return 0;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob;
|
||||
}
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* returns rating as star images
|
||||
*
|
||||
*/
|
||||
function rating_stars_for_version($versionId, $system)
|
||||
{
|
||||
global $apidb_root;
|
||||
|
||||
$r = rating_for_version($versionId, $system);
|
||||
|
||||
$s = '<img src="'.$apidb_root.'images/s1.gif" border=0 alt="s1">';
|
||||
$n = '<img src="'.$apidb_root.'images/s0.gif" border=0 alt="s0">';
|
||||
$h = '<img src="'.$apidb_root.'images/s2.gif" border=0 alt="s2">';
|
||||
|
||||
if ($system == "fake")
|
||||
{
|
||||
$win_gif = "w0.gif";
|
||||
$alt_desc = "Without Windows";
|
||||
}
|
||||
else
|
||||
{
|
||||
$win_gif = "w1.gif";
|
||||
$alt_desc = "With Windows";
|
||||
}
|
||||
|
||||
if(!$r->rating)
|
||||
{
|
||||
$str = "";
|
||||
for($c = 0; $c < 5; $c++) { $str .= $n; }
|
||||
$str = "<img src='images/$win_gif' alt='$alt_desc'> ".$str." <br><small class=rating>"."unrated"."</small>";
|
||||
return $str;
|
||||
}
|
||||
|
||||
$result = "";
|
||||
for($i = 0; $i < (int)floor($r->rating); $i++)
|
||||
$result .= $s;
|
||||
if(floor($r->rating) < round($r->rating))
|
||||
{
|
||||
$i++;
|
||||
$result .= $h;
|
||||
}
|
||||
for(; $i < 5; $i++)
|
||||
$result .= $n;
|
||||
|
||||
$result = "<img src='images/$win_gif' alt='$alt_desc'> ".$result.
|
||||
" <br><small class=rating>".substr($r->rating,0,4).
|
||||
" (".$r->hits." votes) "."</small>";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* called by /updaterating.php to update the rating table
|
||||
*
|
||||
*/
|
||||
function rating_update($vars)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!loggedin())
|
||||
{
|
||||
// do something, must be logged in
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = $current->userid;
|
||||
$versionId = $vars["versionId"];
|
||||
$score_w = $vars["score_w"];
|
||||
$score_f = $vars["score_f"];
|
||||
|
||||
if($score_w)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appRating WHERE versionId = $versionId AND ".
|
||||
"userId = $userId AND system = 'windows'");
|
||||
if($result && mysql_num_rows($result))
|
||||
{
|
||||
$ob = mysql_fetch_object($result);
|
||||
mysql_query("UPDATE appRating SET score = $score_w WHERE id = $ob->id");
|
||||
}
|
||||
else
|
||||
mysql_query("INSERT INTO appRating VALUES (null, null, $versionId, $userId, 'windows', $score_w)");
|
||||
|
||||
$r = rating_for_version($versionId, "windows");
|
||||
mysql_query("UPDATE appVersion SET rating_windows = $r->rating WHERE versionId = $versionId");
|
||||
}
|
||||
|
||||
if($score_f)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appRating WHERE versionId = $versionId AND ".
|
||||
"userId = $userId AND system = 'fake'");
|
||||
if($result && mysql_num_rows($result))
|
||||
{
|
||||
$ob = mysql_fetch_object($result);
|
||||
mysql_query("UPDATE appRating SET score = $score_f WHERE id = $ob->id");
|
||||
}
|
||||
else
|
||||
mysql_query("INSERT INTO appRating VALUES (null, null, $versionId, $userId, 'fake', $score_f)");
|
||||
|
||||
$r = rating_for_version($versionId, "fake");
|
||||
mysql_query("UPDATE appVersion SET rating_fake = $r->rating WHERE versionId = $versionId");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
113
include/session.php
Normal file
113
include/session.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?
|
||||
|
||||
function apidb_session_start()
|
||||
{
|
||||
global $current;
|
||||
|
||||
session_set_cookie_params(time() + 3600 * 48);
|
||||
session_start();
|
||||
|
||||
if($current)
|
||||
$current->connect();
|
||||
}
|
||||
|
||||
|
||||
function apidb_session_destroy()
|
||||
{
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* session handler functions
|
||||
* sessions are stored in a mysql table
|
||||
*
|
||||
*/
|
||||
|
||||
function _session_open($save_path, $session_name)
|
||||
{
|
||||
opendb();
|
||||
//mysql_query("CREATE TABLE IF NOT EXISTS session_list (session_id varchar(64) not null, ".
|
||||
// "userid int, ip varchar(64), data text, messages text, stamp timestamp, primary key(session_id))");
|
||||
return true;
|
||||
}
|
||||
|
||||
function _session_close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function _session_read($key)
|
||||
{
|
||||
global $msg_buffer;
|
||||
|
||||
opendb();
|
||||
$result = mysql_query("SELECT data, messages FROM session_list WHERE session_id = '$key'");
|
||||
|
||||
if(!$result)
|
||||
return null;
|
||||
$r = mysql_fetch_object($result);
|
||||
|
||||
if($r->messages)
|
||||
$msg_buffer = explode("|", $r->messages);
|
||||
|
||||
return $r->data;
|
||||
}
|
||||
|
||||
function _session_write($key, $value)
|
||||
{
|
||||
global $current;
|
||||
global $msg_buffer;
|
||||
global $apidb_debug;
|
||||
|
||||
opendb();
|
||||
|
||||
|
||||
if($msg_buffer)
|
||||
$messages = implode("|", $msg_buffer);
|
||||
else
|
||||
$messages = "";
|
||||
|
||||
|
||||
// remove single quotes
|
||||
$value = str_replace("'", "", $value);
|
||||
|
||||
|
||||
//DEBUGGING
|
||||
if ($apidb_debug)
|
||||
mysql_query("INSERT INTO debug VALUES(null, '$key = $messages')");
|
||||
|
||||
|
||||
if($current)
|
||||
mysql_query("REPLACE session_list VALUES ('$key', $current->userid, '".get_remote()."', '$value', '$messages', NOW())");
|
||||
else
|
||||
mysql_query("REPLACE session_list VALUES ('$key', 0, '".get_remote()."', null, '$messages', NOW())");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function _session_destroy($key)
|
||||
{
|
||||
mysql_query("DELETE FROM session_list WHERE session_id = '$key'");
|
||||
return true;
|
||||
}
|
||||
|
||||
function _session_gc($maxlifetime)
|
||||
{
|
||||
// delete sessions older than 2 days
|
||||
mysql_query("DELETE FROM session_list WHERE to_days(now()) - to_days(stamp) >= 2");
|
||||
return true;
|
||||
}
|
||||
|
||||
session_set_save_handler("_session_open",
|
||||
"_session_close",
|
||||
"_session_read",
|
||||
"_session_write",
|
||||
"_session_destroy",
|
||||
"_session_gc");
|
||||
|
||||
session_register("current");
|
||||
|
||||
?>
|
||||
41
include/sidebar.php
Normal file
41
include/sidebar.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* SideBar
|
||||
*
|
||||
*/
|
||||
|
||||
function global_sidebar_menu() {
|
||||
|
||||
global $apidb_root, $q;
|
||||
|
||||
$g = new htmlmenu("WineHQ Menu");
|
||||
$g->add("Back to WineHQ", "http://www.winehq.org/");
|
||||
$g->done();
|
||||
|
||||
$g = new htmlmenu("App DB");
|
||||
$g->add("AppDB Home", $apidb_root);
|
||||
$g->add("Browse Apps", $apidb_root."appbrowse.php");
|
||||
$g->add("Top 25", $apidb_root."votestats.php");
|
||||
$g->add("Submit App", $apidb_root."appsubmit.php");
|
||||
$g->add("Documentation", $apidb_root."help/");
|
||||
$g->add("Help & Support", $apidb_root."support.php");
|
||||
$g->done();
|
||||
|
||||
$g = new htmlmenu("Search");
|
||||
$g->addmisc(app_search_box($q));
|
||||
$g->done();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function app_search_box($q = '')
|
||||
{
|
||||
$str .= "<form method=GET action=search.php>\n";
|
||||
$str .= "<input type=text name=q value='$q' size=8 class=searchfield>";
|
||||
$str .= "<input type=submit value='Search' class=searchbutton>\n";
|
||||
$str .= "</form>\n";
|
||||
return $str;
|
||||
}
|
||||
|
||||
?>
|
||||
26
include/sidebar_admin.php
Normal file
26
include/sidebar_admin.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* sidebar_admin
|
||||
*
|
||||
*/
|
||||
|
||||
function global_admin_menu() {
|
||||
|
||||
global $apidb_root;
|
||||
|
||||
$g = new htmlmenu("Global Admin");
|
||||
|
||||
$g->add("Add Category", $apidb_root."admin/addCategory.php");
|
||||
$g->add("Add Application", $apidb_root."admin/addAppFamily.php?catId=0");
|
||||
$g->add("Add Vendor", $apidb_root."admin/addVendor.php");
|
||||
|
||||
$g->addmisc(" ");
|
||||
$g->add("List Users", $apidb_root."admin/");
|
||||
$g->add("View App Queue", $apidb_root."admin/adminAppQueue.php");
|
||||
|
||||
$g->done();
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
28
include/sidebar_login.php
Normal file
28
include/sidebar_login.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* Login SideBar
|
||||
*
|
||||
*/
|
||||
|
||||
function global_sidebar_login() {
|
||||
|
||||
global $apidb_root;
|
||||
|
||||
$g = new htmlmenu("User Menu");
|
||||
|
||||
if(loggedin())
|
||||
{
|
||||
$g->add("Logout", $apidb_root."account.php?cmd=logout");
|
||||
$g->add("Preferences", $apidb_root."preferences.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$g->add("Login", $apidb_root."account.php?cmd=login");
|
||||
}
|
||||
|
||||
$g->done();
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
503
include/tableve.php
Normal file
503
include/tableve.php
Normal file
@@ -0,0 +1,503 @@
|
||||
<?
|
||||
|
||||
require(BASE."include/"."parsedate.php");
|
||||
|
||||
class TableVE {
|
||||
|
||||
var $mode;
|
||||
var $titleField;
|
||||
var $titleText;
|
||||
var $numberedTitles;
|
||||
|
||||
/*
|
||||
* mode can be: view, edit, create
|
||||
*/
|
||||
function TableVE($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
$this->titleField = "";
|
||||
$this->titleText = "";
|
||||
$this->numberedTitles = 0;
|
||||
|
||||
opendb();
|
||||
}
|
||||
|
||||
function test($query)
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
$nfields = mysql_num_fields($result);
|
||||
$nrows = mysql_num_rows($result);
|
||||
$table = mysql_field_table($result, 0);
|
||||
|
||||
echo "Table: $table <br> Fields: $nfields <br> Rows: $nrows <br> <br>\n";
|
||||
|
||||
$i = 0;
|
||||
while($i < $nfields)
|
||||
{
|
||||
$type = mysql_field_type($result, $i);
|
||||
$name = mysql_field_name($result, $i);
|
||||
$len = mysql_field_len($result, $i);
|
||||
$flags = mysql_field_flags($result, $i);
|
||||
|
||||
echo "$type | $name | $len | $flags <br>\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* this is a bit of a hack,
|
||||
* we first create an empty entry, and then simply use the
|
||||
* edit() function to do the rest of the work for us.
|
||||
*/
|
||||
function create($query, $table, $idcolumn)
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
$id = mysql_insert_id();
|
||||
|
||||
$new_query = "SELECT * FROM $table WHERE $idcolumn = $id";
|
||||
$this->edit($new_query);
|
||||
}
|
||||
|
||||
|
||||
function view($query)
|
||||
{
|
||||
//$this->test($query);
|
||||
|
||||
$nrows = 0;
|
||||
|
||||
$result = mysql_query($query);
|
||||
$nrows = mysql_num_rows($result);
|
||||
|
||||
if(debugging())
|
||||
{
|
||||
echo "Query returns $nrows rows.";
|
||||
}
|
||||
|
||||
for($i = 0; $i < $nrows; $i++)
|
||||
{
|
||||
$this->view_entry($result, $i);
|
||||
echo "<br>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function view_entry($result, $num)
|
||||
{
|
||||
$nfields = mysql_num_fields($result);
|
||||
$fields = mysql_fetch_array($result, MYSQL_BOTH);
|
||||
|
||||
$titleValue = $fields[$this->titleField];
|
||||
$titleText = $this->titleText;
|
||||
if($this->numberedTitles)
|
||||
{
|
||||
// don't want zero-based.
|
||||
$num++;
|
||||
$titleText .= " # $num";
|
||||
}
|
||||
|
||||
//echo "<table border=1 bordercolor=black width='80%' cellpadding=0 cellspacing=0>\n";
|
||||
//echo "<th class='box-title' colspan='2'></th></tr>\n";
|
||||
|
||||
//echo "<tr><td>\n";
|
||||
|
||||
echo html_frame_start("Viewing $titleValue $titleText","80%","",0);
|
||||
echo "<table border=0 width='100%' cellspacing=0 cellpadding=2>\n";
|
||||
|
||||
for($i = 0; $i < $nfields; $i++)
|
||||
{
|
||||
$field = mysql_fetch_field($result, $i);
|
||||
|
||||
if(ereg("^impl_(.+)$", $field->table, $arr))
|
||||
{
|
||||
if($cur_impl != $arr[1])
|
||||
echo "<tr><th class='box-label' colspan=2> ".ucfirst($arr[1])." Implementation </th></tr>\n";
|
||||
$cur_impl = $arr[1];
|
||||
}
|
||||
|
||||
echo "<tr><td width='15%' class='box-label'><b> $field->name </b></td>";
|
||||
echo "<td class='box-body'>";
|
||||
$this->view_entry_output_field($field, $fields[$i], 0);
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
|
||||
echo "</table>\n";
|
||||
echo html_frame_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function edit($query)
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
if(!$result)
|
||||
echo "Oops: ".mysql_error()."<br>$query<br>\n";
|
||||
$nrows = mysql_num_rows($result);
|
||||
|
||||
echo "<form method=post action='".apidb_url("editapi.php")."'>\n";
|
||||
|
||||
for($i = 0; $i < $nrows; $i++)
|
||||
{
|
||||
$this->edit_entry($result);
|
||||
echo "<br>\n";
|
||||
}
|
||||
|
||||
echo html_frame_start("Update Database",100);
|
||||
echo "<input type=submit value='Update Database'>\n";
|
||||
echo html_frame_end();
|
||||
|
||||
echo "</form>\n";
|
||||
}
|
||||
|
||||
|
||||
function edit_entry($result)
|
||||
{
|
||||
$nfields = mysql_num_fields($result);
|
||||
$fields = mysql_fetch_array($result);
|
||||
|
||||
echo html_frame_start(ucfirst($this->mode),"80%","",0);
|
||||
echo "<table border=0 width='100%' cellspacing=0 cellpadding=2>\n";
|
||||
|
||||
$cur_impl = null;
|
||||
for($i = 0; $i < $nfields; $i++)
|
||||
{
|
||||
global $testvar;
|
||||
$field = mysql_fetch_field($result, $i);
|
||||
$len = mysql_field_len($result, $i);
|
||||
|
||||
if(ereg("^impl_(.+)$", $field->table, $arr))
|
||||
{
|
||||
if($cur_impl != $arr[1])
|
||||
echo "<tr><th class='box-label' colspan=2> ".ucfirst($arr[1])." Implementation </th></tr>\n";
|
||||
$cur_impl = $arr[1];
|
||||
}
|
||||
|
||||
echo "<tr><td width='15%' class='box-label'><b> $field->name </b></td>";
|
||||
echo "<td class='box-body'> ";
|
||||
$this->edit_entry_output_field($field, $fields[$i], $len);
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
|
||||
echo "</table>\n";
|
||||
echo html_frame_end();
|
||||
}
|
||||
|
||||
function timestamp_to_unix($stamp)
|
||||
{
|
||||
$result = mysql_query("select unix_timestamp($stamp)");
|
||||
if(!$result)
|
||||
return 0;
|
||||
$r = mysql_fetch_row($result);
|
||||
return $r[0];
|
||||
}
|
||||
|
||||
function make_option_list($varname, $cvalue, $table, $idField, $nameField, $where = "")
|
||||
{
|
||||
|
||||
$result = mysql_query("SELECT $idField, $nameField FROM $table $where ORDER BY $nameField");
|
||||
if(!result)
|
||||
return; // Oops
|
||||
|
||||
echo "<select name='$varname'>\n";
|
||||
echo "<option value=0>Choose ...</option>\n";
|
||||
while(list($id, $name) = mysql_fetch_row($result))
|
||||
{
|
||||
if ($name == "NONAME")
|
||||
continue;
|
||||
if($id == $cvalue)
|
||||
echo "<option value=$id selected>$name\n";
|
||||
else
|
||||
echo "<option value=$id>$name\n";
|
||||
|
||||
}
|
||||
echo "</select>\n";
|
||||
}
|
||||
|
||||
|
||||
function edit_entry_output_field($field, $value, $len)
|
||||
{
|
||||
static $idx = 0;
|
||||
|
||||
$idx++;
|
||||
if($len > 50)
|
||||
$len = 50;
|
||||
|
||||
$varname = "FIELD_".$field->table."___".$field->name."[]";
|
||||
echo "<input type=hidden name='TYPE_$varname' value='$field->type'>\n";
|
||||
|
||||
if($field->name == "appId" && $field->table != "appFamily")
|
||||
{
|
||||
$this->make_option_list($varname, $value, "appFamily", "appId", "appName");
|
||||
return;
|
||||
}
|
||||
|
||||
if($field->name == "vendorId" && $field->table != "vendor")
|
||||
{
|
||||
$this->make_option_list($varname, $value, "vendor", "vendorId", "vendorName");
|
||||
return;
|
||||
}
|
||||
|
||||
if($field->name == "catId" && $field->table != "appCategory")
|
||||
{
|
||||
$this->make_option_list($varname, $value, "appCategory", "catId", "catName");
|
||||
return;
|
||||
}
|
||||
|
||||
if($field->name == "catParent")
|
||||
{
|
||||
$this->make_option_list($varname, $value, "appCategory", "catId", "catName");
|
||||
return;
|
||||
}
|
||||
|
||||
if($field->name == "keywords")
|
||||
{
|
||||
echo "<textarea cols=$len rows=3 name='$varname'>".stripslashes($value)."</textarea>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
switch($field->type)
|
||||
{
|
||||
case "string":
|
||||
case "enum":
|
||||
case "int":
|
||||
case "text":
|
||||
echo "<input type=text size=$len name='$varname' value='".stripslashes($value)."'>\n";
|
||||
break;
|
||||
case "blob":
|
||||
echo "<textarea cols=$len rows=10 name='$varname'>".stripslashes($value)."</textarea>\n";
|
||||
break;
|
||||
case "timestamp":
|
||||
$time = $this->timestamp_to_unix($value);
|
||||
echo makedate($time);
|
||||
break;
|
||||
case "datetime":
|
||||
$time = parsedate($value);
|
||||
echo makedate($time);
|
||||
break;
|
||||
default:
|
||||
echo "$value \n";
|
||||
break;
|
||||
}
|
||||
|
||||
$this->entry_add_extra($field, $value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function view_entry_output_field($field, $value, $len)
|
||||
{
|
||||
if($len > 50)
|
||||
$len = 50;
|
||||
|
||||
//FIXME: need a better way for special cases
|
||||
if(!$value && $field->name == "comments")
|
||||
{
|
||||
echo "none";
|
||||
return;
|
||||
}
|
||||
if(!$value && ($field->name == "location" || $field->name == "quality"))
|
||||
{
|
||||
echo "unknown";
|
||||
return;
|
||||
}
|
||||
|
||||
if($field->name == "lastmodby")
|
||||
{
|
||||
$user = new user();
|
||||
$name = $user->lookup_username($value);
|
||||
if(!$name)
|
||||
$name = "system";
|
||||
echo "$name ($value)";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch($field->type)
|
||||
{
|
||||
case "string":
|
||||
case "enum":
|
||||
case "int":
|
||||
case "blob":
|
||||
echo "$value \n";
|
||||
break;
|
||||
case "timestamp":
|
||||
$time = $this->timestamp_to_unix($value);
|
||||
echo makedate($time);
|
||||
break;
|
||||
case "datetime":
|
||||
$time = parsedate($value);
|
||||
echo makedate($time);
|
||||
break;
|
||||
default:
|
||||
echo "$value \n";
|
||||
break;
|
||||
}
|
||||
|
||||
$this->entry_add_extra($field, $value);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* add extra stuff to certain fields
|
||||
*/
|
||||
function entry_add_extra($field, $value)
|
||||
{
|
||||
/*
|
||||
* add extra stuff to certain fields
|
||||
*/
|
||||
|
||||
if($field->name == "mslink" && $value)
|
||||
{
|
||||
echo html_imagebutton("Go!", $value);
|
||||
}
|
||||
|
||||
if($field->name == "apiname")
|
||||
{
|
||||
echo html_imagebutton("Wine LXR", "http://twine.codeweavers.com/lxr/ident?i=$value");
|
||||
echo html_imagebutton("Wine API", "http://www.winehq.com/WineAPI/$value.html");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* required field for each table.
|
||||
* When editing a query this field needs to be present in the query
|
||||
* in order to identify the correct row to update.
|
||||
*/
|
||||
var $table_ids = array(
|
||||
"user_list" => "userid",
|
||||
"appFamily" => "appId",
|
||||
"appVersion" => "versionId",
|
||||
"userExperience" => "uExpId",
|
||||
"appCategory" => "catId",
|
||||
"vendor" => "vendorId",
|
||||
"appNotes" => "noteId"
|
||||
);
|
||||
|
||||
function get_id($name)
|
||||
{
|
||||
reset($this->table_ids);
|
||||
while(list($table, $id) = each($this->table_ids))
|
||||
{
|
||||
$r = "^$table$";
|
||||
//echo "Checking $r against $name <br>\n";
|
||||
if(ereg($r, $name))
|
||||
{
|
||||
//echo "ID for $name -> $id <br>\n";
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* update() expects $HTTP_POST_VARS as argument
|
||||
* this is where things are getting kinda complex, here we update "
|
||||
* multiple entries with multiple fields in multiple tables (get it?)
|
||||
*/
|
||||
function update($vars)
|
||||
{
|
||||
global $current;
|
||||
|
||||
$tables = array();
|
||||
$fieldnames = array();
|
||||
$num_entries = 0;
|
||||
|
||||
while(list($varname, $arr) = each($vars))
|
||||
{
|
||||
if(!ereg("^FIELD_([a-zA-Z_]+)___(.+)$", $varname, $regs))
|
||||
continue;
|
||||
|
||||
$tables[$regs[1]][] = $regs[2];
|
||||
$fieldnames[$regs[2]] = $arr;
|
||||
$num_entries = sizeof($arr);
|
||||
}
|
||||
|
||||
while(list($table, $fields) = each($tables))
|
||||
{
|
||||
echo "<b> $table (".$this->get_id($table).") </b>";
|
||||
|
||||
if($fieldnames[$this->get_id($table)])
|
||||
echo "OK!";
|
||||
|
||||
echo "<br>\n";
|
||||
|
||||
for($i = 0; $i < sizeof($fields); $i++)
|
||||
echo "- $fields[$i] <br>\n";
|
||||
|
||||
echo "<br>\n";
|
||||
}
|
||||
|
||||
for($i = 0; $i < $num_entries; $i++)
|
||||
{
|
||||
reset($tables);
|
||||
while(list($table, $fields) = each($tables))
|
||||
{
|
||||
$update = "UPDATE $table SET ";
|
||||
|
||||
$count = sizeof($fields);
|
||||
reset($fields);
|
||||
while(list($idx, $field) = each($fields))
|
||||
{
|
||||
$count--;
|
||||
|
||||
if($this->table_ids[$table] == $field)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$key = "FIELD_".$table."___".$field;
|
||||
$type = $vars["TYPE_$key"][$i];
|
||||
|
||||
if($type == "int")
|
||||
$update .= "$field = ".$vars[$key][$i];
|
||||
else
|
||||
$update .= "$field = '".addslashes($vars[$key][$i])."'";
|
||||
|
||||
if($count)
|
||||
$update .= ", ";
|
||||
}
|
||||
|
||||
$value = $fieldnames[$this->get_id($table)][$i];
|
||||
|
||||
$update .= " WHERE ".$this->get_id($table)." = $value";
|
||||
|
||||
if(!mysql_query($update))
|
||||
{
|
||||
$thisError = "<p><font color=black><b>Query:</b>: $update</font></p>\n";
|
||||
$thisError .= "<p><font color=red>".mysql_error()."</font></p>";
|
||||
addmsg($thisError,"red");
|
||||
}
|
||||
else
|
||||
{
|
||||
addmsg("Database Operation Complete!","green");
|
||||
}
|
||||
|
||||
if(ereg("^impl_.+$", $table))
|
||||
{
|
||||
$value = $fieldnames["apiid"][$i];
|
||||
mysql_query("UPDATE $table SET lastmodby = $current->userid WHERE apiid = $value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function set_title_field($newTitleField)
|
||||
{
|
||||
$this->titleField = $newTitleField;
|
||||
}
|
||||
|
||||
function set_title_text($newTitleText)
|
||||
{
|
||||
$this->titleText = $newTitleText;
|
||||
}
|
||||
|
||||
function set_numbered_titles()
|
||||
{
|
||||
$this->numberedTitles = 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
319
include/user.php
Normal file
319
include/user.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* This class represents a logged in user
|
||||
*/
|
||||
class User {
|
||||
|
||||
var $link; // database connection
|
||||
|
||||
var $stamp;
|
||||
var $userid;
|
||||
var $username;
|
||||
var $realname;
|
||||
var $created;
|
||||
var $status;
|
||||
var $perm;
|
||||
|
||||
/*
|
||||
* constructor
|
||||
* opens a connection to the user database
|
||||
*/
|
||||
function User()
|
||||
{
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
|
||||
function connect()
|
||||
{
|
||||
$this->link = opendb();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* check if a user exists
|
||||
* returns TRUE if the user exists
|
||||
*/
|
||||
function exists($username)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM user_list WHERE username = '$username'", $this->link);
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
function lookup_username($userid)
|
||||
{
|
||||
$result = mysql_query("SELECT username FROM user_list WHERE userid = $userid");
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return null;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->username;
|
||||
}
|
||||
|
||||
function lookup_userid($username)
|
||||
{
|
||||
$result = mysql_query("SELECT userid FROM user_list WHERE username = '$username'");
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return null;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->userid;
|
||||
}
|
||||
|
||||
function lookup_realname($userid)
|
||||
{
|
||||
$result = mysql_query("SELECT realname FROM user_list WHERE userid = $userid");
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return null;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->realname;
|
||||
}
|
||||
|
||||
function lookup_email($userid)
|
||||
{
|
||||
$result = mysql_query("SELECT email FROM user_list WHERE userid = $userid");
|
||||
if(!$result || mysql_num_rows($result) != 1)
|
||||
return null;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->email;
|
||||
}
|
||||
|
||||
/*
|
||||
* restore a user from the database
|
||||
* returns 0 on success and an error msg on failure
|
||||
*/
|
||||
function restore($username, $password)
|
||||
{
|
||||
$result = mysql_query("SELECT stamp, userid, username, realname, ".
|
||||
"created, status, perm FROM user_list WHERE ".
|
||||
"username = '$username' AND ".
|
||||
"password = password('$password')", $this->link);
|
||||
//echo "RESTORE($username, $password) result=$result rows=".mysql_num_rows($result)."<br>\n";
|
||||
if(!$result)
|
||||
return "Error: ".mysql_error($this->link);
|
||||
|
||||
if(mysql_num_rows($result) == 0)
|
||||
return "Invalid username or password";
|
||||
|
||||
list($this->stamp, $this->userid, $this->username, $this->realname,
|
||||
$this->created, $status, $perm) = mysql_fetch_row($result);
|
||||
|
||||
//echo "<br> User: $this->userid ($this->username, $this->realname) <br>\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function login($username, $password)
|
||||
{
|
||||
$result = $this->restore($username, $password);
|
||||
|
||||
if($result != null)
|
||||
return $result;
|
||||
//echo "<br>LOGIN($this->username)<br>\n";
|
||||
//FIXME: update last_login here
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* create a new user
|
||||
* returns 0 on success and an error msg on failure
|
||||
*/
|
||||
function create($username, $password, $realname, $email)
|
||||
{
|
||||
$result = mysql_query("INSERT INTO user_list VALUES ( NOW(), 0, ".
|
||||
"'$username', password('$password'), ".
|
||||
"'$realname', '$email', NOW(), 0, 0)", $this->link);
|
||||
//echo "error: ".mysql_error();
|
||||
if(!$result)
|
||||
return mysql_error($this->link);
|
||||
return $this->restore($username, $password);
|
||||
}
|
||||
|
||||
// Update User Account;
|
||||
function update($userid = 0, $password = null, $realname = null, $email = null)
|
||||
{
|
||||
if (!$userid)
|
||||
return 0;
|
||||
if ($password)
|
||||
{
|
||||
if (!mysql_query("UPDATE user_list SET password = password('$password') WHERE userid = $userid"))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($realname)
|
||||
{
|
||||
if (!mysql_query("UPDATE user_list SET realname = '".addslashes($realname)."' WHERE userid = $userid"))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($email)
|
||||
{
|
||||
if (!mysql_query("UPDATE user_list SET email = '".addslashes($email)."' WHERE userid = $userid"))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* remove the current, or specified user from the database
|
||||
* returns 0 on success and an error msg on failure
|
||||
*/
|
||||
function remove($username = 0)
|
||||
{
|
||||
if($username == 0)
|
||||
$username = $this->username;
|
||||
|
||||
$result = mysql_query("DELETE FROM user_list WHERE username = '$username'", $this->link);
|
||||
|
||||
if(!$result)
|
||||
return mysql_error($this->link);
|
||||
if(mysql_affected_rows($result) == 0)
|
||||
return "No such user.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function done()
|
||||
{
|
||||
mysql_close($this->link);
|
||||
}
|
||||
|
||||
|
||||
function getpref($key, $def = null)
|
||||
{
|
||||
if(!$this->userid || !$key)
|
||||
return $def;
|
||||
|
||||
$result = mysql_query("SELECT * FROM user_prefs WHERE userid = $this->userid AND name = '$key'", $this->link);
|
||||
if(!$result || mysql_num_rows($result) == 0)
|
||||
return $def;
|
||||
$ob = mysql_fetch_object($result);
|
||||
return $ob->value;
|
||||
}
|
||||
|
||||
function setpref($key, $value)
|
||||
{
|
||||
if(!$this->userid || !$key || !$value)
|
||||
return null;
|
||||
|
||||
$result = mysql_query("DELETE FROM user_prefs WHERE userid = $this->userid AND name = '$key'");
|
||||
$result = mysql_query("INSERT INTO user_prefs VALUES($this->userid, '$key', '$value')");
|
||||
echo mysql_error();
|
||||
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* check if this user has $priv
|
||||
*/
|
||||
function checkpriv($priv)
|
||||
{
|
||||
if(!$this->userid || !$priv)
|
||||
return 0;
|
||||
|
||||
$result = mysql_query("SELECT * FROM user_privs WHERE userid = $this->userid AND priv = '$priv'", $this->link);
|
||||
if(!$result)
|
||||
return 0;
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
function addpriv($priv)
|
||||
{
|
||||
if(!$this->userid || !$priv)
|
||||
return 0;
|
||||
|
||||
if($this->checkpriv($priv))
|
||||
return 1;
|
||||
|
||||
$result = mysql_query("INSERT INTO user_privs VALUES ($this->userid, '$priv')", $this->link);
|
||||
|
||||
return mysql_affected_rows($result);
|
||||
}
|
||||
|
||||
function delpriv($priv)
|
||||
{
|
||||
if(!$this->userid || !$priv)
|
||||
return 0;
|
||||
|
||||
$result = mysql_query("DELETE FROM user_privs WHERE userid = $this->userid AND priv = '$priv'", $this->link);
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
*
|
||||
* App Owners
|
||||
*
|
||||
*/
|
||||
function ownsApp($appId)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appOwners WHERE ownerId = $this->userid AND appId = $appId");
|
||||
if($result && mysql_num_rows($result))
|
||||
return 1; // OK
|
||||
return 0; // NOPE!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function loggedin()
|
||||
{
|
||||
global $current;
|
||||
|
||||
if($current && $current->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function havepriv($priv)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!loggedin())
|
||||
return false;
|
||||
|
||||
return $current->checkpriv($priv);
|
||||
}
|
||||
|
||||
function debugging()
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!loggedin())
|
||||
return false;
|
||||
return $current->getpref("debug") == "yes";
|
||||
}
|
||||
|
||||
|
||||
function makeurl($text, $url, $pref = null)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(loggedin())
|
||||
{
|
||||
if($current->getpref($pref) == "yes")
|
||||
$extra = "window='new'";
|
||||
}
|
||||
return "<a href='$url' $extra> $text </a>\n";
|
||||
}
|
||||
|
||||
// create a new random password
|
||||
function generate_passwd($pass_len = 10)
|
||||
{
|
||||
$nps = "";
|
||||
mt_srand ((double) microtime() * 1000000);
|
||||
while (strlen($nps)<$pass_len)
|
||||
{
|
||||
$c = chr(mt_rand (0,255));
|
||||
if (eregi("^[a-z0-9]$", $c)) $nps = $nps.$c;
|
||||
}
|
||||
return ($nps);
|
||||
}
|
||||
|
||||
?>
|
||||
174
include/util.php
Normal file
174
include/util.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
$dbcon = null;
|
||||
$dbref = 0;
|
||||
|
||||
function opendb()
|
||||
{
|
||||
global $apidb_dbuser, $apidb_dbpass, $apidb_dbhost, $apidb_db;
|
||||
global $dbcon, $dbref;
|
||||
|
||||
$dbref++;
|
||||
|
||||
if($dbcon)
|
||||
return $dbcon;
|
||||
|
||||
$dbcon = mysql_connect($apidb_dbhost, $apidb_dbuser, $apidb_dbpass);
|
||||
if(!$dbcon)
|
||||
{
|
||||
echo "An error occurred: ".mysql_error()."<p>\n";
|
||||
exit;
|
||||
}
|
||||
mysql_select_db($apidb_db);
|
||||
return $dbcon;
|
||||
}
|
||||
|
||||
function closedb()
|
||||
{
|
||||
global $dbcon, $dbref;
|
||||
|
||||
if(--$dbref)
|
||||
return;
|
||||
|
||||
mysql_close($dbcon);
|
||||
}
|
||||
|
||||
function querydb($query)
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
if(!$result)
|
||||
{
|
||||
echo "<br><font color=green> $query </font> <br><br>\n";
|
||||
echo "<font color=red>A QUERY error occurred:</font> ".
|
||||
"<font color=blue>".mysql_error()."</font><p>\n";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function mysql_field_is_null($result, $row, $field)
|
||||
{
|
||||
if(mysql_result($result, $row, $field) == null)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function read_string($filename)
|
||||
{
|
||||
return join("", file($filename));
|
||||
}
|
||||
|
||||
|
||||
function build_urlarg($vars)
|
||||
{
|
||||
$arr = array();
|
||||
while(list($key, $val) = each($vars))
|
||||
{
|
||||
if(is_array($val))
|
||||
{
|
||||
while(list($idx, $value) = each($val))
|
||||
{
|
||||
//echo "Encoding $key / $value<br>";
|
||||
$arr[] = rawurlencode($key."[]")."=".rawurlencode($value);
|
||||
}
|
||||
}
|
||||
else
|
||||
$arr[] = $key."=".rawurlencode($val);
|
||||
}
|
||||
return implode("&", $arr);
|
||||
}
|
||||
|
||||
|
||||
function add_option_menu($options, $label, $id)
|
||||
{
|
||||
echo "<form action='project.php' method='get'>\n";
|
||||
echo "<select name='prj_id'>\n";
|
||||
while(list($idx, $val) = each($options))
|
||||
echo "<option>$val</option>\n";
|
||||
echo "</select>\n";
|
||||
echo "<input type='submit' value='$label'>\n";
|
||||
echo "</form> <br>\n";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* return all keys of a mapping as an array
|
||||
*/
|
||||
function keys($arr)
|
||||
{
|
||||
$res = array();
|
||||
while(list($k, $v) = each($arr))
|
||||
$res[] = $k;
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* return all values of a mapping as an array
|
||||
*/
|
||||
function values($arr)
|
||||
{
|
||||
$res = array();
|
||||
while(list($k, $v) = each($arr))
|
||||
$res[] = $v;
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* format date
|
||||
*/
|
||||
function makedate($time)
|
||||
{
|
||||
return date("F d, Y H:i:s", $time);
|
||||
}
|
||||
|
||||
|
||||
function get_remote()
|
||||
{
|
||||
global $REMOTE_HOST, $REMOTE_ADDR;
|
||||
|
||||
if($REMOTE_HOST)
|
||||
$ip = $REMOTE_HOST;
|
||||
else
|
||||
$ip = $REMOTE_ADDR;
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
function htmlify_urls($text)
|
||||
{
|
||||
//FIXME: wonder what the syntax is, this doesn't seem to work
|
||||
// $text = strip_tags($text, "<a>,<b>,<i>,<ul>,<li>");
|
||||
|
||||
// html-ify urls
|
||||
$urlreg = "([a-zA-Z]+://([^\t\r\n ]+))";
|
||||
$text = ereg_replace($urlreg, "<a href=\"\\1\"> \\2 </a>", $text);
|
||||
|
||||
$emailreg = "([a-zA-Z0-9_%+.-]+@[^\t\r\n ]+)";
|
||||
$text = ereg_replace($emailreg, " <a href='mailto:\\1'>\\1</a>", $text);
|
||||
|
||||
$text = str_replace("\n", "<br>", $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
// open file and display contents of selected tag
|
||||
function get_xml_tag ($file, $mode = null)
|
||||
{
|
||||
if ($mode and file_exists($file))
|
||||
{
|
||||
$fp = @fopen($file, "r");
|
||||
$data = fread($fp, filesize($file));
|
||||
@fclose($fp);
|
||||
if (eregi("<" . $mode . ">(.*)</" . $mode . ">", $data, $out))
|
||||
{
|
||||
return $out[1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
199
include/vote.php
Normal file
199
include/vote.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?
|
||||
|
||||
/* max votes per user */
|
||||
$MAX_VOTES = 3;
|
||||
|
||||
|
||||
/*
|
||||
* count the number of votes for appId by userId
|
||||
*/
|
||||
function vote_count($appId, $userId = null)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!$userId)
|
||||
{
|
||||
if(loggedin())
|
||||
$userId = $current->userid;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
$result = mysql_query("SELECT * FROM appVotes WHERE appId = $appId AND userId = $userId");
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
/*
|
||||
* total votes by userId
|
||||
*/
|
||||
function vote_count_user_total($userId = null)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!$userId)
|
||||
{
|
||||
if(loggedin())
|
||||
$userId = $current->userid;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
$result = mysql_query("SELECT * FROM appVotes WHERE userId = $userId");
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
/*
|
||||
* total votes for appId
|
||||
*/
|
||||
function vote_count_app_total($appId)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM appVotes WHERE appId = $appId");
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* add a vote for appId
|
||||
*/
|
||||
function vote_add($appId, $slot, $userId = null)
|
||||
{
|
||||
global $current;
|
||||
global $MAX_VOTES;
|
||||
|
||||
if(!$userId)
|
||||
{
|
||||
if(loggedin())
|
||||
$userId = $current->userid;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
//if(vote_count_user_total($userId) >= $MAX_VOTES)
|
||||
// return;
|
||||
vote_remove($appId, $slot, $userId);
|
||||
mysql_query("INSERT INTO appVotes VALUES (null, null, $appId, $userId, $slot)");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* remove vote for appId
|
||||
*/
|
||||
function vote_remove($appId, $slot, $userId = null)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!$userId)
|
||||
{
|
||||
if(loggedin())
|
||||
$userId = $current->userid;
|
||||
else
|
||||
return;
|
||||
}
|
||||
mysql_query("DELETE FROM appVotes WHERE appId = $appId AND userId = $userId AND slot = $slot");
|
||||
}
|
||||
|
||||
function vote_get_user_votes($userId = null)
|
||||
{
|
||||
global $current;
|
||||
|
||||
if(!$userId)
|
||||
{
|
||||
if(loggedin())
|
||||
$userId = $current->userid;
|
||||
if(!$userId)
|
||||
return array();
|
||||
}
|
||||
$result = mysql_query("SELECT * FROM appVotes WHERE userId = $userId");
|
||||
if(!$result)
|
||||
return array();
|
||||
|
||||
$obs = array();
|
||||
while($ob = mysql_fetch_object($result))
|
||||
$obs[$ob->slot] = $ob;
|
||||
return $obs;
|
||||
}
|
||||
|
||||
function vote_menu()
|
||||
{
|
||||
global $appId;
|
||||
global $apidb_root;
|
||||
|
||||
$m = new htmlmenu("Votes","updatevote.php");
|
||||
|
||||
$votes = vote_get_user_votes();
|
||||
|
||||
if($votes[1])
|
||||
{
|
||||
$str = "<a href='appview.php?appId=".$votes[1]->appId."'> App #".$votes[1]->appId."</a>";
|
||||
$m->add("<input type=radio name=slot value='1' selected> ".$str);
|
||||
}
|
||||
else
|
||||
$m->add("<input type=radio name=slot value='1' selected> No App Selected");
|
||||
|
||||
if($votes[2])
|
||||
{
|
||||
$str = "<a href='appview.php?appId=".$votes[2]->appId."'> App #".$votes[2]->appId."</a>";
|
||||
$m->add("<input type=radio name=slot value='2'> ".$str);
|
||||
}
|
||||
else
|
||||
$m->add("<input type=radio name=slot value='2'> No App Selected");
|
||||
|
||||
if($votes[3])
|
||||
{
|
||||
$str = "<a href='appview.php?appId=".$votes[3]->appId."'> App #".$votes[3]->appId."</a>";
|
||||
$m->add("<input type=radio name=slot value='3'> ".$str);
|
||||
}
|
||||
else
|
||||
$m->add("<input type=radio name=slot value='3'> No App Selected");
|
||||
|
||||
$m->addmisc(" ");
|
||||
|
||||
$m->add("<input type=submit name=clear value=' Clear Vote ' class=votebutton>");
|
||||
$m->add("<input type=submit name=vote value='Vote for App' class=votebutton>");
|
||||
|
||||
$m->addmisc("<input type=hidden name=appId value=$appId>");
|
||||
|
||||
$m->add("View Results", $apidb_root."votestats.php");
|
||||
$m->add("Voting Help", $apidb_root."help/?topic=voting");
|
||||
|
||||
$m->done(1);
|
||||
}
|
||||
|
||||
|
||||
function dump($arr)
|
||||
{
|
||||
while(list($key, $val) = each($arr))
|
||||
{
|
||||
echo "$key => $val <br>\n";
|
||||
}
|
||||
}
|
||||
|
||||
function vote_update($vars)
|
||||
{
|
||||
global $current;
|
||||
|
||||
//FIXME this doesn't work since msgs only work when logged in
|
||||
if(!$current)
|
||||
{
|
||||
addmsg("You must be logged in to vote", "red");
|
||||
return;
|
||||
}
|
||||
|
||||
dump($vars);
|
||||
echo "<br>\n";
|
||||
|
||||
if($vars["vote"])
|
||||
{
|
||||
addmsg("Registered vote for App #".$vars["appId"], "green");
|
||||
vote_add($vars["appId"], $vars["slot"]);
|
||||
}
|
||||
else
|
||||
if($vars["clear"])
|
||||
{
|
||||
addmsg("Removed vote for App #".$vars["appId"], "green");
|
||||
vote_remove($vars["appId"], $vars["slot"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user