View file includes/rate.php

File size: 1.4Kb
<?php

if ($u['id'] and $id > 0) {
	if ($type == 'profile') {
		$type_ch_r = mysql_query("SELECT * FROM `users` WHERE `id` = '$id'");
	} else {
		$type_ch_r = mysql_query("SELECT * FROM `$type` WHERE `id` = '$id'");
	}
	$type_ch = mysql_fetch_assoc($type_ch_r);
	if ($type_ch['id']) {
		switch ($type) {
			case 'blogs': $go =  '?act=view&id='.$id; break;
			case 'loads': $go =  '?act=view&id='.$id; break;
			case 'photos': $go =  '?act=view&id='.$id; break;
			case 'profile': $go =  '?id='.$id; break;
			case 'forum_msg': $go =  '?id='.$type_ch['id_topic'].'&p='.$page.'#'.$id; break;
		}
		
		$vote_r = mysql_query("SELECT `id` FROM `voting` WHERE `type` = '$type' and `id_data` = '$id' and `id_user` = '$u[id]'");
		if (!mysql_num_rows($vote_r)) {
			mysql_query("INSERT INTO `voting` SET `type` = '$type', `id_data` = '$id', `id_user` = '$u[id]'");
			if ($type == 'profile') {
				if ($id != $u['id']) {
					$karma = !empty($ok) ? '(`karma`+1)' : '(`karma`-1)';
					mysql_query("UPDATE `users` SET `karma` = $karma WHERE `id` = '$id'");
				}
			} else { // other stuff's rating like blogs (=notes)
				$rating = !empty($ok) ? '(`rating`+1)' : '(`rating`-1)';
				if ($type_ch['id_user'] != $u['id']) {
					mysql_query("UPDATE `$type` SET `rating` = $rating WHERE `id` = '$id'");
				}
			}
		}
		redirect($go);
	} else {
		//redirect('../');
	}
} else {
	redirect('../');
}

?>