getrating($table, $id); parse_str($options,$options); // $label = varset($options['label'],RATELAN_5); $readonly = $this->checkrated($table, $id) ? '1' : '0'; $hintArray = array(RATELAN_POOR,RATELAN_FAIR,RATELAN_GOOD,RATELAN_VERYGOOD,RATELAN_EXCELLENT); $datahint = implode(",",$hintArray); $path = e_FILE_ABS."jslib/rate/img/"; $score = ($score / 2); // var_dump($readonly); if(!$votes) { $voteDiz = RATELAN_4; } else { $voteDiz = ($votes == 1) ? RATELAN_0 : RATELAN_1; } if($readonly == '1') { $label = RATELAN_3; } if(!USERID) { $label = RATELAN_6; // Please login to vote. $readonly = '1'; } $template = vartrue($options['template'], "STATUS|RATE|VOTES"); $TEMPLATE['STATUS'] = "
".$label."
"; $TEMPLATE['RATE'] = "
"; $TEMPLATE['VOTES'] = "
".$this->renderVotes($votes,$score)."
"; $tmp = explode("|",$template); $text = ""; foreach($tmp as $k) { $text .= $TEMPLATE[$k]; } return $text; } function renderVotes($votes,$score) // TODO use template? { if(!$votes) { $voteDiz = RATELAN_4; } else { $voteDiz = ($votes == 1) ? RATELAN_0 : RATELAN_1; } return "{$score}/5 : {$votes} ".$voteDiz; } // Legacy Rate Selector. function rateselect($text, $table, $id, $mode=FALSE) { //$mode : if mode is set, no urljump will be used (used in combined comments+rating system) $table = preg_replace('/\W/', '', $table); $id = intval($id); // return $this->render($text,$table,$id,$mode); // $self = $_SERVER['PHP_SELF']; // if ($_SERVER['QUERY_STRING']) { // $self .= "?".$_SERVER['QUERY_STRING']; // } $self = e_REQUEST_URI; $jump = ""; $url = ""; if($mode==FALSE){ $jump = "onchange='urljump(this.options[selectedIndex].value)'"; $url = e_HTTP."rate.php?"; } $str = $text." "; return $str; } function rateradio($table, $id) { $table = preg_replace('/\W/', '', $table); $id = intval($id); $str = " 1 10"; return $str; } function checkrated($table, $id) { $table = preg_replace('/\W/', '', $table); $id = intval($id); $sql = new db; if (!$sql->db_Select("rate", "*", "rate_table = '{$table}' AND rate_itemid = '{$id}' ")) { return FALSE; } else { $row = $sql->db_Fetch(); if (preg_match("/\.".USERID."\./", $row['rate_voters'])) { return TRUE; //added option to split an individual users rating }else if (preg_match("/\.".USERID.chr(1)."([0-9]{1,2})\./", $row['rate_voters'])) { return TRUE; } else { return FALSE; } } } function getrating($table, $id, $userid=FALSE) { //userid : boolean, get rating for a single user, or get general total rating of the item $table = preg_replace('/\W/', '', $table); $id = intval($id); if($id == 0) { return "There is no item ID in the rating"; } $sep = chr(1); $sql = new db; if (!$sql->db_Select("rate", "*", "rate_table = '{$table}' AND rate_itemid = '{$id}' ")) { return FALSE; } else { $rowgr = $sql->db_Fetch(); if($userid==TRUE){ $rating = ""; $rateusers = explode(".", $rowgr['rate_voters']); for($i=0;$ienterrating($array,true); } function enterrating($rateindex,$ajax = false) { $sql = e107::getDb(); $tp = e107::getParser(); $qs = explode("^", $rateindex); if (!$qs[0] || USER == FALSE || $qs[3] > 10 || $qs[3] < 1) { if($ajax == false) { header("location:".e_BASE."index.php"); exit; } else { return "Error: ".print_a($qs,true); } } $table = $tp -> toDB($qs[0], true); $itemid = intval($qs[1]); $rate = intval($qs[3]); //rating is now stored as userid-rating (to retain individual users rating) //$sep = "^"; $sep = chr(1); // problematic - invisible in phpmyadmin. $voter = USERID.$sep.intval($qs[3]); if ($sql->db_Select("rate", "*", "rate_table='{$table}' AND rate_itemid='{$itemid}' ")) { $row = $sql -> db_Fetch(); $rate_voters = $row['rate_voters'].".".$voter."."; $new_votes = $row['rate_votes'] + 1; $new_rating = $row['rate_rating'] + $rate; $stat = ($new_rating /$new_votes)/2; $statR = round($stat,1); if(strpos($row['rate_voters'], ".".$voter.".") == true || strpos($row['rate_voters'], ".".USERID.".") == true) { return "You already voted|".$this->renderVotes($new_votes,$statR); // " newvotes = ".($statR). " =".$new_votes; } if($sql->db_Update("rate", "rate_votes= ".$new_votes.", rate_rating='{$new_rating}', rate_voters='{$rate_voters}' WHERE rate_id='{$row['rate_id']}' ")) { return RATELAN_3."|".$this->renderVotes($new_votes,$statR); // Thank you for your vote. } else { return "Error"; } } elseif($sql->db_Insert("rate", " 0, '$table', '$itemid', '$rate', '1', '.".$voter.".' ")) { $stat = ($rate /1)/2; $statR = round($stat,1); return RATELAN_3."|".$this->renderVotes(1,$statR); ; // Thank you for your vote. } } function composerating($table, $id, $enter=TRUE, $userid=FALSE, $nojump=FALSE){ //enter : boolean to show (rateselect box + textual info) or not //userid : used to calculate a users given rating //nojump : boolean, if present no urljump will be used (needed in comment_rating system) $rate = ""; if($ratearray = $this -> getrating($table, $id, $userid)){ if($ratearray[1] > 0){ for($c=1; $c<= $ratearray[1]; $c++){ $rate .= ""; } if($ratearray[1] < 10){ for($c=9; $c>=$ratearray[1]; $c--){ $rate .= ""; } } $rate .= ""; if($ratearray[2] == ""){ $ratearray[2] = 0; } $rate .= " ".$ratearray[1].".".$ratearray[2]; if(!$userid){ $rate .= " - ".$ratearray[0]." "; $rate .= ($ratearray[0] == 1 ? RATELAN_0 : RATELAN_1); } } }else{ if($enter===TRUE){ $rate .= RATELAN_4; } } if($enter===TRUE){ if(!isset($ratearray[1]) || $ratearray[1] > 0){ $rate .= " - "; } if(!$this -> checkrated($table, $id) && USER){ $rate .= $this -> rateselect(RATELAN_2, $table, $id, $nojump); }else if(USER){ $rate .= RATELAN_3; } } return $rate; } function delete_ratings($table, $id) { global $tp, $sql; $table = $tp->toDB($table, true); $id = intval($id); return $sql -> db_Delete("rate", "rate_itemid='{$id}' AND rate_table='{$table}'"); } }