[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_handlers/rate_class.php,v $ 14 | $Revision: 1.20 $ 15 | $Date: 2007/01/10 21:30:34 $ 16 | $Author: e107steved $ 17 +----------------------------------------------------------------------------+ 18 */ 19 20 if (!defined('e107_INIT')) { exit; } 21 22 @include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_rate.php"); 23 @include_once(e_LANGUAGEDIR."English/lan_rate.php"); 24 class rater { 25 function rateselect($text, $table, $id, $mode=FALSE) { 26 //$mode : if mode is set, no urljump will be used (used in combined comments+rating system) 27 28 $table = preg_replace('/\W/', '', $table); 29 $id = intval($id); 30 31 $self = $_SERVER['PHP_SELF']; 32 if ($_SERVER['QUERY_STRING']) { 33 $self .= "?".$_SERVER['QUERY_STRING']; 34 } 35 36 $jump = ""; 37 $url = ""; 38 if($mode==FALSE){ 39 $jump = "onchange='urljump(this.options[selectedIndex].value)'"; 40 $url = e_BASE."rate.php?"; 41 } 42 43 $str = $text." 44 <select name='rateindex' ".$jump." class='tbox'> 45 <option selected='selected' value='0'>".RATELAN_5."</option> 46 <option value='".$url."{$table}^{$id}^{$self}^1'>1</option> 47 <option value='".$url."{$table}^{$id}^{$self}^2'>2</option> 48 <option value='".$url."{$table}^{$id}^{$self}^3'>3</option> 49 <option value='".$url."{$table}^{$id}^{$self}^4'>4</option> 50 <option value='".$url."{$table}^{$id}^{$self}^5'>5</option> 51 <option value='".$url."{$table}^{$id}^{$self}^6'>6</option> 52 <option value='".$url."{$table}^{$id}^{$self}^7'>7</option> 53 <option value='".$url."{$table}^{$id}^{$self}^8'>8</option> 54 <option value='".$url."{$table}^{$id}^{$self}^9'>9</option> 55 <option value='".$url."{$table}^{$id}^{$self}^10'>10</option> 56 </select>"; 57 return $str; 58 } 59 60 function rateradio($table, $id) { 61 62 $table = preg_replace('/\W/', '', $table); 63 $id = intval($id); 64 65 $str = " 66 <input type='radio' value='1' />1 67 <input type='radio' value='2' />2 68 <input type='radio' value='3' />3 69 <input type='radio' value='4' />4 70 <input type='radio' value='5' />5 71 <input type='radio' value='6' />6 72 <input type='radio' value='7' />7 73 <input type='radio' value='8' />8 74 <input type='radio' value='9' />9 75 <input type='radio' value='10' />10"; 76 return $str; 77 } 78 79 function checkrated($table, $id) { 80 81 $table = preg_replace('/\W/', '', $table); 82 $id = intval($id); 83 84 $sql = new db; 85 if (!$sql->db_Select("rate", "*", "rate_table = '{$table}' AND rate_itemid = '{$id}' ")) { 86 return FALSE; 87 } else { 88 $row = $sql->db_Fetch(); 89 90 if (preg_match("/\.".USERID."\./", $row['rate_voters'])) { 91 return TRUE; 92 //added option to split an individual users rating 93 }else if (preg_match("/\.".USERID.chr(1)."([0-9]{1,2})\./", $row['rate_voters'])) { 94 return TRUE; 95 } else { 96 return FALSE; 97 } 98 } 99 } 100 101 function getrating($table, $id, $userid=FALSE) { 102 //userid : boolean, get rating for a single user, or get general total rating of the item 103 104 $table = preg_replace('/\W/', '', $table); 105 $id = intval($id); 106 107 $sql = new db; 108 if (!$sql->db_Select("rate", "*", "rate_table = '{$table}' AND rate_itemid = '{$id}' ")) { 109 return FALSE; 110 } else { 111 $rowgr = $sql->db_Fetch(); 112 if($userid==TRUE){ 113 $rating = ""; 114 $rateusers = explode(".", $rowgr['rate_voters']); 115 for($i=0;$i<count($rateusers);$i++){ 116 if(strpos($rateusers[$i], chr(1))){ 117 $rateuserinfo[$i] = explode(chr(1), $rateusers[$i]); 118 if($userid == $rateuserinfo[$i][0]){ 119 $rating[0] = 0; //number of votes, not relevant in users rating 120 $rating[1] = $rateuserinfo[$i][1]; //the rating by this user 121 $rating[2] = 0; //no remainder is present, because we have a single users rating 122 break; 123 } 124 }else{ 125 $rating[0] = 0; //number of votes, not relevant in users rating 126 $rating[1] = 0; //the rating by this user 127 $rating[2] = 0; //no remainder is present, because we have a single users rating 128 } 129 } 130 }else{ 131 $rating[0] = $rowgr['rate_votes']; // $rating[0] == number of votes 132 $tmp = $rowgr['rate_rating'] / $rowgr['rate_votes']; 133 $tmp = (strpos($tmp,",")) ? explode(",", $tmp) : explode(".", $tmp); 134 $rating[1] = $tmp[0]; 135 if(isset($tmp[1])){ 136 $rating[2] = substr($tmp[1], 0, 1); 137 }else{ 138 $rating[2] = "0"; 139 } 140 } 141 142 return $rating; 143 } 144 } 145 146 function enterrating($rateindex){ 147 global $sql, $tp; 148 149 $qs = explode("^", $rateindex); 150 151 if (!$qs[0] || USER == FALSE || $qs[3] > 10 || $qs[3] < 1) { 152 header("location:".e_BASE."index.php"); 153 exit; 154 } 155 156 $table = $tp -> toDB($qs[0], true); 157 $itemid = intval($qs[1]); 158 $rate = intval($qs[3]); 159 160 //rating is now stored as userid-rating (to retain individual users rating) 161 //$sep = "^"; 162 $sep = chr(1); 163 $voter = USERID.$sep.intval($qs[3]); 164 165 if ($sql->db_Select("rate", "*", "rate_table='{$table}' AND rate_itemid='{$itemid}' ")) { 166 $row = $sql->db_Fetch(); 167 $rate_voters = $row['rate_voters'].".".$voter."."; 168 $sql->db_Update("rate", "rate_votes=rate_votes+1, rate_rating=rate_rating+'{$rate}', rate_voters='{$rate_voters}' WHERE rate_id='{$row['rate_id']}' "); 169 } else { 170 $sql->db_Insert("rate", " 0, '$table', '$itemid', '$rate', '1', '.".$voter.".' "); 171 } 172 } 173 174 function composerating($table, $id, $enter=TRUE, $userid=FALSE, $nojump=FALSE){ 175 //enter : boolean to show (rateselect box + textual info) or not 176 //userid : used to calculate a users given rating 177 //nojump : boolean, if present no urljump will be used (needed in comment_rating system) 178 179 $rate = ""; 180 if($ratearray = $this -> getrating($table, $id, $userid)){ 181 if($ratearray[1] > 0){ 182 for($c=1; $c<= $ratearray[1]; $c++){ 183 $rate .= "<img src='".e_IMAGE."rate/box.png' alt='' style='height:8px; vertical-align:middle' />"; 184 } 185 if($ratearray[1] < 10){ 186 for($c=9; $c>=$ratearray[1]; $c--){ 187 $rate .= "<img src='".e_IMAGE."rate/empty.png' alt='' style='height:8px; vertical-align:middle' />"; 188 } 189 } 190 $rate .= "<img src='".e_IMAGE."rate/boxend.png' alt='' style='height:8px; vertical-align:middle' />"; 191 if($ratearray[2] == ""){ $ratearray[2] = 0; } 192 $rate .= " ".$ratearray[1].".".$ratearray[2]; 193 if(!$userid){ 194 $rate .= " - ".$ratearray[0]." "; 195 $rate .= ($ratearray[0] == 1 ? RATELAN_0 : RATELAN_1); 196 } 197 } 198 }else{ 199 if($enter===TRUE){ 200 $rate .= RATELAN_4; 201 } 202 } 203 if($enter===TRUE){ 204 if(!isset($ratearray[1]) || $ratearray[1] > 0){ 205 $rate .= " - "; 206 } 207 if(!$this -> checkrated($table, $id) && USER){ 208 $rate .= $this -> rateselect(RATELAN_2, $table, $id, $nojump); 209 210 }else if(USER){ 211 $rate .= RATELAN_3; 212 } 213 } 214 215 return $rate; 216 217 } 218 219 function delete_ratings($table, $id) 220 { 221 global $tp, $sql; 222 $table = $tp->toDB($table, true); 223 $id = intval($id); 224 return $sql -> db_Delete("rate", "rate_itemid='{$id}' AND rate_table='{$table}'"); 225 } 226 } 227 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |