Hi,
I've recently had an urge to implement an ajax rating system to the profile module so users could rate each others' profiles to define reliable customers. So I came across an interesting AJAX solution I will share now. Here is what my profile page looks like now:
How to implement:
1. Donwload the file archive (15Kb) from
here.
2. Import ratings.sql to your database. This will create a new table there.
3. Upload images/, js/ and css/ directories into your default theme directory.
4. Upload _config-rating.php, db.php, rpc.php and _drawrating.php into modules/profile/ directory. Edit _config-rating.php with your server info.
5. Edit your theme.html. Add
<script type="text/javascript" language="javascript" src="<{xoImgUrl}>js/behavior.js">script>
<script type="text/javascript" language="javascript" src="<{xoImgUrl}>js/rating.js">script>
<link rel="stylesheet" type="text/css" href="<{xoImgUrl}>css/rating.css" />
just before the closing tag.
6. Edit userinfo.php. Add
require('_drawrating.php');
right before
$uid = intval($_GET['uid']);
. Also add
//rating hack
if ( $xoopsUser ) {
$rate = rating_bar($uid,'5');
$xoopsTpl->assign('rate', $rate);
} else {
$rate = rating_bar($uid,'5','static');
$xoopsTpl->assign('rate', $rate); // we don't want anonymous users to vote so we give them a static picture
}
//end of hack
before
include $GLOBALS['xoops']->path('/include/comment_view.php')
.
7. Edit the profile_userinfo.html template and add
<{$rate}>
wherever you want your rating box to appear.
8. Clean your cache.
This is it. Enjoy your new AJAX rating system. This can be also easily implemented to any other module.