PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/profile_options.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 307 lines | 226 code | 37 blank | 44 comment | 57 complexity | 21af5f5a75a35d5701c3b6a268a56e6b MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Ptirhiik (admin@rpgnet-fr.com)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  20. include(IP_ROOT_PATH . 'includes/class_form.' . PHP_EXT);
  21. $class_form = new class_form();
  22. // Start session management
  23. $user->session_begin();
  24. $auth->acl($user->data);
  25. $user->setup();
  26. // End session management
  27. if (!$user->data['session_logged_in'])
  28. {
  29. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=profile_options.' . PHP_EXT, true));
  30. }
  31. // constant
  32. $nav_separator = empty($nav_separator) ? (empty($lang['Nav_Separator']) ? '&nbsp;&raquo;&nbsp;' : $lang['Nav_Separator']) : $nav_separator;
  33. $sid = request_var('sid', '');
  34. $view_user_id = request_var('view_user_id', 0);
  35. $view_user_id = empty($view_user_id) ? request_var(POST_USERS_URL, 0) : $view_user_id;
  36. $target_userdata = array();
  37. if (empty($view_user_id) || ($view_user_id == ANONYMOUS))
  38. {
  39. $view_user_id = $user->data['user_id'];
  40. $target_userdata = $user->data;
  41. }
  42. else
  43. {
  44. $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = '" . $view_user_id . "'";
  45. $result = $db->sql_query($sql);
  46. if (!$target_userdata = $db->sql_fetchrow($result))
  47. {
  48. if (!defined('STATUS_404')) define('STATUS_404', true);
  49. message_die(GENERAL_INFO, $lang['NO_USER']);
  50. }
  51. $target_userdata['user_level'] = ($target_userdata['user_level'] == JUNIOR_ADMIN) ? ADMIN : $target_userdata['user_level'];
  52. }
  53. // Get the user level
  54. $user_level = $user->data['user_level'];
  55. if ($user_level == MOD)
  56. {
  57. if ($target_userdata['user_level'] == ADMIN)
  58. {
  59. $user_level = USER;
  60. }
  61. else
  62. {
  63. // Verify that the user is really a moderator (phpBB lack)
  64. $sql = "SELECT * FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug
  65. WHERE ug.user_id = " . $user->data['user_id'] . "
  66. AND aa.group_id = ug.group_id
  67. AND aa.auth_mod = 1
  68. AND ug.user_pending = 0
  69. LIMIT 0, 1";
  70. $db->sql_query($sql);
  71. if ($db->sql_numrows($result) <= 0)
  72. {
  73. $user_level = USER;
  74. }
  75. $db->sql_freeresult($result);
  76. }
  77. }
  78. // Check auth level
  79. if (($view_user_id != $user->data['user_id']) && ($user->data['user_level'] != ADMIN))
  80. {
  81. message_die(GENERAL_INFO, $lang['Wrong_Profile']);
  82. }
  83. // create entry if NULL: fix isset issue
  84. @reset($target_userdata);
  85. while (list($key, $data) = each($target_userdata))
  86. {
  87. if ($target_userdata[$key] == NULL)
  88. {
  89. $target_userdata[$key] = '';
  90. }
  91. }
  92. // main_menu
  93. $menu_name = request_var('data', '');
  94. if (empty($menu_name))
  95. {
  96. $menu_name = 'Preferences';
  97. }
  98. elseif (!isset($class_settings->modules[$menu_name]['data']))
  99. {
  100. // no mods
  101. $menu_name = '';
  102. }
  103. // mod_id
  104. $mod_id = request_var('mod_id', 0);
  105. $mod_id = empty($mod_id) ? request_var('mod', 0) : $mod_id;
  106. // sub_id
  107. $sub_id = request_var('mod_sub_id', 0);
  108. $sub_id = empty($sub_id) ? request_var('msub', 0) : $sub_id;
  109. // Build a key array
  110. $profile_modules = $class_settings->modules;
  111. $settings_modules_array = $class_settings->process_settings_modules($profile_modules, false, $target_userdata);
  112. $mod_ids = $settings_modules_array['mod_id'][0];
  113. $mod_keys = $settings_modules_array['mod_keys'][0];
  114. $mod_sort = $settings_modules_array['mod_sort'][0];
  115. $sub_keys = $settings_modules_array['sub_keys'][0];
  116. $sub_sort = $settings_modules_array['sub_sort'][0];
  117. $module_id = request_var('module', '');
  118. $module_id_found = false;
  119. if (!empty($module_id))
  120. {
  121. foreach ($mod_ids as $k => $v)
  122. {
  123. if (isset($v[$module_id]))
  124. {
  125. $mod_keys_flip = array_flip($mod_keys);
  126. $mod_id = $mod_keys_flip[$v[$module_id]];
  127. $module_id_found = true;
  128. break;
  129. }
  130. }
  131. }
  132. // We need to reset this var if not found... so we can use module to url append
  133. if (!$module_id_found)
  134. {
  135. $module_id = '';
  136. }
  137. // fix mod id
  138. if ($mod_id > sizeof($mod_keys))
  139. {
  140. $mod_id = 0;
  141. }
  142. if ($sub_id > sizeof($sub_keys[$mod_id]))
  143. {
  144. $sub_id = 0;
  145. }
  146. // mod name
  147. $mod_name = $mod_keys[$mod_id];
  148. // sub name
  149. $sub_name = $sub_keys[$mod_id][$sub_id];
  150. // buttons
  151. $submit = isset($_POST['submit']) ? true : false;
  152. // create the back link
  153. $return_link = append_sid('profile_options.' . PHP_EXT . '?sub=' . strtolower($menu_name) . '&amp;' . (!empty($module_id) ? ('module=' . $module_id) : ('mod=' . $mod_id)) . '&amp;msub=' . $sub_id . '&amp;' . POST_USERS_URL . '=' . $view_user_id);
  154. // validate
  155. if ($submit)
  156. {
  157. // session id check
  158. if ($sid != $user->data['session_id'])
  159. {
  160. message_die(GENERAL_ERROR, 'INVALID_SESSION');
  161. }
  162. // init for error
  163. $error = false;
  164. $error_msg = '';
  165. // format and verify data
  166. @reset($class_settings->modules[$menu_name]['data'][$mod_name]['data'][$sub_name]['data']);
  167. while (list($config_name, $config_data) = @each($class_settings->modules[$menu_name]['data'][$mod_name]['data'][$sub_name]['data']))
  168. {
  169. if (isset($_POST[$config_data['user']]) && $class_settings->is_auth($config_data['auth']))
  170. {
  171. $config_data['name'] = $config_data['user'];
  172. $config_data['default'] = $_POST[$config_data['user']];
  173. $config_value = $class_form->validate_value($config_data);
  174. if ((isset($target_userdata[$config_data['name']]) && (!$config[$config_name . '_over'] || ($user->data['user_level'] == ADMIN))) || $config_data['system'])
  175. {
  176. // update
  177. $sql = "UPDATE " . USERS_TABLE . "
  178. SET " . $config_data['name'] . " = '" . $db->sql_escape($config_value) . "'
  179. WHERE user_id = " . $target_userdata['user_id'];
  180. $db->sql_query($sql);
  181. }
  182. }
  183. }
  184. // send an update message
  185. $redirect_url = $return_link;
  186. meta_refresh(3, $redirect_url);
  187. $message = $lang['Profile_updated'] . '<br /><br />' . sprintf($lang['Click_return_preferences'], '<a href="' . $return_link . '">', '</a>') . '<br /><br />';
  188. message_die(GENERAL_MESSAGE, $message);
  189. }
  190. else
  191. {
  192. $pcp_section = $class_settings->get_lang($mod_name) . (!empty($sub_name) ? ' - ' . $class_settings->get_lang($sub_name) : '');
  193. $link_name = $pcp_section;
  194. $nav_server_url = create_server_url();
  195. $breadcrumbs['address'] = $nav_separator . '<a href="' . $nav_server_url . append_sid(CMS_PAGE_PROFILE_MAIN) . '"' . (!empty($link_name) ? '' : ' class="nav-current"') . '>' . $lang['Profile'] . '</a>' . (!empty($link_name) ? ($nav_separator . '<a class="nav-current" href="' . $nav_server_url . $return_link . '">' . $link_name . '</a>') : '');
  196. include_once(IP_ROOT_PATH . 'includes/users_zebra_block.' . PHP_EXT);
  197. // header
  198. $template->assign_vars(array(
  199. 'L_OPTION' => $meta_content['page_title'],
  200. 'U_OPTION' => $return_link,
  201. 'L_MOD_NAME' => $pcp_section,
  202. 'U_USER' => append_sid(CMS_PAGE_PROFILE . '?mode=viewprofile&amp;' . POST_USERS_URL . '=' . $view_user_id),
  203. 'L_USER' => $target_userdata['username'],
  204. 'L_SUBMIT' => $lang['Submit'],
  205. 'L_RESET' => $lang['Reset'],
  206. )
  207. );
  208. // send menu
  209. for ($i = 0; $i < sizeof($mod_keys); $i++)
  210. {
  211. $template->assign_block_vars('mod', array(
  212. 'CLASS' => ($mod_id == $i) ? $theme['td_class1'] : $theme['td_class2'],
  213. 'ALIGN' => (($mod_id == $i) && (sizeof($sub_keys[$i]) > 1)) ? 'left' : 'center',
  214. 'U_MOD' => append_sid('./profile_options.' . PHP_EXT . '?sub=' . $menu_name . '&mod=' . $i . '&amp;' . POST_USERS_URL . '=' . $view_user_id),
  215. 'L_MOD' => sprintf((($mod_id == $i) ? '<b>%s</b>' : '%s'), $class_settings->get_lang($mod_keys[$i])),
  216. )
  217. );
  218. if ($mod_id == $i)
  219. {
  220. if (sizeof($sub_keys[$i]) > 1)
  221. {
  222. $template->assign_block_vars('mod.sub', array());
  223. for ($j=0; $j < sizeof($sub_keys[$i]); $j++)
  224. {
  225. $template->assign_block_vars('mod.sub.row', array(
  226. 'CLASS' => ($sub_id == $j) ? $theme['td_class1'] : $theme['td_class2'],
  227. 'U_MOD' => append_sid('./profile_options.' . PHP_EXT . '?sub=' . $menu_name . '&amp;mod=' . $i . '&amp;msub=' . $j . '&amp;' . POST_USERS_URL . '=' . $view_user_id),
  228. 'L_MOD' => sprintf((($sub_id == $j) ? '<b>%s</b>' : '%s'), $class_settings->get_lang($sub_keys[$i][$j])),
  229. )
  230. );
  231. }
  232. }
  233. }
  234. }
  235. // send items
  236. @reset($class_settings->modules[$menu_name]['data'][$mod_name]['data'][$sub_name]['data']);
  237. while (list($config_name, $config_data) = @each($class_settings->modules[$menu_name]['data'][$mod_name]['data'][$sub_name]['data']))
  238. {
  239. // process only fields from users table
  240. $user_field = $config_data['user'];
  241. if (((!empty($user_field) && isset($target_userdata[$user_field]) && (!$config[$config_name . '_over'] || ($user->data['user_level'] == ADMIN))) || $config_data['system']) && $class_settings->is_auth($config_data['auth'], $user_level))
  242. {
  243. $config_data['name'] = $config_data['user'];
  244. $config_data['default'] = $target_userdata[$user_field];
  245. $input = $class_form->create_input($config_data['name'], $config_data);
  246. // dump to template
  247. $template->assign_block_vars('field', array(
  248. 'L_NAME' => $class_settings->get_lang($config_data['lang_key']),
  249. 'L_EXPLAIN' => !empty($config_data['explain']) ? $class_settings->get_lang($config_data['explain']) : '',
  250. 'INPUT' => $input,
  251. )
  252. );
  253. }
  254. }
  255. // system
  256. $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $user->data['session_id'] . '" />';
  257. $s_hidden_fields .= '<input type="hidden" name="view_user_id" value="' . $view_user_id . '" />';
  258. $s_hidden_fields .= '<input type="hidden" name="sub" value="' . $menu_name . '" />';
  259. $s_hidden_fields .= '<input type="hidden" name="mod_id" value="' . $mod_id . '" />';
  260. $s_hidden_fields .= '<input type="hidden" name="mod_sub_id" value="' . $sub_id . '" />';
  261. $s_hidden_fields .= '<input type="hidden" name="set" value="add" />';
  262. $template->assign_vars(array(
  263. 'S_PROFILCP_ACTION' => append_sid('profile_options.' . PHP_EXT),
  264. 'NAV_SEPARATOR' => $nav_separator,
  265. 'S_HIDDEN_FIELDS' => $s_hidden_fields,
  266. )
  267. );
  268. full_page_generation('profile_options_body.tpl', $lang['Preferences'], '', '');
  269. }
  270. ?>