PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/root/includes/ucp/ucp_account_link.php

https://github.com/laszloh/account_link
PHP | 214 lines | 153 code | 34 blank | 27 comment | 13 complexity | 803fc7cb633b907b2475e8c961d90612 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @author Michael Flenniken, Jr drakkim@conclavewiz.com
  5. *
  6. * @package ucp
  7. * @version SVN: $Id: ucp_account_link.php 77 2012-09-02 10:48:53Z drakkim $
  8. * @copyright (c) 2008 Michael Flenniken, Jr
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. *
  11. */
  12. /**
  13. * @ignore
  14. */
  15. if (!defined('IN_PHPBB'))
  16. {
  17. exit;
  18. }
  19. /**
  20. * @package ucp
  21. */
  22. class ucp_account_link
  23. {
  24. var $u_action;
  25. function main($id, $mode)
  26. {
  27. global $user, $auth, $template, $phpbb_root_path, $phpEx, $db;
  28. global $alink;
  29. $user->add_lang('mods/account_link');
  30. $submit = request_var('submit', '', true);
  31. $action = request_var('action', '', true);
  32. $u_redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx");
  33. $l_redirect = ($u_redirect === ("{$phpbb_root_path}index.$phpEx" || $u_redirect === "index.$phpEx")) ? $user->lang['RETURN_INDEX'] : $user->lang['RETURN_PAGE'];
  34. // append/replace SID (may change during the session for AOL users)
  35. $u_redirect = reapply_sid($u_redirect);
  36. $redirect = '<br /><br />' . sprintf($l_redirect, '<a href="' . $u_redirect . '">', '</a>');
  37. $error = $message = array();
  38. // Always need this
  39. $is_master = false;
  40. if ($user->data['master_id'] != 0)
  41. {
  42. $sql = 'SELECT username
  43. FROM ' . USERS_TABLE . '
  44. WHERE user_id = '. $user->data['master_id'];
  45. $result = $db->sql_query($sql);
  46. $master_name = $db->sql_fetchfield('username');
  47. $db->sql_freeresult($result);
  48. }
  49. else
  50. {
  51. $master_name = $user->data['username'];
  52. $is_master = true;
  53. }
  54. switch ($mode)
  55. {
  56. case 'manage':
  57. $this->page_title = $user->lang['MANAGE_LINKED_ACCOUNTS'];
  58. $this->tpl_name = 'ucp_alink_manage';
  59. if($is_master)
  60. {
  61. switch($submit)
  62. {
  63. case 'link':
  64. if(!check_form_key('ucp_alink'))
  65. {
  66. $error[] = $user->lang['FORM_INVALID'];
  67. break;
  68. }
  69. $master_pass = request_var('master_pass', '', true);
  70. $linked_name = request_var('linked_name', '', true);
  71. $linked_pass = request_var('linked_pass', '', true);
  72. $result = $alink->link_account_validate ($master_name, $master_pass, $linked_name, $linked_pass);
  73. if ($result === true)
  74. {
  75. add_log('user', 'LOG_LINK_SUCCESS', $master_name, $linked_name);
  76. $message[] = $user->lang['LINK_SUCCESS'];
  77. }
  78. else
  79. {
  80. $error = array_merge($error, $result);
  81. add_log('user', 'LOG_LINK_FAILED', $master_name, $linked_name, $error);
  82. }
  83. break;
  84. case 'unlink':
  85. $uids = request_var('userids', array(0));
  86. user_get_id_name($uids, $username_ary);
  87. // confirm the unlink
  88. if(confirm_box(true))
  89. {
  90. $unlink_id = $uids[0];
  91. // test if accounts are linked
  92. if(!$alink->is_account_linked($user->data['user_id'], $unlink_id))
  93. {
  94. $error = $user->lang['ACCOUNT_UNLINK_FAILED'];
  95. add_log('user', 'LOG_LINK_BROCKEN_FAILED', $master_name, implode(' ', $username_ary));
  96. // hammer time!
  97. trigger_error($error);
  98. }
  99. // do the unlink
  100. $alink->unlink_accounts($unlink_id, $user->data['user_id']);
  101. $message[] = $user->lang['LINK_BROKEN'];
  102. add_log ('user', $user->data['user_id'], 'LOG_LINK_BROKEN', $master_name, implode(' ', $username_ary));
  103. }
  104. else
  105. {
  106. confirm_box(false, sprintf($user->lang['CONFIRM_ACCOUNT_UNLINK'], implode(' ', $username_ary), $master_name), build_hidden_fields(array(
  107. 'mode' => 'manage',
  108. 'submit' => 'unlink',
  109. 'userids' => $uids,
  110. )));
  111. }
  112. break;
  113. case 'config':
  114. $data = array(
  115. 'alink_position' => request_var('disp_pos', 1),
  116. 'alink_hidespeci' => request_var('hide_acc', 0),
  117. 'alink_pm_mode' => request_var('multi_pn', 1),
  118. );
  119. $validate_array = array(
  120. 'alink_position' => array('num', true, 0, 2),
  121. 'alink_pm_mode' => array('num', true, 0, 1),
  122. );
  123. $error = validate_data($data, $validate_array);
  124. if(!check_form_key('ucp_alink'))
  125. {
  126. $error[] = $user->lang['FORM_INVALID'];
  127. }
  128. if(!sizeof($error))
  129. {
  130. // save the settings
  131. $sql = 'UPDATE ' . USERS_TABLE . '
  132. SET ' . $db->sql_build_array('UPDATE', $data) . '
  133. WHERE user_id = ' . $user->data['user_id'];
  134. $db->sql_query($sql);
  135. meta_refresh(3, $this->u_action);
  136. $message = $user->lang['CONFIG_ALINK_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
  137. trigger_error($message);
  138. }
  139. break;
  140. }
  141. }
  142. break;
  143. case 'switch':
  144. $this->page_title = $user->lang['SWITCH_LINKED_ACCOUNTS'];
  145. $this->tpl_name = 'ucp_alink_switch';
  146. break;
  147. case 'create':
  148. if(!$auth->acl_get('u_alink_create'))
  149. {
  150. $error = $user->lang['ALINK_CREATE_FAILED'];
  151. add_log('user', 'LOG_ALINK_CREATE_FAILED', $master_name);
  152. // hammer time!
  153. trigger_error($error . $this->u_action);
  154. }
  155. $this->page_title = 'Create Linked Account';
  156. $this->tpl_name = 'ucp_alink_create';
  157. // not implemented
  158. $error = $user->lang['ACCOUNT_CREATE_MISSING'];
  159. add_log('user', 'LOG_ACCOUNT_CREATE_MISSING', $user->data['username'], implode(' ', $username_ary));
  160. // hammer time!
  161. trigger_error($error . $this->u_action);
  162. break;
  163. }
  164. add_form_key('ucp_alink');
  165. // fill up the global template variable
  166. $template->assign_vars(array(
  167. 'TITLE' => $user->lang['ACCOUNT_LINK'],
  168. 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
  169. 'MESSAGE' => (sizeof($message)) ? implode('<br />', $error) : '',
  170. 'IS_MASTER_ACCOUNT' => $is_master,
  171. 'L_NOT_MASTER' => sprintf($user->lang['NOT_MASTER'], $master_name),
  172. 'S_MASTER_NAME' => $master_name,
  173. 'S_ALINK_POSITION' => $user->data['alink_position'],
  174. 'S_ALINK_HIDE' => ($user->data['alink_hidespeci']) ? true : false,
  175. 'S_ALINK_PM_MODE' => ($user->data['alink_pm_mode']) ? true : false,
  176. 'S_UCP_ACTION' => ($mode=='switch') ? "{$phpbb_root_path}alink.{$phpEx}" : $this->u_action,
  177. ));
  178. }
  179. }
  180. ?>