PageRenderTime 37ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/addons/user/user/register.php

http://wowroster.googlecode.com/
PHP | 362 lines | 312 code | 39 blank | 11 comment | 43 complexity | 0878a3ec20b7d08570441687aaeddfe3 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. if( !isset($user) )
  3. {
  4. include_once ($addon['inc_dir'] . 'conf.php');
  5. }
  6. if(isset($_POST['op']) && $_POST['op']=='register')
  7. {
  8. // If the Register form has been submitted
  9. echo '<pre>';
  10. print_r($_POST);
  11. echo '</pre>';
  12. $err = array();
  13. if(strlen($_POST['username'])<4 || strlen($_POST['username'])>64)
  14. {
  15. $err[]='Your username must be between 3 and 64 characters!';
  16. }
  17. if (isset($_POST['password1']) && isset($_POST['password2']) && $_POST['password1'] == $_POST['password2'])
  18. {
  19. $pass = md5($_POST['password1']);
  20. }
  21. if(!count($err))
  22. {
  23. $_POST['email'] = mysql_real_escape_string($_POST['email']);
  24. $_POST['username'] = mysql_real_escape_string($_POST['username']);
  25. // Escape the input data
  26. if (!empty($_POST['rank']))
  27. {
  28. $rank = $_POST['rank'];
  29. }
  30. else
  31. {
  32. $querya = "SELECT `name`,`guild_rank` FROM `".$roster->db->table('members')."` WHERE `name` = '".$_POST['username']."';";
  33. $resulta = $roster->db->query($querya);
  34. if( $resulta )
  35. {
  36. $row = $roster->db->fetch($resulta);
  37. $rank = $row['guild_rank'];
  38. }
  39. else
  40. {
  41. $rank = '';
  42. }
  43. }
  44. $age = mktime(0, 0, 0, $_POST['age_Month'], $_POST['age_Day'], $_POST['age_Year']);
  45. $data = array(
  46. 'usr' => $_POST['username'],
  47. 'pass' => $pass,
  48. 'email' => $_POST['email'],
  49. 'regIP' => $_SERVER['REMOTE_ADDR'],
  50. 'dt' => $roster->db->escape(gmdate('Y-m-d H:i:s')),
  51. 'access' => '0:'.$rank,
  52. 'fname' => $_POST['fname'],
  53. 'lname' => $_POST['lname'],
  54. 'age' => $age,
  55. 'city' => $_POST['City'],
  56. 'state' => $_POST['State'],
  57. 'country' => $_POST['Country'],
  58. 'zone' => $_POST['Zone'],
  59. 'active' => $_POST['active']
  60. );
  61. $query = 'INSERT INTO `' . $roster->db->table('user_members') . '` ' . $roster->db->build_query('INSERT', $data);
  62. // user link table i was hoping to NOT use this....
  63. if( $roster->db->query($query) )
  64. {
  65. $uuid = $roster->db->insert_id();
  66. $roster->set_message('You are registered and can now login','User Register:','notice');
  67. $querya = "SELECT `name`,`guild_id`,`server`,`region`,`member_id` FROM `".$roster->db->table('members')."` WHERE `name` = '".$_POST['username']."';";
  68. $resulta = $roster->db->query($querya);
  69. $a = "INSERT INTO `".$roster->db->table('profile','user')."` (`uid`, `signature`, `avatar`, `avsig_src`, `show_fname`, `show_lname`, `show_email`, `show_city`, `show_country`, `show_homepage`, `show_notes`, `show_joined`, `show_lastlogin`, `show_chars`, `show_guilds`, `show_realms`) VALUES ('$uuid', '', '', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');";
  70. $aa = $roster->db->query($a);
  71. if( !$resulta )
  72. {
  73. die_quietly($roster->db->error, 'user Profile', __FILE__,__LINE__,$querya);
  74. }
  75. else
  76. {
  77. $row = $roster->db->fetch($resulta);
  78. $data2 = array(
  79. 'uid' => $uuid,
  80. 'member_id' => $row['member_id'],
  81. 'guild_id' => $row['guild_id'],
  82. 'group_id' => '1',
  83. 'is_main' => '1',
  84. 'realm' => $row['server'],
  85. 'region' => $row['region']
  86. );
  87. $query2 = 'INSERT INTO `' . $roster->db->table('user_link', 'user') . '` ' . $roster->db->build_query('INSERT', $data2);
  88. $result2 = $roster->db->query($query2);
  89. $update_sql = "UPDATE `" . $roster->db->table('members') . "`"
  90. . " SET `account_id` = '" . $uuid . "'"
  91. . " WHERE `name` = '".$_POST['username']."';";
  92. $accid = $roster->db->query($update_sql);
  93. }
  94. echo $roster->auth->getLoginForm();
  95. return;
  96. }
  97. else
  98. {
  99. $roster->set_message('There was a DB error while creating your user.', '', 'error');
  100. $roster->set_message('<pre>' . $roster->db->error() . '</pre>', 'MySQL Said', 'error');
  101. }
  102. }
  103. if(count($err))
  104. {
  105. $e = implode('<br />',$err);
  106. }
  107. }
  108. $num1=$num2=$num3=null;
  109. function generateUniqueRandoms($min, $max, $count)
  110. {
  111. if($count > $max)
  112. { // this prevents an infinite loop
  113. echo "ERROR: The array count is greater than the random number maximum.<br>\n";
  114. echo "Therefore, it is impossible to build an array of unique random numbers.<br>\n";
  115. break;
  116. }
  117. $numArray = array('0'=>'','1'=>'','2'=>'');
  118. for($i = 0; $i < $count; $i++)
  119. {
  120. $numArray[$i] = mt_rand($min,$max); // set random number
  121. for($j = 0; $j < $count; $j++) // for each number, check for duplicates
  122. if($j != $i) // except for the one you are checking of course
  123. if($numArray[$i] == $numArray[$j])
  124. {
  125. $numArray[$i] = mt_rand(1,10); // if duplicate, generate new random
  126. $j = 0; // go back through and check new number
  127. }
  128. }
  129. return $numArray;
  130. }
  131. if ($addon['config']['char_auth'])
  132. {
  133. $x = generateUniqueRandoms(0, 18, 3);
  134. $r = implode(':',$x);
  135. list($num1,$num2,$num3) = explode(':',$r);
  136. $s = "
  137. $(document).ready(function () {
  138. //$('input#xsubmit').attr('disabled', 'true');
  139. $('input#submit_btn').click(function(){
  140. //$('#pUsername').keyup(function () {
  141. var t = this;
  142. var char = $('input#pUsername').val();
  143. var validateUsername = $('#validateUsername');
  144. var pUsername = $('#pUsername');
  145. var pclass = $('input#class');
  146. var plevel = $('input#level');
  147. var prank = $('#rank');
  148. var pmember_id = $('#member_id');
  149. var ptitle = $('#title');
  150. var photo = $('#photo');
  151. var EQ1 = $('div#EQ1');
  152. var EQ2 = $('div#EQ2');
  153. var EQ3 = $('div#EQ3');
  154. if (this.timer) clearTimeout(this.timer);
  155. validateUsername.removeClass('error').html('<img src=\"".$roster->config['img_url']."canvas-loader.gif\" height=\"18\" width=\"18\" /> checking availability...');
  156. this.timer = setTimeout(function () {
  157. $.ajax({
  158. url: 'index.php?p=user-user-ajaxcvar',
  159. //url: 'index.php?p=ajaxcvar',
  160. data: 'action=check_username&server=".$roster->data['server']."&slot=".$num1.'-'.$num2.'-'.$num3."&character=' + char,
  161. dataType: 'json',
  162. type: 'post',
  163. success: function (j) {
  164. if (j.ok)
  165. {
  166. validateUsername.html(j.msg);
  167. pUsername.val(char);
  168. $('div#EQ1').removeClass(\"RGaccepy RGdenyed RGquestion\").addClass(j.EEQQ1);
  169. $('div#EQ2').removeClass(\"RGaccepy RGdenyed RGquestion\").addClass(j.EEQQ2);
  170. $('div#EQ3').removeClass(\"RGaccepy RGdenyed RGquestion\").addClass(j.EEQQ3);
  171. pclass.val(j.cla55);
  172. plevel.val(j.level);
  173. prank.val(j.rank);
  174. pmember_id.val(j.member_id);
  175. ptitle.html(j.title);
  176. photo.html('<img src=\"http://us.battle.net/static-render/us/'+j.thumb+'\" height=\"75\" width=\"75\" /></a>');
  177. $('#xsubmit').removeAttr('disabled');
  178. $('input#submit_btn').attr('disabled', 'true');
  179. }
  180. else
  181. {
  182. photo.html('<img src=\"http://us.battle.net/static-render/us/'+j.thumb+'\" height=\"75\" width=\"75\" /></a>');
  183. validateUsername.html(j.msg);
  184. $('div#EQ1').removeClass(\"RGaccepy RGdenyed RGquestion\").addClass(j.EEQQ1);
  185. $('div#EQ2').removeClass(\"RGaccepy RGdenyed RGquestion\").addClass(j.EEQQ2);
  186. $('div#EQ3').removeClass(\"RGaccepy RGdenyed RGquestion\").addClass(j.EEQQ3);
  187. pclass.val(j.cla55);
  188. plevel.val(j.level);
  189. prank.val(j.rank);
  190. ptitle.html(j.title);
  191. }
  192. }
  193. });
  194. }, 200);
  195. });
  196. });";
  197. roster_add_js($s,'inline');
  198. }
  199. function _getItemSlot($value) {
  200. $ret = '';
  201. switch ($value)
  202. {
  203. case 0: $ret = "Head";break; case 1: $ret = "Neck";break; case 2: $ret = "Shoulder";break;
  204. case 3: $ret = "Shirt";break; case 4: $ret = "Chest";break; case 5: $ret = "Waist";break;
  205. case 6: $ret = "Legs";break; case 7: $ret = "Feet";break; case 8: $ret = "Wrist";break;
  206. case 9: $ret = "Hands";break; case 10: $ret = "Finger0";break; case 11: $ret = "Finger1";break;
  207. case 12: $ret = "Trinket0";break; case 13: $ret = "Trinket1";break; case 14: $ret = "Back";break;
  208. case 15: $ret = "MainHand";break; case 16: $ret = "SecondaryHand";break; case 17: $ret = "Ranged";break;
  209. case 18: $ret = "Tabard";break;
  210. }
  211. return $ret;
  212. }
  213. function _getItemSlotn($value) {
  214. $ret = '';
  215. switch ($value)
  216. {
  217. case 0: $ret = "Head";break; case 1: $ret = "Neck";break; case 2: $ret = "Shoulder";break;
  218. case 3: $ret = "Shirt";break; case 4: $ret = "Chest";break; case 5: $ret = "Waist";break;
  219. case 6: $ret = "Legs";break; case 7: $ret = "Feet";break; case 8: $ret = "Wrist";break;
  220. case 9: $ret = "Hands";break; case 10: $ret = "Finger 0";break; case 11: $ret = "Finger 1";break;
  221. case 12: $ret = "Trinket 0";break; case 13: $ret = "Trinket 1";break; case 14: $ret = "Back";break;
  222. case 15: $ret = "MainHand";break; case 16: $ret = "SecondaryHand";break; case 17: $ret = "Ranged";break;
  223. case 18: $ret = "Tabard";break;
  224. }
  225. return $ret;
  226. }
  227. $form = 'userApp';
  228. //$user->form->newForm('post', makelink('util-accounts-application'), $form, 'formClass', 4);
  229. $user->form->newForm('post', makelink('user-user-register'), $form, 'formClass', 4);
  230. if ($addon['config']['fname_auth'] == '1')
  231. {
  232. $user->form->addTextBox('text', 'fname', '', $roster->locale->act['user_int']['fname'], 'wowinput128', 1, $form);
  233. }
  234. if ($addon['config']['lname_auth'] == '1')
  235. {
  236. $user->form->addTextBox('text', 'lname', '', $roster->locale->act['user_int']['lname'], 'wowinput128', '', $form);
  237. }
  238. if ($addon['config']['age_auth'] == '1')
  239. {
  240. $user->form->addDateSelect('age','Birthdate',1,$form);
  241. }
  242. if ($addon['config']['city_auth'] == '1')
  243. {
  244. $user->form->addTextBox('text','City','',$roster->locale->act['user_int']['city'],'wowinput128','',$form);
  245. }
  246. if ($addon['config']['state_auth'] == '1')
  247. {
  248. $user->form->addTextBox('text','State','',$roster->locale->act['user_int']['state'],'wowinput128','',$form);
  249. }
  250. if ($addon['config']['country_auth'] == '1')
  251. {
  252. $user->form->addTextBox('text','Country','',$roster->locale->act['user_int']['country'],'wowinput128',1,$form);
  253. }
  254. if ($addon['config']['zone_auth'] == '1')
  255. {
  256. $user->form->addTimezone('Zone',$roster->locale->act['user_app']['zone'],'',$form);
  257. }
  258. if ($addon['config']['char_auth'] == '1')
  259. {
  260. $roster->tpl->assign_vars(array(
  261. 'R_EQUIP_1' => _getItemSlot($num1),
  262. 'R_EQUIP_2' => _getItemSlot($num2),
  263. 'R_EQUIP_3' => _getItemSlot($num3),
  264. 'N_EQUIP_1' => _getItemSlotn($num1),
  265. 'N_EQUIP_2' => _getItemSlotn($num2),
  266. 'N_EQUIP_3' => _getItemSlotn($num3),
  267. 'R_IMAGE_PTH' => $roster->config['img_url'].'Interface/EmptyEquip/',
  268. //'R_Q_CHAR' => @$_REQUEST['character'],
  269. //'R_Q_RANK' => @$_REQUEST['rank'],
  270. 'R_MSG_ERROR' => (!empty($e) ? $e : ''),
  271. 'CHAR_AUTH' => $addon['config']['char_auth'],
  272. 'CNAMETT' => makeOverlib($roster->locale->act['cname_tt'],$roster->locale->act['cname'],'',1,'',',WRAP'),
  273. 'CNAME' => $roster->locale->act['cname'],
  274. 'CLASSTT' => makeOverlib($roster->locale->act['cclass_tt'],$roster->locale->act['cclass'],'',1,'',',WRAP'),
  275. 'CLASS' => $roster->locale->act['cclass'],
  276. 'LEVELTT' => makeOverlib($roster->locale->act['clevel_tt'],$roster->locale->act['clevel'],'',1,'',',WRAP'),
  277. 'LEVEL' => $roster->locale->act['clevel'],
  278. 'RANKTT' => makeOverlib($roster->locale->act['cgrank_tt'],$roster->locale->act['cgrank'],'',1,'',',WRAP'),
  279. 'RANK' => $roster->locale->act['cgrank'],
  280. 'EMAILTT' => makeOverlib($roster->locale->act['cemail_tt'],$roster->locale->act['cemail'],'',1,'',',WRAP'),
  281. 'EMAIL' => $roster->locale->act['cemail'],
  282. 'AGE' => 'Birthday',
  283. 'AGEF' => '',
  284. 'XXX' => $user->form->getTableOfElements_3(1,$form),
  285. )
  286. );
  287. }
  288. else
  289. {
  290. $roster->tpl->assign_vars(array(
  291. 'R_EQUIP_1' => '',//_getItemSlot($num1),
  292. 'R_EQUIP_2' => '',//_getItemSlot($num2),
  293. 'R_EQUIP_3' => '',//_getItemSlot($num3),
  294. 'N_EQUIP_1' => '',//_getItemSlotn($num1),
  295. 'N_EQUIP_2' => '',//_getItemSlotn($num2),
  296. 'N_EQUIP_3' => '',//_getItemSlotn($num3),
  297. 'R_IMAGE_PTH' => $roster->config['img_url'].'Interface/EmptyEquip/',
  298. //'R_Q_CHAR' => @$_REQUEST['character'],
  299. //'R_Q_RANK' => @$_REQUEST['rank'],
  300. 'R_MSG_ERROR' => (!empty($e) ? $e : ''),
  301. 'CHAR_AUTH' => $addon['config']['char_auth'],
  302. 'CNAMETT' => makeOverlib($roster->locale->act['cname_tt'],$roster->locale->act['cname'],'',1,'',',WRAP'),
  303. 'CNAME' => $roster->locale->act['cname'],
  304. 'CLASSTT' => makeOverlib($roster->locale->act['cclass_tt'],$roster->locale->act['cclass'],'',1,'',',WRAP'),
  305. 'CLASS' => $roster->locale->act['cclass'],
  306. 'LEVELTT' => makeOverlib($roster->locale->act['clevel_tt'],$roster->locale->act['clevel'],'',1,'',',WRAP'),
  307. 'LEVEL' => $roster->locale->act['clevel'],
  308. 'RANKTT' => makeOverlib($roster->locale->act['cgrank_tt'],$roster->locale->act['cgrank'],'',1,'',',WRAP'),
  309. 'RANK' => $roster->locale->act['cgrank'],
  310. 'EMAILTT' => makeOverlib($roster->locale->act['cemail_tt'],$roster->locale->act['cemail'],'',1,'',',WRAP'),
  311. 'EMAIL' => $roster->locale->act['cemail'],
  312. 'AGE' => 'Birthday',
  313. 'AGEF' => '',
  314. 'XXX' => $user->form->getTableOfElements_3(1,$form),
  315. )
  316. );
  317. }
  318. $roster->tpl->set_filenames(array(
  319. 'register' => 'register.html'
  320. )
  321. );
  322. $roster->tpl->display('register');
  323. ?>