Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // define member-tablename
- define('TABLENAME','members');
- class getUser {
- private $info = array();
- public function __construct($idOrName, $inputType = "user") {
- $this->setUser($idOrName, $inputType);
- }
- public function setUser($idOrName, $inputType = "user") {
- $success = true;
- if(isset($this->info)) {
- unset($this->info);
- }
- if($inputType == "user") {
- $idOrName = mysql_real_escape_string($idOrName);
- $this->info = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLENAME." WHERE username = '" . $idOrName . "'"));
- } elseif($inputType == "id") {
- $idOrName = intval($idOrName);
- $this->info = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLENAME." WHERE id = '" . $idOrName . "'"));
- } else {
- $success = false;
- die('<b>Error: </b>Second parameter wrong. Write either user or id (leave blank for user)');
- }
- return $success;
- }
- private function createAge($birthDate) {
- list($y, $m, $d) = explode('-', $birthDate);
- if(!preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $birthDate) || $m>12 || $d>31) {
- return false;
- } else {
- $age = (date('z') < date('z', strtotime(date('Y')."-$m-$d"))) ? date('Y')-$y-1 : date('Y')-$y;
- return $age;
- }
- }
- /*/////////////////////////////////////
- SIMPLE THINGS BUT STILL IMPORTANT
- /////////////////////////////////////*/
- public function getId() {
- return $this->info['id'];
- }
- public function getUsername() {
- return $this->info['username'];
- }
- public function getFirstName() {
- return $this->info['fnamn'];
- }
- public function getLastName() {
- return $this->info['enamn'];
- }
- public function getGender() {
- return $this->info['kon'];
- }
- public function getPic() {
- return $this->info['bild'];
- }
- public function getStad() {
- return $this->info['bor'];
- }
- public function getRights() {
- return $this->info['kebab'];
- }
- /*/////////////////////////////////////
- DATES, NUMBERS AND STUFF
- /////////////////////////////////////*/
- public function getBirthDate() {
- return $this->info['fodelsedatum'];
- }
- public function getAge() {
- return $this->createAge($this->info['fodelsedatum']);
- }
- public function getDateRegistrated() {
- return $this->info['reg_reg'];
- }
- public function getLatestLogin() {
- return $this->info['latest_login'];
- }
- /*/////////////////////////////////////
- OTHERS
- /////////////////////////////////////*/
- public function getSpecial() {
- return $this->info['special'];
- }
- public function getSpecial2() {
- return $this->info['special2'];
- }
- public function getContact() {
- return $this->info['kontakt'];
- }
- public function getStatus() {
- return $this->info['online'];
- }
- public function getVip() {
- return $this->info['vip'];
- }
- public function getUnreadGb() {
- return $this->info['olastgb'];
- }
- public function getUnreadPm() {
- return $this->info['olastpm'];
- }
- /*/////////////////////////////////////
- PRESENTATION
- /////////////////////////////////////*/
- public function getPresentation() {
- return $this->info['presentation'];
- }
- public function getPressBg() {
- return $this->info['press_bg'];
- }
- public function getPressColor() {
- return $this->info['press_color'];
- }
- public function getPressBgWhich() {
- return $this->info['press_bg_which'];
- }
- /*/////////////////////////////////////
- PROFILE PARAMETERS
- /////////////////////////////////////*/
- public function getFritid() {
- return $this->info['par_fritid'];
- }
- public function getGenre() {
- return $this->info['par_lyssnar'];
- }
- public function getGillar() {
- return $this->info['par_gillar'];
- }
- public function getPersonlighet() {
- return $this->info['par_personlighet'];
- }
- public function getCivilstand() {
- return $this->info['par_civilstand'];
- }
- public function getBor() {
- return $this->info['par_bor'];
- }
- public function getHarfarg() {
- return $this->info['par_harfarg'];
- }
- /*/////////////////////////////////////
- DESTRUCTOR
- /////////////////////////////////////*/
- public function __destruct() {
- unset($this->info);
- }
- }
- class setUser {
- private $user; // the username we will be changing the settings for
- public $sqlstring;
- public function __construct($idOrName, $inputType = "user") {
- $this->setUser($idOrName, $inputType);
- }
- public function setUser($idOrName, $inputType = "user") {
- $success = true;
- if($inputType == 'user') {
- $this->user = "username = '".$idOrName."'";
- } elseif($inputType == 'id') {
- $this->user = "id = ".$idOrName;
- } else {
- $success = false;
- die('<b>Error: </b>Second parameter wrong. Write either user or id (leave blank for user)');
- }
- return $success;
- }
- /*/////////////////////////////////////
- SIMPLE THINGS BUT STILL IMPORTANT
- /////////////////////////////////////*/
- public function setId() {
- die('<b>Denied: </b>ID can\'t be changed!');
- }
- public function setUsername($value) {
- $this->sqlstring .= ", username = '".$value."'";
- }
- public function setPassword($value) {
- $this->sqlstring .= ", password = '".md5($value)."'";
- }
- public function setFirstName($value) {
- $this->sqlstring .= ", fnamn = '".$value."'";
- }
- public function setLastName($value) {
- $this->sqlstring .= ", enamn = '".$value."'";
- }
- public function setGender($value) {
- $this->sqlstring .= ", kon = '".$value."'";
- }
- public function setPic($value) {
- $this->sqlstring .= ", bild = '".$value."'";
- }
- public function setStad($value) {
- $this->sqlstring .= ", bor = '".$value."'";
- }
- public function setZip($value) {
- $success = true;
- $gottenCity = mysql_fetch_assoc(mysql_query("SELECT * FROM `caipirinha_zipcodes` WHERE entry_zipcode = ".$value));
- if(empty($gottenCity['entry_city'])) {
- $success = false;
- } else {
- mysql_query("UPDATE `".TABLENAME."` SET stad = '".ucfirst(strtolower($gottenCity['entry_city']))."'");
- }
- return $success;
- }
- public function setRights($value) {
- $this->sqlstring .= ", kebab = '".$value."'";
- }
- /*/////////////////////////////////////
- DATES, NUMBERS AND STUFF
- /////////////////////////////////////*/
- public function setBirthDate($value) {
- $this->sqlstring .= ", fodelsedatum = '".$value."'";
- }
- public function setDateRegistrated($value) {
- $this->sqlstring .= ", reg_reg = '".$value."'";
- }
- public function setLatestLogin($value) {
- $this->sqlstring .= ", latest_login = '".$value."'";
- }
- /*/////////////////////////////////////
- OTHERS
- /////////////////////////////////////*/
- public function setSpecial($value) {
- $this->sqlstring .= ", special = '".$value."'";
- }
- public function setSpecial2($value) {
- $this->sqlstring .= ", special2 = '".$value."'";
- }
- public function setContact($value) {
- $this->sqlstring .= ", kontakt = '".$value."'";
- }
- public function setStatus($value) {
- $this->sqlstring .= ", online = '".$value."'";
- }
- public function setVip($value) {
- $this->sqlstring .= ", vip = '".$value."'";
- }
- /*/////////////////////////////////////
- PRESENTATION
- /////////////////////////////////////*/
- public function setPresentation($value) {
- $this->sqlstring .= ", presentation = '".$value."'";
- }
- public function setPressBg($value) {
- $this->sqlstring .= ", press_bg = '".$value."'";
- }
- public function setPressColor($value) {
- $this->sqlstring .= ", press_color = '".$value."'";
- }
- public function setPressBgWhich($value) {
- $this->sqlstring .= ", press_bg_which = '".$value."'";
- }
- /*/////////////////////////////////////
- PROFILE PARAMETERS
- /////////////////////////////////////*/
- public function setFritid($value) {
- $this->sqlstring .= ", par_fritid = '".$value."'";
- }
- public function setGenre($value) {
- $this->sqlstring .= ", par_lyssnar = '".$value."'";
- }
- public function setGillar($value) {
- $this->sqlstring .= ", par_gillar = '".$value."'";
- }
- public function setPersonlighet($value) {
- $this->sqlstring .= ", par_personlighet = '".$value."'";
- }
- public function setCivilstand($value) {
- $this->sqlstring .= ", par_civilstand = '".$value."'";
- }
- public function setBor($value) {
- $this->sqlstring .= ", par_bor = '".$value."'";
- }
- public function setHarfarg($value) {
- $this->sqlstring .= ", par_harfarg = '".$value."'";
- }
- public function execute() {
- $success = true;
- $this->sqlstring = "UPDATE `".TABLENAME."` ".$this->sqlstring." WHERE ".$this->user."";
- $this->sqlstring = str_replace('UPDATE `'.TABLENAME.'` , ', 'UPDATE `'.TABLENAME.'` SET ', $this->sqlstring);
- mysql_query($this->sqlstring) or die(mysql_error());
- return $success;
- }
- }
- ?>
- <?php
- /*/////////////////////////////////////
- INSTANCE
- /////////////////////////////////////*/
- /*
- mysql_connect($server,$user,$pw);
- mysql_select_db($database);
- $info = new getUser('100000','id');
- echo $info->getAge()."<br />";
- echo $info->getBirthDate();
- echo "<p>";
- // nu vill jag byta användare, så jag kallar på metoden setUser (som constructorn använder)
- $info->setUser('Leoone','user');
- echo $info->getAge();
- */
- ?>
Add Comment
Please, Sign In to add comment