Guest User

Untitled

a guest
May 2nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. <?php
  2.  
  3. // define member-tablename
  4. define('TABLENAME','members');
  5.  
  6. class getUser {
  7.  
  8. private $info = array();
  9.  
  10. public function __construct($idOrName, $inputType = "user") {
  11.  
  12. $this->setUser($idOrName, $inputType);
  13.  
  14. }
  15.  
  16. public function setUser($idOrName, $inputType = "user") {
  17.  
  18. $success = true;
  19.  
  20. if(isset($this->info)) {
  21. unset($this->info);
  22. }
  23.  
  24. if($inputType == "user") {
  25.  
  26. $idOrName = mysql_real_escape_string($idOrName);
  27. $this->info = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLENAME." WHERE username = '" . $idOrName . "'"));
  28.  
  29. } elseif($inputType == "id") {
  30.  
  31. $idOrName = intval($idOrName);
  32. $this->info = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLENAME." WHERE id = '" . $idOrName . "'"));
  33.  
  34. } else {
  35.  
  36. $success = false;
  37. die('<b>Error: </b>Second parameter wrong. Write either user or id (leave blank for user)');
  38.  
  39. }
  40.  
  41. return $success;
  42.  
  43. }
  44.  
  45. private function createAge($birthDate) {
  46.  
  47. list($y, $m, $d) = explode('-', $birthDate);
  48. if(!preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $birthDate) || $m>12 || $d>31) {
  49. return false;
  50. } else {
  51. $age = (date('z') < date('z', strtotime(date('Y')."-$m-$d"))) ? date('Y')-$y-1 : date('Y')-$y;
  52. return $age;
  53. }
  54. }
  55.  
  56. /*/////////////////////////////////////
  57. SIMPLE THINGS BUT STILL IMPORTANT
  58. /////////////////////////////////////*/
  59.  
  60. public function getId() {
  61. return $this->info['id'];
  62. }
  63.  
  64. public function getUsername() {
  65. return $this->info['username'];
  66. }
  67.  
  68. public function getFirstName() {
  69. return $this->info['fnamn'];
  70. }
  71.  
  72. public function getLastName() {
  73. return $this->info['enamn'];
  74. }
  75.  
  76. public function getGender() {
  77. return $this->info['kon'];
  78. }
  79.  
  80. public function getPic() {
  81. return $this->info['bild'];
  82. }
  83.  
  84. public function getStad() {
  85. return $this->info['bor'];
  86. }
  87.  
  88. public function getRights() {
  89. return $this->info['kebab'];
  90. }
  91.  
  92. /*/////////////////////////////////////
  93. DATES, NUMBERS AND STUFF
  94. /////////////////////////////////////*/
  95.  
  96. public function getBirthDate() {
  97. return $this->info['fodelsedatum'];
  98. }
  99.  
  100. public function getAge() {
  101. return $this->createAge($this->info['fodelsedatum']);
  102. }
  103.  
  104. public function getDateRegistrated() {
  105. return $this->info['reg_reg'];
  106. }
  107.  
  108. public function getLatestLogin() {
  109. return $this->info['latest_login'];
  110. }
  111.  
  112. /*/////////////////////////////////////
  113. OTHERS
  114. /////////////////////////////////////*/
  115.  
  116. public function getSpecial() {
  117. return $this->info['special'];
  118. }
  119.  
  120. public function getSpecial2() {
  121. return $this->info['special2'];
  122. }
  123.  
  124. public function getContact() {
  125. return $this->info['kontakt'];
  126. }
  127.  
  128. public function getStatus() {
  129. return $this->info['online'];
  130. }
  131.  
  132. public function getVip() {
  133. return $this->info['vip'];
  134. }
  135.  
  136. public function getUnreadGb() {
  137. return $this->info['olastgb'];
  138. }
  139.  
  140. public function getUnreadPm() {
  141. return $this->info['olastpm'];
  142. }
  143.  
  144. /*/////////////////////////////////////
  145. PRESENTATION
  146. /////////////////////////////////////*/
  147.  
  148. public function getPresentation() {
  149. return $this->info['presentation'];
  150. }
  151.  
  152. public function getPressBg() {
  153. return $this->info['press_bg'];
  154. }
  155.  
  156. public function getPressColor() {
  157. return $this->info['press_color'];
  158. }
  159.  
  160. public function getPressBgWhich() {
  161. return $this->info['press_bg_which'];
  162. }
  163.  
  164. /*/////////////////////////////////////
  165. PROFILE PARAMETERS
  166. /////////////////////////////////////*/
  167.  
  168. public function getFritid() {
  169. return $this->info['par_fritid'];
  170. }
  171.  
  172. public function getGenre() {
  173. return $this->info['par_lyssnar'];
  174. }
  175.  
  176. public function getGillar() {
  177. return $this->info['par_gillar'];
  178. }
  179.  
  180. public function getPersonlighet() {
  181. return $this->info['par_personlighet'];
  182. }
  183.  
  184. public function getCivilstand() {
  185. return $this->info['par_civilstand'];
  186. }
  187.  
  188. public function getBor() {
  189. return $this->info['par_bor'];
  190. }
  191.  
  192. public function getHarfarg() {
  193. return $this->info['par_harfarg'];
  194. }
  195.  
  196. /*/////////////////////////////////////
  197. DESTRUCTOR
  198. /////////////////////////////////////*/
  199.  
  200. public function __destruct() {
  201. unset($this->info);
  202. }
  203.  
  204. }
  205.  
  206. class setUser {
  207.  
  208. private $user; // the username we will be changing the settings for
  209.  
  210. public $sqlstring;
  211.  
  212. public function __construct($idOrName, $inputType = "user") {
  213.  
  214. $this->setUser($idOrName, $inputType);
  215.  
  216. }
  217.  
  218. public function setUser($idOrName, $inputType = "user") {
  219.  
  220. $success = true;
  221.  
  222. if($inputType == 'user') {
  223. $this->user = "username = '".$idOrName."'";
  224. } elseif($inputType == 'id') {
  225. $this->user = "id = ".$idOrName;
  226. } else {
  227.  
  228. $success = false;
  229. die('<b>Error: </b>Second parameter wrong. Write either user or id (leave blank for user)');
  230.  
  231. }
  232.  
  233. return $success;
  234.  
  235. }
  236.  
  237.  
  238. /*/////////////////////////////////////
  239. SIMPLE THINGS BUT STILL IMPORTANT
  240. /////////////////////////////////////*/
  241.  
  242. public function setId() {
  243. die('<b>Denied: </b>ID can\'t be changed!');
  244. }
  245.  
  246. public function setUsername($value) {
  247. $this->sqlstring .= ", username = '".$value."'";
  248. }
  249.  
  250. public function setPassword($value) {
  251. $this->sqlstring .= ", password = '".md5($value)."'";
  252. }
  253.  
  254. public function setFirstName($value) {
  255. $this->sqlstring .= ", fnamn = '".$value."'";
  256. }
  257.  
  258. public function setLastName($value) {
  259. $this->sqlstring .= ", enamn = '".$value."'";
  260. }
  261.  
  262. public function setGender($value) {
  263. $this->sqlstring .= ", kon = '".$value."'";
  264. }
  265.  
  266. public function setPic($value) {
  267. $this->sqlstring .= ", bild = '".$value."'";
  268. }
  269.  
  270. public function setStad($value) {
  271. $this->sqlstring .= ", bor = '".$value."'";
  272. }
  273.  
  274. public function setZip($value) {
  275. $success = true;
  276.  
  277. $gottenCity = mysql_fetch_assoc(mysql_query("SELECT * FROM `caipirinha_zipcodes` WHERE entry_zipcode = ".$value));
  278. if(empty($gottenCity['entry_city'])) {
  279. $success = false;
  280. } else {
  281. mysql_query("UPDATE `".TABLENAME."` SET stad = '".ucfirst(strtolower($gottenCity['entry_city']))."'");
  282. }
  283. return $success;
  284. }
  285.  
  286. public function setRights($value) {
  287. $this->sqlstring .= ", kebab = '".$value."'";
  288. }
  289.  
  290. /*/////////////////////////////////////
  291. DATES, NUMBERS AND STUFF
  292. /////////////////////////////////////*/
  293.  
  294. public function setBirthDate($value) {
  295. $this->sqlstring .= ", fodelsedatum = '".$value."'";
  296. }
  297.  
  298. public function setDateRegistrated($value) {
  299. $this->sqlstring .= ", reg_reg = '".$value."'";
  300. }
  301.  
  302. public function setLatestLogin($value) {
  303. $this->sqlstring .= ", latest_login = '".$value."'";
  304. }
  305.  
  306. /*/////////////////////////////////////
  307. OTHERS
  308. /////////////////////////////////////*/
  309.  
  310. public function setSpecial($value) {
  311. $this->sqlstring .= ", special = '".$value."'";
  312. }
  313.  
  314. public function setSpecial2($value) {
  315. $this->sqlstring .= ", special2 = '".$value."'";
  316. }
  317.  
  318. public function setContact($value) {
  319. $this->sqlstring .= ", kontakt = '".$value."'";
  320. }
  321.  
  322. public function setStatus($value) {
  323. $this->sqlstring .= ", online = '".$value."'";
  324. }
  325.  
  326. public function setVip($value) {
  327. $this->sqlstring .= ", vip = '".$value."'";
  328. }
  329.  
  330. /*/////////////////////////////////////
  331. PRESENTATION
  332. /////////////////////////////////////*/
  333.  
  334. public function setPresentation($value) {
  335. $this->sqlstring .= ", presentation = '".$value."'";
  336. }
  337.  
  338. public function setPressBg($value) {
  339. $this->sqlstring .= ", press_bg = '".$value."'";
  340. }
  341.  
  342. public function setPressColor($value) {
  343. $this->sqlstring .= ", press_color = '".$value."'";
  344. }
  345.  
  346. public function setPressBgWhich($value) {
  347. $this->sqlstring .= ", press_bg_which = '".$value."'";
  348. }
  349.  
  350. /*/////////////////////////////////////
  351. PROFILE PARAMETERS
  352. /////////////////////////////////////*/
  353.  
  354. public function setFritid($value) {
  355. $this->sqlstring .= ", par_fritid = '".$value."'";
  356. }
  357.  
  358. public function setGenre($value) {
  359. $this->sqlstring .= ", par_lyssnar = '".$value."'";
  360. }
  361.  
  362. public function setGillar($value) {
  363. $this->sqlstring .= ", par_gillar = '".$value."'";
  364. }
  365.  
  366. public function setPersonlighet($value) {
  367. $this->sqlstring .= ", par_personlighet = '".$value."'";
  368. }
  369.  
  370. public function setCivilstand($value) {
  371. $this->sqlstring .= ", par_civilstand = '".$value."'";
  372. }
  373.  
  374. public function setBor($value) {
  375. $this->sqlstring .= ", par_bor = '".$value."'";
  376. }
  377.  
  378. public function setHarfarg($value) {
  379. $this->sqlstring .= ", par_harfarg = '".$value."'";
  380. }
  381.  
  382. public function execute() {
  383.  
  384. $success = true;
  385. $this->sqlstring = "UPDATE `".TABLENAME."` ".$this->sqlstring." WHERE ".$this->user."";
  386. $this->sqlstring = str_replace('UPDATE `'.TABLENAME.'` , ', 'UPDATE `'.TABLENAME.'` SET ', $this->sqlstring);
  387. mysql_query($this->sqlstring) or die(mysql_error());
  388.  
  389. return $success;
  390.  
  391. }
  392.  
  393. }
  394.  
  395. ?>
  396.  
  397. <?php
  398.  
  399. /*/////////////////////////////////////
  400. INSTANCE
  401. /////////////////////////////////////*/
  402. /*
  403.  
  404. mysql_connect($server,$user,$pw);
  405. mysql_select_db($database);
  406.  
  407. $info = new getUser('100000','id');
  408. echo $info->getAge()."<br />";
  409. echo $info->getBirthDate();
  410.  
  411. echo "<p>";
  412.  
  413. // nu vill jag byta användare, så jag kallar på metoden setUser (som constructorn använder)
  414.  
  415. $info->setUser('Leoone','user');
  416. echo $info->getAge();
  417.  
  418. */
  419.  
  420. ?>
Add Comment
Please, Sign In to add comment