aUser['login'] = $login; } function setUserID($id) { $sql = " SELECT login FROM sm_users WHERE id = '$id' LIMIT 0 , 1 "; $qUser = mysql_query($sql); if(mysql_num_rows($qUser)>0) { $fUser = mysql_fetch_array($qUser); $this->aUser['login'] = $fUser['login']; } } function __construct($username) { if(isset($username)) { $this->aUser['login'] = $username; } } function getUser() { global $_SESSION; if(isset($this->aUser['login'])) { $login = mysql_escape_string($this->aUser['login']); $sql = " SELECT * FROM sm_users WHERE login = '$login' LIMIT 0 , 1 "; $qUser = mysql_query($sql); if(mysql_num_rows($qUser)>0) { $check = true; $fUser = mysql_fetch_array($qUser); $uUserID = $fUser['id']; $uOrgID = $fUser['organization_id']; $uMemberID = $fUser['member_id']; $uAdminID = $fUser['administrator_id']; $u['user_id'] = $uUserID; $u['email'] = $fUser['email']; $u['login'] = $login; if ($uOrgID != NULL) { $u['Type_User'] = 'Org'; $adv_user = one_row_query("SELECT * FROM sm_organizations WHERE organization_id = '".$uOrgID."'"); if (!$adv_user) { return NULL; } if (ctype_digit($adv['registr_user_title'])) $adv_title_user = one_row_query("SELECT * FROM sm_members_title WHERE id = ".$adv_user['registr_user_title']); else $adv_title_user = ""; $u['User_Name'] = $adv_title_user['title']." ".$adv_user['registr_user_first_name']." ".$adv_user['registr_user_last_name']; $u['organization_id'] = $uOrgID; $u['organization_name'] = $adv_user['short_name_org']; $u['status_organization'] = $adv_user['status_organization_id']; $u['type_registrations'] = $adv_user['type_reg_org_id']; } elseif ($uMemberID != NULL) { $u['Type_User'] = 'Memb'; $adv_user = one_row_query("SELECT * FROM sm_members WHERE id = '".$uMemberID."'"); if (!$adv_user) { return NULL; } if (ctype_digit($adv['title'])) $adv_title_user = one_row_query("SELECT * FROM sm_members_title WHERE id = ".$adv_user['title']); else $adv_title_user = ""; $u['User_Name'] = $adv_title_user['title']." ".$adv_user['first_name']." ".$adv_user['last_name']; $u['organization_id'] = $adv_user['organization_id']; $u['organization_name'] = $adv_user['short_name_org']; if ($adv_user['organization_id'] != NULL) { $org = one_row_query("SELECT * FROM sm_organizations WHERE organization_id = '".$adv_user['organization_id']."'"); $u['organization_name'] = $org['short_name_org']; $u['status_organization'] = $org['status_organization_id']; // PRO $u['type_registrations'] = $org['type_reg_org_id']; // Research Scientist } else { $u['status_organization'] = $adv_user['type_org']; $u['type_registrations'] = $adv_user['id_type_registration']; } } elseif ($uAdminID != NULL) { $u['Type_User'] = 'Adm'; $adv_user = one_row_query("SELECT * FROM sm_administators WHERE id = '".$uAdminID."'"); if (!$adv_user) { return NULL; } if (ctype_digit($adv['title'])) $adv_title_user = one_row_query("SELECT * FROM sm_members_title WHERE id = ".$adv_user['title']); else $adv_title_user = ""; $u['User_Name'] = $adv_title_user['title']." ".$adv_user['firts_name']." ".$adv_user['last_name']; $u['organization_id'] = 0; $u['organization_name'] = 'Administration'; $u['status_organization'] = 1; $u['type_registrations'] = 1; } return $u; } else { return NULL; } } else { return NULL; } } } ?>rItems = $item_id; $this->rTypeItem = $type_item; $this->rUser = $user_id; $this->rUrl = $url; $this->GetRating(); } function IsCanAdd() { if (empty($this->rUser)) { return false; } $sql = "select count(user_id) as count_rec from sm_ratings where user_id = ".$this->rUser." and type_item = '".$this->rTypeItem."' and item_id = ".$this->rItems; $res = one_row_query($sql); if ($res['count_rec'] > 0) { return false; } return true; } function GetRating() { $sql = "select count(rZap.user_id) as count_rec, sum(rZap.rating) as sum_rec from (select * from sm_ratings where type_item = '".$this->rTypeItem."' and item_id = ".$this->rItems." order by dateadd DESC limit 0, 400) rZap"; $res = one_row_query($sql); $this->rCurrentRating = 0; $this->rRatings = 0; if ($res['count_rec'] != 0) { $this->rRatings = $res['count_rec']; $this->rCurrentRating = ($res['sum_rec']) / ($res['count_rec']); } return $this->rCurrentRating; } function AddRating($value) { if ($this->IsCanAdd()) { $res = mysql_query("insert into sm_ratings (user_id, type_item, rating, item_id) values (".$this->rUser." , '".$this->rTypeItem."' , ".$value.", ".$this->rItems.")"); } $this->GetRating(); } function ShowRating() { if ($this->rTypeItem == 'wiki') { $url1 = $this->rUrl.'&rat=1'; $url2 = $this->rUrl.'&rat=2'; $url3 = $this->rUrl.'&rat=3'; $url4 = $this->rUrl.'&rat=4'; $url5 = $this->rUrl.'&rat=5'; } $l1 = (140 / 5 * $this->rCurrentRating); if ($l1 == 0) $l1 = 140; $l2 = round(140 - $l1); $rat = Round($this->rCurrentRating*100)/100; $out = ''; if ($this->IsCanAdd()) { $out = $out.'
Current rating - '.$rat.'
Ratings - '.$this->rRatings.'
'; } else { $out = $out.'
Current rating - '.$rat.'
Ratings - '.$this->rRatings.'
'; } return $out; } } ?>