PageRenderTime 73ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/html/AppCode/expressionengine/controllers/cp/members.php

https://github.com/w3bg/www.hsifin.com
PHP | 3624 lines | 2580 code | 628 blank | 416 comment | 283 complexity | 55b807b074fb952faf09d58201e3bcdc MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author ExpressionEngine Dev Team
  7. * @copyright Copyright (c) 2003 - 2010, EllisLab, Inc.
  8. * @license http://expressionengine.com/user_guide/license.html
  9. * @link http://expressionengine.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Member Management Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Control Panel
  19. * @category Control Panel
  20. * @author ExpressionEngine Dev Team
  21. * @link http://expressionengine.com
  22. */
  23. class Members extends Controller {
  24. // Default member groups. We used these for translation purposes
  25. var $english = array('Guests', 'Banned', 'Members', 'Pending', 'Super Admins');
  26. var $no_delete = array('1', '2', '3', '4'); // Member groups that can not be deleted
  27. var $perpage = 50; // Number of results on the "View all member" page
  28. var $pipe_length = 5;
  29. /**
  30. * Constructor
  31. *
  32. * @access public
  33. */
  34. function Members()
  35. {
  36. parent::Controller();
  37. if ( ! $this->cp->allowed_group('can_access_members'))
  38. {
  39. show_error($this->lang->line('unauthorized_access'));
  40. }
  41. $this->lang->loadfile('members');
  42. $this->load->model('member_model');
  43. }
  44. // --------------------------------------------------------------------
  45. /**
  46. * Index function
  47. *
  48. * @access public
  49. * @return mixed
  50. */
  51. function index()
  52. {
  53. if ( ! $this->cp->allowed_group('can_access_members'))
  54. {
  55. show_error($this->lang->line('unauthorized_access'));
  56. }
  57. $this->cp->set_variable('cp_page_title', $this->lang->line('members'));
  58. $this->javascript->compile();
  59. $this->load->vars(array('controller'=>'members'));
  60. $this->load->view('_shared/overview');
  61. }
  62. // --------------------------------------------------------------------
  63. /**
  64. * View all members
  65. *
  66. * @access public
  67. * @return mixed
  68. */
  69. function view_all_members()
  70. {
  71. if ( ! $this->cp->allowed_group('can_access_members'))
  72. {
  73. show_error($this->lang->line('unauthorized_access'));
  74. }
  75. $message = $this->session->flashdata('message');
  76. $this->load->library('table');
  77. $this->load->library('pagination');
  78. $this->load->helper('form');
  79. $this->cp->set_variable('cp_page_title', $this->lang->line('view_members'));
  80. $this->cp->add_js_script(array('plugin' => 'dataTables'));
  81. $this->javascript->output('
  82. $("#filter_member_submit").hide();
  83. $(".toggle_all").toggle(
  84. function(){
  85. $("input.toggle").each(function() {
  86. this.checked = true;
  87. });
  88. }, function (){
  89. var checked_status = this.checked;
  90. $("input.toggle").each(function() {
  91. this.checked = false;
  92. });
  93. }
  94. );
  95. ');
  96. // These variables are only set when one of the pull-down menus is used
  97. // We use it to construct the SQL query with
  98. $group_id = ($this->input->get_post('group_id')) ? $this->input->get_post('group_id') : '';
  99. $order = $this->input->get_post('order');
  100. $vars['column_filter_options'] = array(
  101. 'all' => $this->lang->line('all'),
  102. 'screen_name' => $this->lang->line('screen_name'),
  103. 'username' => $this->lang->line('username'),
  104. 'email' => $this->lang->line('email')
  105. );
  106. $vars['column_filter_selected'] = ($this->input->get_post('column_filter')) ? $this->input->get_post('column_filter') : 'all';
  107. // Repopulate Search Box ?
  108. $member_name = $this->input->get_post('member_name') ? $this->input->get_post('member_name') : '';
  109. $per_page = ($this->input->get('per_page') != '') ? $this->input->get('per_page') : '0';
  110. // remember previously selected values
  111. $vars['selected_group'] = $group_id;
  112. // start blank, and add any we need as we go
  113. $vars['message'] = $message;
  114. // get all member groups for the dropdown list
  115. $member_groups = $this->member_model->get_member_groups();
  116. // first dropdown item is "all"
  117. $vars['member_groups_dropdown'] = array('' => $this->lang->line('all'));
  118. foreach($member_groups->result() as $group)
  119. {
  120. $vars['member_groups_dropdown'][$group->group_id] = $group->group_title;
  121. }
  122. $vars['member_list'] = $this->member_model->get_members($group_id, $this->config->item('memberlist_row_limit'), $per_page, $member_name);
  123. if ($vars['member_list'] === FALSE)
  124. {
  125. $vars['total_members'] = 0;
  126. }
  127. else
  128. {
  129. $vars['total_members'] = $this->member_model->count_members($group_id, $member_name);
  130. }
  131. // if we're looking at group 4 (pending), and require email activation, let's also give the option to resend their activation emails
  132. if ($group_id == '4' && $this->config->item('req_mbr_activation') == 'email' && $this->cp->allowed_group('can_admin_members'))
  133. {
  134. $vars['member_action_options'] = array('delete' => $this->lang->line('delete_selected'), 'resend' => $this->lang->line('resend_activation_emails'));
  135. $vars['delete_button_label'] = $this->lang->line('submit');
  136. }
  137. else
  138. {
  139. $vars['member_action_options'] = array();
  140. $vars['form_hidden']['action'] = 'delete';
  141. $vars['delete_button_label'] = $this->lang->line('delete_selected');
  142. }
  143. // creating a member automatically fills the search box
  144. if ( ! $member_name && ! $member_name = $this->session->flashdata('username'))
  145. {
  146. $member_name = '';
  147. }
  148. $vars['member_name'] = $member_name;
  149. // Pagination stuff
  150. $group_pagination = ($this->input->get_post('group_id')) ? AMP.'group_id='.$group_id : '';
  151. $member_pagination = ($this->input->get_post('member_name')) ? AMP.'member_name='.$group_id : '';
  152. $config['base_url'] = BASE.AMP.'C=members'.AMP.'M=view_all_members'.$group_pagination.$member_pagination;
  153. $config['total_rows'] = $vars['total_members'];
  154. $config['per_page'] = $this->config->item('memberlist_row_limit');
  155. $config['page_query_string'] = TRUE;
  156. $config['full_tag_open'] = '<p id="paginationLinks">';
  157. $config['full_tag_close'] = '</p>';
  158. $config['prev_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_prev_button.gif" width="13" height="13" alt="&lt;" />';
  159. $config['next_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_next_button.gif" width="13" height="13" alt="&gt;" />';
  160. $config['first_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_first_button.gif" width="13" height="13" alt="&lt; &lt;" />';
  161. $config['last_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_last_button.gif" width="13" height="13" alt="&gt; &gt;" />';
  162. $this->pagination->initialize($config);
  163. $vars['pagination'] = $this->pagination->create_links();
  164. //$this->jquery->dataTables('.mainTable');
  165. $this->javascript->output('
  166. var oCache = {
  167. iCacheLower: -1
  168. };
  169. function fnSetKey( aoData, sKey, mValue )
  170. {
  171. for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  172. {
  173. if ( aoData[i].name == sKey )
  174. {
  175. aoData[i].value = mValue;
  176. }
  177. }
  178. }
  179. function fnGetKey( aoData, sKey )
  180. {
  181. for ( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  182. {
  183. if ( aoData[i].name == sKey )
  184. {
  185. return aoData[i].value;
  186. }
  187. }
  188. return null;
  189. }
  190. function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
  191. var iPipe = '.$this->pipe_length.'; /* Adjust the pipe size */
  192. var bNeedServer = false;
  193. var sEcho = fnGetKey(aoData, "sEcho");
  194. var iRequestStart = fnGetKey(aoData, "iDisplayStart");
  195. var iRequestLength = fnGetKey(aoData, "iDisplayLength");
  196. var iRequestEnd = iRequestStart + iRequestLength;
  197. var k_search = document.getElementById("member_name");
  198. var group = document.getElementById("group_id");
  199. var column_filter = document.getElementById("column_filter");
  200. aoData.push(
  201. { "name": "k_search", "value": k_search.value },
  202. { "name": "group", "value": group.value },
  203. { "name": "column_filter", "value": column_filter.value }
  204. );
  205. oCache.iDisplayStart = iRequestStart;
  206. /* outside pipeline? */
  207. if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
  208. {
  209. bNeedServer = true;
  210. }
  211. /* sorting etc changed? */
  212. if ( oCache.lastRequest && !bNeedServer )
  213. {
  214. for( var i=0, iLen=aoData.length ; i<iLen ; i++ )
  215. {
  216. if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" )
  217. {
  218. if ( aoData[i].value != oCache.lastRequest[i].value )
  219. {
  220. bNeedServer = true;
  221. break;
  222. }
  223. }
  224. }
  225. }
  226. /* Store the request for checking next time around */
  227. oCache.lastRequest = aoData.slice();
  228. if ( bNeedServer )
  229. {
  230. if ( iRequestStart < oCache.iCacheLower )
  231. {
  232. iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
  233. if ( iRequestStart < 0 )
  234. {
  235. iRequestStart = 0;
  236. }
  237. }
  238. oCache.iCacheLower = iRequestStart;
  239. oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
  240. oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
  241. fnSetKey( aoData, "iDisplayStart", iRequestStart );
  242. fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
  243. aoData.push(
  244. { "name": "k_search", "value": k_search.value },
  245. { "name": "group", "value": group.value },
  246. { "name": "column_filter", "value": column_filter.value }
  247. );
  248. $.getJSON( sSource, aoData, function (json) {
  249. /* Callback processing */
  250. oCache.lastJson = jQuery.extend(true, {}, json);
  251. if ( oCache.iCacheLower != oCache.iDisplayStart )
  252. {
  253. json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
  254. }
  255. json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
  256. fnCallback(json)
  257. } );
  258. }
  259. else
  260. {
  261. json = jQuery.extend(true, {}, oCache.lastJson);
  262. json.sEcho = sEcho; /* Update the echo for each response */
  263. json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
  264. json.aaData.splice( iRequestLength, json.aaData.length );
  265. fnCallback(json);
  266. return;
  267. }
  268. }
  269. oTable = $(".mainTable").dataTable( {
  270. "sPaginationType": "full_numbers",
  271. "bLengthChange": false,
  272. "bFilter": false,
  273. "sWrapper": false,
  274. "sInfo": false,
  275. "bAutoWidth": false,
  276. "iDisplayLength": '.$this->perpage.',
  277. "aoColumns": [null, null, null, null, null, { "bSortable" : false }, { "bSortable" : false } ],
  278. "oLanguage": {
  279. "sZeroRecords": "'.$this->lang->line('no_members_matching_that_criteria').'",
  280. "oPaginate": {
  281. "sFirst": "<img src=\"'.$this->cp->cp_theme_url.'images/pagination_first_button.gif\" width=\"13\" height=\"13\" alt=\"&lt; &lt;\" />",
  282. "sPrevious": "<img src=\"'.$this->cp->cp_theme_url.'images/pagination_prev_button.gif\" width=\"13\" height=\"13\" alt=\"&lt; &lt;\" />",
  283. "sNext": "<img src=\"'.$this->cp->cp_theme_url.'images/pagination_next_button.gif\" width=\"13\" height=\"13\" alt=\"&lt; &lt;\" />",
  284. "sLast": "<img src=\"'.$this->cp->cp_theme_url.'images/pagination_last_button.gif\" width=\"13\" height=\"13\" alt=\"&lt; &lt;\" />"
  285. }
  286. },
  287. "bProcessing": true,
  288. "bServerSide": true,
  289. "sAjaxSource": EE.BASE+"&C=members&M=member_search",
  290. "fnServerData": fnDataTablesPipeline
  291. } );
  292. $("#member_name").bind("keyup blur paste", function (e) {
  293. /* Filter on the column (the index) of this element */
  294. setTimeout(function(){oTable.fnDraw();}, 1);
  295. });
  296. $("#member_form").submit(function() {
  297. oTable.fnDraw();
  298. return false;
  299. });
  300. $("select#group_id").change(function () {
  301. oTable.fnDraw();
  302. if ($(this).val() == 4)
  303. {
  304. $("#member_action_options").show();
  305. }
  306. });
  307. $("select#column_filter").change(function () {
  308. oTable.fnDraw();
  309. });
  310. ');
  311. $this->javascript->compile();
  312. $this->load->view('members/view_members', $vars);
  313. }
  314. function member_search()
  315. {
  316. if ( ! $this->cp->allowed_group('can_access_members'))
  317. {
  318. show_error($this->lang->line('unauthorized_access'));
  319. }
  320. $this->output->enable_profiler(FALSE);
  321. $col_map = array('username', 'screen_name', 'email', 'join_date', 'last_visit');
  322. $search_value = ($this->input->get_post('k_search')) ? $this->input->get_post('k_search') : '';
  323. $group_id = ($this->input->get_post('group')) ? $this->input->get_post('group') : '';
  324. // Note- we pipeline the js, so pull more data than are displayed on the page
  325. $perpage = $this->input->get_post('iDisplayLength');
  326. $offset = ($this->input->get_post('iDisplayStart')) ? $this->input->get_post('iDisplayStart') : 0; // Display start point
  327. $sEcho = $this->input->get_post('sEcho');
  328. /* Ordering */
  329. $order = array();
  330. if ($this->input->get('iSortCol_0') !== FALSE)
  331. {
  332. for ( $i=0; $i < $this->input->get('iSortingCols'); $i++ )
  333. {
  334. if (isset($col_map[$this->input->get('iSortCol_'.$i)]))
  335. {
  336. $order[$col_map[$this->input->get('iSortCol_'.$i)]] = ($this->input->get('sSortDir_'.$i) == 'asc') ? 'asc' : 'desc';
  337. }
  338. }
  339. }
  340. $column_filter = ($this->input->get_post('column_filter')) ? $this->input->get_post('column_filter') : 'all';
  341. $members = $this->member_model->get_members($group_id, $perpage, $offset, $search_value, $order, $column_filter);
  342. $total = $this->member_model->count_members();
  343. $f_total = $this->member_model->count_members($group_id, $search_value, $column_filter);
  344. $j_response['sEcho'] = $sEcho;
  345. $j_response['iTotalRecords'] = $total;
  346. $j_response['iTotalDisplayRecords'] = $f_total;
  347. // Get the group titles- we need this in the display
  348. $member_groups = $this->member_model->get_member_groups();
  349. $groups = array();
  350. foreach($member_groups->result() as $group)
  351. {
  352. $groups[$group->group_id] = $group->group_title;
  353. }
  354. $tdata = array();
  355. $i = 0;
  356. if ($members !== FALSE)
  357. {
  358. foreach ($members->result_array() as $k => $member)
  359. {
  360. $m[] = '<a href="'.BASE.AMP.'C=myaccount'.AMP.'id='.$member['member_id'].'">'.$member['username'].'</a>';
  361. $m[] = $member['screen_name'];
  362. $m[] = '<a href="mailto:'.$member['email'].'">'.$member['email'].'</a>';
  363. $m[] = $this->localize->convert_timestamp('%Y', $member['join_date']).'-'.
  364. $this->localize->convert_timestamp('%m', $member['join_date']).'-'.
  365. $this->localize->convert_timestamp('%d', $member['join_date']);
  366. $m[] = ($member['last_visit'] == 0) ? ' - ' : $this->localize->set_human_time($member['last_visit']);
  367. $m[] = $groups[$member['group_id']];
  368. $m[] = '<input class="toggle" type="checkbox" name="toggle[]" value="'.$member['member_id'].'" />';
  369. $tdata[$i] = $m;
  370. $i++;
  371. unset($m);
  372. }
  373. }
  374. $j_response['aaData'] = $tdata;
  375. $sOutput = $this->javascript->generate_json($j_response, TRUE);
  376. exit($sOutput);
  377. }
  378. // --------------------------------------------------------------------
  379. /**
  380. * Member Confirm
  381. *
  382. * Used to choose between emailing or deleting
  383. *
  384. * @access public
  385. * @return mixed
  386. */
  387. function member_confirm()
  388. {
  389. if ( ! $this->cp->allowed_group('can_access_members'))
  390. {
  391. show_error($this->lang->line('unauthorized_access'));
  392. }
  393. if ($this->input->post('action') == 'resend')
  394. {
  395. $this->resend_activation_emails();
  396. }
  397. else
  398. {
  399. $this->member_delete_confirm();
  400. }
  401. }
  402. // --------------------------------------------------------------------
  403. /**
  404. * Resend Activation Emails
  405. *
  406. * Resend Pending Member's Activation Emails
  407. *
  408. * @access public
  409. * @return mixed
  410. */
  411. function resend_activation_emails()
  412. {
  413. if ( ! $this->cp->allowed_group('can_access_members') OR $this->config->item('req_mbr_activation') !== 'email')
  414. {
  415. show_error($this->lang->line('unauthorized_access'));
  416. }
  417. if ($this->input->get('mid') !== FALSE)
  418. {
  419. $_POST['toggle'][] = $this->input->get('mid');
  420. }
  421. if ( ! $this->input->post('toggle'))
  422. {
  423. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  424. }
  425. $damned = array();
  426. foreach ($_POST['toggle'] as $key => $val)
  427. {
  428. $damned[] = $val;
  429. }
  430. if (count($damned) == 0)
  431. {
  432. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  433. }
  434. $this->load->library('email');
  435. $this->load->helper('text');
  436. $this->db->select('screen_name, username, email, authcode');
  437. $this->db->where_in('member_id', $damned);
  438. $query = $this->db->get('members');
  439. if ($query->num_rows() == 0)
  440. {
  441. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  442. }
  443. $action_id = $this->functions->fetch_action_id('Member', 'activate_member');
  444. $template = $this->functions->fetch_email_template('mbr_activation_instructions');
  445. $swap = array(
  446. 'site_name' => stripslashes($this->config->item('site_name')),
  447. 'site_url' => $this->config->item('site_url')
  448. );
  449. foreach($query->result_array() as $row)
  450. {
  451. $swap['name'] = ($row['screen_name'] != '') ? $row['screen_name'] : $row['username'];
  452. $swap['activation_url'] = $this->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$action_id.'&id='.$row['authcode'];
  453. $swap['username'] = $row['username'];
  454. $swap['email'] = $row['email'];
  455. // Send email
  456. $this->email->EE_initialize();
  457. $this->email->wordwrap = TRUE;
  458. $this->email->from($this->config->item('webmaster_email'), $this->config->item('webmaster_name'));
  459. $this->email->to($row['email']);
  460. $this->email->subject($this->functions->var_swap($template['title'], $swap));
  461. $this->email->message(entities_to_ascii($this->functions->var_swap($template['data'], $swap)));
  462. $this->email->send();
  463. }
  464. $this->session->set_flashdata('message_success', $this->lang->line(($this->input->get('mid') !== FALSE) ? 'activation_email_resent' : 'activation_emails_resent'));
  465. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  466. }
  467. // --------------------------------------------------------------------
  468. /**
  469. * Delete Member (confirm)
  470. *
  471. * Warning message if you try to delete members
  472. *
  473. * @access public
  474. * @return mixed
  475. */
  476. function member_delete_confirm()
  477. {
  478. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_delete_members'))
  479. {
  480. show_error($this->lang->line('unauthorized_access'));
  481. }
  482. $this->load->helper('form');
  483. $from_myaccount = FALSE;
  484. if ($this->input->get('mid') != '')
  485. {
  486. $from_myaccount = TRUE;
  487. $_POST['toggle'][] = $this->input->get('mid');
  488. }
  489. if ( ! isset($_POST['toggle']))
  490. {
  491. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  492. }
  493. if ( ! is_array($_POST['toggle']) OR count($_POST['toggle']) == 0)
  494. {
  495. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  496. }
  497. $damned = array();
  498. $vars['ids_delete'] = array();
  499. foreach ($this->input->post('toggle') as $key => $val)
  500. {
  501. // Is the user trying to delete himself?
  502. if ($this->session->userdata('member_id') == $val)
  503. {
  504. show_error($this->lang->line('can_not_delete_self'));
  505. }
  506. $damned[] = $val;
  507. }
  508. // Pass the damned on for judgement
  509. $vars['damned'] = $damned;
  510. if (count($damned) == 1)
  511. {
  512. $vars['user_name'] = $this->member_model->get_username($damned['0']);
  513. }
  514. else
  515. {
  516. $vars['user_name'] = '';
  517. }
  518. // Do the users being deleted have entries assigned to them?
  519. // If so, fetch the member names for reassigment
  520. $vars['heirs'] = array();
  521. if ($this->member_model->count_member_entries($damned) > 0)
  522. {
  523. $group_ids = $this->member_model->get_members_group_ids($damned);
  524. // Find Valid Member Replacements
  525. $this->db->select('member_id, username, screen_name');
  526. $this->db->from('members');
  527. $this->db->where_in('member_id', $group_ids);
  528. $this->db->where_not_in('member_id', $damned);
  529. $this->db->order_by('screen_name');
  530. $heirs = $this->db->get();
  531. foreach($heirs->result() as $heir)
  532. {
  533. $name_to_use = ($heir->screen_name != '') ? $heir->screen_name : $heir->username;
  534. $vars['heirs'][$heir->member_id] = $name_to_use;
  535. }
  536. }
  537. $this->cp->set_variable('cp_page_title', $this->lang->line('delete_member'));
  538. $this->load->view('members/delete_confirm', $vars);
  539. }
  540. // --------------------------------------------------------------------
  541. /**
  542. * Login as Member
  543. *
  544. * Login as Member - SuperAdmins only!
  545. *
  546. * @access public
  547. * @return mixed
  548. */
  549. function login_as_member()
  550. {
  551. if ($this->session->userdata('group_id') != 1)
  552. {
  553. show_error($this->lang->line('unauthorized_access'));
  554. }
  555. $this->lang->loadfile('myaccount');
  556. $id = $this->input->get('mid');
  557. if ($id == '')
  558. {
  559. show_error($this->lang->line('unauthorized_access'));
  560. }
  561. if ($this->session->userdata['member_id'] == $id)
  562. {
  563. show_error($this->lang->line('unauthorized_access'));
  564. }
  565. $this->load->helper('form');
  566. $this->cp->set_variable('cp_page_title', $this->lang->line('login_as_member'));
  567. // Fetch member data
  568. $this->db->from('members, member_groups');
  569. $this->db->select('members.screen_name, member_groups.can_access_cp');
  570. $this->db->where('member_id', $id);
  571. $this->db->where('member_groups.site_id', $this->config->item('site_id'));
  572. $this->db->where('members.group_id = '.$this->db->dbprefix('member_groups.group_id'));
  573. $query = $this->db->get();
  574. if ($query->num_rows() == 0)
  575. {
  576. show_error($this->lang->line('unauthorized_access'));
  577. }
  578. $vars['message'] = str_replace('%screen_name%', $query->row('screen_name') , $this->lang->line('login_as_member_description'));
  579. $vars['form_hidden']['mid'] = $id;
  580. $vars['can_access_cp'] = ($query->row('can_access_cp') == 'y') ? TRUE : FALSE;
  581. $this->load->view('members/login_as_member', $vars);
  582. }
  583. // --------------------------------------------------------------------
  584. /**
  585. * Do Login as Member
  586. *
  587. * Do Login as Member - SuperAdmins only!
  588. *
  589. * @access public
  590. * @return mixed
  591. */
  592. function do_login_as_member()
  593. {
  594. if ($this->session->userdata['group_id'] != 1)
  595. {
  596. show_error($this->lang->line('unauthorized_access'));
  597. }
  598. $id = $this->input->get_post('mid');
  599. if ($id == '')
  600. {
  601. show_error($this->lang->line('unauthorized_access'));
  602. }
  603. if ($this->session->userdata['member_id'] == $id)
  604. {
  605. show_error($this->lang->line('unauthorized_access'));
  606. }
  607. // Fetch member data
  608. $this->db->from('members, member_groups');
  609. $this->db->select('members.username, members.password, members.unique_id, members.member_id, members.group_id, member_groups.can_access_cp');
  610. $this->db->where('member_id', $id);
  611. $this->db->where('member_groups.site_id', $this->config->item('site_id'));
  612. $this->db->where('members.group_id = '.$this->db->dbprefix('member_groups.group_id'));
  613. $query = $this->db->get();
  614. if ($query->num_rows() == 0)
  615. {
  616. show_error($this->lang->line('unauthorized_access'));
  617. }
  618. $this->lang->loadfile('login');
  619. // Do we allow multiple logins on the same account?
  620. if ($this->config->item('allow_multi_logins') == 'n')
  621. {
  622. // Kill old sessions first
  623. $this->session->gc_probability = 100;
  624. $this->session->delete_old_sessions();
  625. $expire = time() - $this->session->session_length;
  626. // See if there is a current session
  627. $this->db->select('ip_address, user_agent');
  628. $this->db->where('member_id', $query->row('member_id'));
  629. $this->db->where('last_activity >', $expire);
  630. $result = $this->db->get('sessions');
  631. // If a session exists, trigger the error message
  632. if ($result->num_rows() == 1)
  633. {
  634. if ($this->session->userdata['ip_address'] != $result->row('ip_address') OR
  635. $this->session->userdata['user_agent'] != $result->row('user_agent') )
  636. {
  637. show_error($this->lang->line('multi_login_warning'));
  638. }
  639. }
  640. }
  641. // Log the SuperAdmin login
  642. $this->logger->log_action($this->lang->line('login_as_user').':'.NBS.$query->row('username') );
  643. // Set cookie expiration to one year if the "remember me" button is clicked
  644. $expire = 0;
  645. $type = (isset($_POST['return_destination']) && $_POST['return_destination'] == 'cp') ? $this->config->item('admin_session_type') : $this->config->item('user_session_type');
  646. if ($type != 's')
  647. {
  648. $this->functions->set_cookie($this->session->c_expire , time()+$expire, $expire);
  649. $this->functions->set_cookie($this->session->c_uniqueid , $query->row('unique_id') , $expire);
  650. $this->functions->set_cookie($this->session->c_password , $query->row('password') , $expire);
  651. $this->functions->set_cookie($this->session->c_anon , 1, $expire);
  652. }
  653. // Create a new session
  654. $session_id = $this->session->create_new_session($query->row('member_id') , TRUE);
  655. // Delete old password lockouts
  656. $this->session->delete_password_lockout();
  657. // Redirect the user to the return page
  658. $return_path = $this->functions->fetch_site_index();
  659. if (isset($_POST['return_destination']))
  660. {
  661. if ($_POST['return_destination'] == 'cp')
  662. {
  663. $s = ($this->config->item('admin_session_type') != 'c') ? $this->session->userdata['session_id'] : 0;
  664. $return_path = $this->config->item('cp_url', FALSE).'?S='.$s;
  665. }
  666. elseif ($_POST['return_destination'] == 'other' && isset($_POST['other_url']) && stristr($_POST['other_url'], 'http'))
  667. {
  668. $return_path = $this->security->xss_clean(strip_tags($_POST['other_url']));
  669. }
  670. }
  671. $this->functions->redirect($return_path);
  672. }
  673. // --------------------------------------------------------------------
  674. /**
  675. * Member Delete
  676. *
  677. * Delete Members
  678. *
  679. * @access public
  680. * @return mixed
  681. */
  682. function member_delete()
  683. {
  684. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_delete_members'))
  685. {
  686. show_error($this->lang->line('unauthorized_access'));
  687. }
  688. if ( ! $this->input->post('delete') OR ! is_array($this->input->post('delete')))
  689. {
  690. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  691. }
  692. $this->load->model('member_model');
  693. // Fetch member ID numbers and build the query
  694. $ids = array();
  695. $mids = array();
  696. foreach ($this->input->post('delete') as $key => $val)
  697. {
  698. if ($val != '')
  699. {
  700. $ids[] = "member_id = '".$this->db->escape_str($val)."'";
  701. $mids[] = $this->db->escape_str($val);
  702. }
  703. }
  704. $IDS = implode(" OR ", $ids);
  705. // SAFETY CHECK
  706. // Let's fetch the Member Group ID of each member being deleted
  707. // If there is a Super Admin in the bunch we'll run a few more safeties
  708. $super_admins = 0;
  709. $query = $this->db->query("SELECT group_id FROM exp_members WHERE ".$IDS);
  710. foreach ($query->result_array() as $row)
  711. {
  712. if ($query->row('group_id') == 1)
  713. {
  714. $super_admins++;
  715. }
  716. }
  717. if ($super_admins > 0)
  718. {
  719. // You must be a Super Admin to delete a Super Admin
  720. if ($this->session->userdata['group_id'] != 1)
  721. {
  722. show_error($this->lang->line('must_be_superadmin_to_delete_one'));
  723. }
  724. // You can't delete the only Super Admin
  725. $query = $this->member_model->count_members(1);
  726. if ($super_admins >= $query)
  727. {
  728. show_error($this->lang->line('can_not_delete_super_admin'));
  729. }
  730. }
  731. // If we got this far we're clear to delete the members
  732. $this->db->query("DELETE FROM exp_members WHERE ".$IDS);
  733. $this->db->query("DELETE FROM exp_member_data WHERE ".$IDS);
  734. $this->db->query("DELETE FROM exp_member_homepage WHERE ".$IDS);
  735. foreach($mids as $val)
  736. {
  737. $message_query = $this->db->query("SELECT DISTINCT recipient_id FROM exp_message_copies WHERE sender_id = '$val' AND message_read = 'n'");
  738. $this->db->query("DELETE FROM exp_message_copies WHERE sender_id = '$val'");
  739. $this->db->query("DELETE FROM exp_message_data WHERE sender_id = '$val'");
  740. $this->db->query("DELETE FROM exp_message_folders WHERE member_id = '$val'");
  741. $this->db->query("DELETE FROM exp_message_listed WHERE member_id = '$val'");
  742. if ($message_query->num_rows() > 0)
  743. {
  744. foreach($message_query->result_array() as $row)
  745. {
  746. $count_query = $this->db->query("SELECT COUNT(*) AS count FROM exp_message_copies WHERE recipient_id = '".$row['recipient_id']."' AND message_read = 'n'");
  747. $this->db->query($this->db->update_string('exp_members', array('private_messages' => $count_query->row('count') ), "member_id = '".$row['recipient_id']."'"));
  748. }
  749. }
  750. }
  751. /** ----------------------------------
  752. /** Are there forum posts to delete?
  753. /** ----------------------------------*/
  754. if ($this->config->item('forum_is_installed') == "y")
  755. {
  756. $this->db->query("DELETE FROM exp_forum_subscriptions WHERE ".$IDS);
  757. $this->db->query("DELETE FROM exp_forum_pollvotes WHERE ".$IDS);
  758. $IDS = str_replace('member_id', 'admin_member_id', $IDS);
  759. $this->db->query("DELETE FROM exp_forum_administrators WHERE ".$IDS);
  760. $IDS = str_replace('admin_member_id', 'mod_member_id', $IDS);
  761. $this->db->query("DELETE FROM exp_forum_moderators WHERE ".$IDS);
  762. $IDS = str_replace('mod_member_id', 'author_id', $IDS);
  763. $this->db->query("DELETE FROM exp_forum_topics WHERE ".$IDS);
  764. // Snag the affected topic id's before deleting the members for the update afterwards
  765. $query = $this->db->query("SELECT topic_id FROM exp_forum_posts WHERE ".$IDS);
  766. if ($query->num_rows() > 0)
  767. {
  768. $topic_ids = array();
  769. foreach ($query->result_array() as $row)
  770. {
  771. $topic_ids[] = $row['topic_id'];
  772. }
  773. $topic_ids = array_unique($topic_ids);
  774. }
  775. $this->db->query("DELETE FROM exp_forum_posts WHERE ".$IDS);
  776. $this->db->query("DELETE FROM exp_forum_polls WHERE ".$IDS);
  777. $IDS = str_replace('author_id', 'member_id', $IDS);
  778. // Kill any attachments
  779. $query = $this->db->query("SELECT attachment_id, filehash, extension, board_id FROM exp_forum_attachments WHERE ".$IDS);
  780. if ($query->num_rows() > 0)
  781. {
  782. // Grab the upload path
  783. $res = $this->db->query('SELECT board_id, board_upload_path FROM exp_forum_boards');
  784. $paths = array();
  785. foreach ($res->result_array() as $row)
  786. {
  787. $paths[$row['board_id']] = $row['board_upload_path'];
  788. }
  789. foreach ($query->result_array() as $row)
  790. {
  791. if ( ! isset($paths[$row['board_id']]))
  792. {
  793. continue;
  794. }
  795. $file = $paths[$row['board_id']].$row['filehash'].$row['extension'];
  796. $thumb = $paths[$row['board_id']].$row['filehash'].'_t'.$row['extension'];
  797. @unlink($file);
  798. @unlink($thumb);
  799. $this->db->query("DELETE FROM exp_forum_attachments WHERE attachment_id = '{$row['attachment_id']}'");
  800. }
  801. }
  802. // Update the forum stats
  803. $query = $this->db->query("SELECT forum_id FROM exp_forums WHERE forum_is_cat = 'n'");
  804. if ( ! class_exists('Forum'))
  805. {
  806. require PATH_MOD.'forum/mod.forum'.EXT;
  807. require PATH_MOD.'forum/mod.forum_core'.EXT;
  808. }
  809. $FRM = new Forum_Core;
  810. foreach ($query->result_array() as $row)
  811. {
  812. $FRM->_update_post_stats($row['forum_id']);
  813. }
  814. if (isset($topic_ids))
  815. {
  816. foreach ($topic_ids as $topic_id)
  817. {
  818. $FRM->_update_topic_stats($topic_id);
  819. }
  820. }
  821. }
  822. /** -------------------------------------
  823. /** Delete comments and update entry stats
  824. /** -------------------------------------*/
  825. $channel_ids = array();
  826. if ($this->db->table_exists('comment_subscriptions'))
  827. {
  828. $this->db->query("DELETE FROM exp_comment_subscriptions WHERE ".$IDS);
  829. }
  830. if ($this->db->table_exists('comments'))
  831. {
  832. $IDS = str_replace('member_id', 'author_id', $IDS);
  833. $query = $this->db->query("SELECT DISTINCT(entry_id), channel_id FROM exp_comments WHERE ".$IDS);
  834. if ($query->num_rows() > 0)
  835. {
  836. $this->db->query("DELETE FROM exp_comments WHERE ".$IDS);
  837. foreach ($query->result_array() as $row)
  838. {
  839. $channel_ids[] = $row['channel_id'];
  840. $query = $this->db->query("SELECT MAX(comment_date) AS max_date FROM exp_comments WHERE status = 'o' AND entry_id = '".$this->db->escape_str($row['entry_id'])."'");
  841. $comment_date = ($query->num_rows() == 0 OR ! is_numeric($query->row('max_date') )) ? 0 : $query->row('max_date') ;
  842. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '{$row['entry_id']}' AND status = 'o'");
  843. $this->db->query("UPDATE exp_channel_titles
  844. SET comment_total = '".$this->db->escape_str($query->row('count') )."', recent_comment_date = '$comment_date'
  845. WHERE entry_id = '{$row['entry_id']}'");
  846. }
  847. }
  848. if (count($channel_ids) > 0)
  849. {
  850. foreach (array_unique($channel_ids) as $channel_id)
  851. {
  852. $this->stats->update_comment_stats($channel_id);
  853. }
  854. }
  855. }
  856. /** ----------------------------------
  857. /** Reassign Entires to Heir
  858. /** ----------------------------------*/
  859. $heir_id = $this->input->post('heir');
  860. if ($heir_id !== FALSE && is_numeric($heir_id))
  861. {
  862. $this->db->query("UPDATE exp_channel_titles SET author_id = '{$heir_id}' WHERE ".str_replace('member_id', 'author_id', $IDS));
  863. $query = $this->db->query("SELECT COUNT(entry_id) AS count, MAX(entry_date) AS entry_date
  864. FROM exp_channel_titles
  865. WHERE author_id = '{$heir_id}'");
  866. $this->db->query("UPDATE exp_members
  867. SET total_entries = '".$this->db->escape_str($query->row('count') )."', last_entry_date = '".$this->db->escape_str($query->row('entry_date') )."'
  868. WHERE member_id = '{$heir_id}'");
  869. }
  870. /* -------------------------------------------
  871. /* 'cp_members_member_delete_end' hook.
  872. /* - Additional processing when a member is deleted through the CP
  873. */
  874. $edata = $this->extensions->call('cp_members_member_delete_end');
  875. if ($this->extensions->end_script === TRUE) return;
  876. /*
  877. /* -------------------------------------------*/
  878. // Update
  879. $this->stats->update_member_stats();
  880. $cp_message = (count($ids) == 1) ? $this->lang->line('member_deleted') :
  881. $this->lang->line('members_deleted');
  882. $this->session->set_flashdata('message_success', $cp_message);
  883. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  884. }
  885. // --------------------------------------------------------------------
  886. /**
  887. * Member Group Manager
  888. *
  889. * Member group overview
  890. *
  891. * @access public
  892. * @return mixed
  893. */
  894. function member_group_manager()
  895. {
  896. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_mbr_groups'))
  897. {
  898. show_error($this->lang->line('unauthorized_access'));
  899. }
  900. $this->load->library('table');
  901. $this->load->library('pagination');
  902. $this->load->helper('form');
  903. $row_limit = $this->perpage;
  904. $offset = ($this->input->get('per_page') != '') ? $this->input->get('per_page') : 0;
  905. $query = $this->member_model->get_member_groups(array('can_access_cp', 'is_locked'), array(), $row_limit, $offset);
  906. $groups = array(); // holder for group info
  907. foreach($query->result_array() as $row)
  908. {
  909. $group_name = $row['group_title'];
  910. if (in_array($group_name, $this->english))
  911. {
  912. $group_name = $this->lang->line(strtolower(str_replace(" ", "_", $group_name)));
  913. }
  914. $groups[$row['group_id']]['group_id'] = $row['group_id'];
  915. $groups[$row['group_id']]['title'] = $group_name;
  916. $groups[$row['group_id']]['can_access_cp'] = $row['can_access_cp'];
  917. $groups[$row['group_id']]['security_lock'] = ($row['is_locked'] == 'y') ? $this->lang->line('locked') : $this->lang->line('unlocked');
  918. $groups[$row['group_id']]['member_count'] = $this->member_model->count_members($row['group_id']);
  919. $groups[$row['group_id']]['delete'] = ( ! in_array($row['group_id'], $this->no_delete)) ? TRUE : FALSE;
  920. }
  921. $vars['clone_group_options'] = array();
  922. $g_query = $this->member_model->get_member_groups();
  923. foreach($g_query->result_array() as $row)
  924. {
  925. $vars['clone_group_options'][$row['group_id']] = $row['group_title'];
  926. }
  927. $config = array(
  928. 'base_url' => BASE.AMP.'C=members'.AMP.'M=member_group_manager',
  929. 'total_rows' => $g_query->num_rows(),
  930. 'per_page' => $row_limit,
  931. 'page_query_string' => TRUE,
  932. 'first_link' => $this->lang->line('pag_first_link'),
  933. 'last_link' => $this->lang->line('pag_last_link')
  934. );
  935. $this->pagination->initialize($config);
  936. $vars['paginate'] = $this->pagination->create_links();
  937. $this->cp->set_variable('cp_page_title', $this->lang->line('member_groups'));
  938. $this->jquery->tablesorter('.mainTable', '{headers: {1: {sorter: false}, 5: {sorter: false}}, widgets: ["zebra"]}');
  939. $this->javascript->compile();
  940. $vars['groups'] = $groups;
  941. $this->cp->set_right_nav(array('create_new_member_group' => BASE.AMP.'C=members'.AMP.'M=edit_member_group'));
  942. $this->load->view('members/member_group_manager', $vars);
  943. }
  944. // --------------------------------------------------------------------
  945. /**
  946. * Edit Member Group
  947. *
  948. * Edit/Create a member group form
  949. *
  950. * @access public
  951. * @return mixed
  952. */
  953. function edit_member_group()
  954. {
  955. // Only super admins can administrate member groups
  956. if ($this->session->userdata['group_id'] != 1)
  957. {
  958. show_error($this->lang->line('only_superadmins_can_admin_groups'));
  959. }
  960. $this->load->library('table');
  961. $this->load->helper('form');
  962. $this->load->model('channel_model');
  963. $this->load->model('template_model');
  964. $this->load->model('addons_model');
  965. $this->load->model('site_model');
  966. $this->lang->loadfile('admin');
  967. $this->cp->add_js_script('ui', 'accordion');
  968. $this->jquery->tablesorter('#edit_member_group table', '{
  969. headers: {1: {sorter: false}, 2: {sorter: false}},
  970. widgets: ["zebra"]
  971. }');
  972. $this->javascript->output('
  973. $(".site_prefs").hide();
  974. $(".site_prefs:first").show();
  975. $("#edit_member_group").accordion({autoHeight: false,header: "h3"});
  976. $("#site_list_pulldown").change(function() {
  977. id = $("#site_list_pulldown").val();
  978. $(".site_prefs").fadeOut("500", function(){
  979. $("#site_options_"+id).fadeIn("500");
  980. });
  981. });
  982. ');
  983. $this->javascript->compile();
  984. $group_id = $this->input->get_post('group_id');
  985. $clone_id = $this->input->get_post('clone_id');
  986. $id = ($group_id == '') ? '3' : $group_id;
  987. // Assign the page title
  988. $title = ($group_id != '') ? $this->lang->line('edit_member_group') : $this->lang->line('create_member_group');
  989. // Fetch the Sites
  990. if ($this->config->item('multiple_sites_enabled') == 'y')
  991. {
  992. $sites_query = $this->site_model->get_site();
  993. }
  994. else
  995. {
  996. $sites_query = $this->site_model->get_site('1');
  997. }
  998. // Fetch the member group data
  999. if ($clone_id != '')
  1000. {
  1001. $id = $clone_id;
  1002. }
  1003. $query = $this->db->get_where('member_groups', array('group_id' => $id));
  1004. $result = ($query->num_rows() == 0) ? FALSE : TRUE;
  1005. $group_data = array();
  1006. foreach($query->result_array() as $row)
  1007. {
  1008. $group_data[$row['site_id']] = $row;
  1009. }
  1010. $default_id = $query->row('site_id');
  1011. // Translate the group title
  1012. // We only translate this if it has not been edited
  1013. $group_title = ($group_id == '') ? '' : $group_data[$default_id]['group_title'];
  1014. $group_description = ($group_id == '') ? '' : $group_data[$default_id]['group_description'];
  1015. if (isset($this->english[$group_title]))
  1016. {
  1017. $group_title = $this->lang->line(strtolower(str_replace(" ", "_", $group_title)));
  1018. }
  1019. if ($clone_id != '')
  1020. {
  1021. $group_title = '';
  1022. $group_description = '';
  1023. $vars['form_hidden']['clone_id'] = $clone_id;
  1024. }
  1025. $vars['form_hidden']['group_id'] = $group_id;
  1026. // Group name and description form fields
  1027. $vars['group_title'] = $group_title;
  1028. $vars['group_description'] = $group_description;
  1029. $vars['group_id'] = $group_id;
  1030. // Group lock
  1031. $vars['is_locked'] = ($group_data[$default_id]['is_locked'] == 'y') ? 'y' : 'n';
  1032. // Fetch the names and IDs of all channels
  1033. $this->db->select('channel_id, site_id, channel_title');
  1034. $this->db->order_by('channel_title');
  1035. $query = $this->db->get('channels');
  1036. $channel_names = array();
  1037. $channel_perms = array();
  1038. $channel_ids = array();
  1039. if ($id == 1)
  1040. {
  1041. foreach($query->result_array() as $row)
  1042. {
  1043. $channel_names['channel_id_'.$row['channel_id']] = $row['channel_title'];
  1044. $channel_perms[$row['site_id']]['channel_id_'.$row['channel_id']] = 'y';
  1045. }
  1046. }
  1047. else
  1048. {
  1049. $this->db->select('channel_id');
  1050. $this->db->where('group_id', $id);
  1051. $res = $this->db->get('channel_member_groups');
  1052. if ($res->num_rows() > 0)
  1053. {
  1054. foreach ($res->result_array() as $row)
  1055. {
  1056. $channel_ids[$row['channel_id']] = TRUE;
  1057. }
  1058. }
  1059. foreach($query->result_array() as $row)
  1060. {
  1061. $channel_names['channel_id_'.$row['channel_id']] = $row['channel_title'];
  1062. $channel_perms[$row['site_id']]['channel_id_'.$row['channel_id']] = (isset($channel_ids[$row['channel_id']])) ? 'y' : 'n';
  1063. }
  1064. }
  1065. $vars['channel_names'] = $channel_names;
  1066. // Fetch the names and IDs of all modules
  1067. $this->db->select('module_id, module_name');
  1068. $this->db->where('has_cp_backend', 'y');
  1069. $this->db->order_by('module_name');
  1070. $query = $this->db->get('modules');
  1071. $module_names = array();
  1072. $module_perms = array();
  1073. $module_ids = array();
  1074. if ($id == 1)
  1075. {
  1076. foreach($query->result_array() as $row)
  1077. {
  1078. $module_names['module_id_'.$row['module_id']] = $row['module_name'];
  1079. $module_perms['module_id_'.$row['module_id']] = 'y';
  1080. }
  1081. }
  1082. else
  1083. {
  1084. $this->db->select('module_id');
  1085. $this->db->where('group_id', $id);
  1086. $res = $this->db->get('module_member_groups');
  1087. if ($res->num_rows() > 0)
  1088. {
  1089. foreach ($res->result_array() as $row)
  1090. {
  1091. $module_ids[$row['module_id']] = TRUE;
  1092. }
  1093. }
  1094. foreach($query->result_array() as $row)
  1095. {
  1096. $module_names['module_id_'.$row['module_id']] = $row['module_name'];
  1097. $module_perms['module_id_'.$row['module_id']] = (isset($module_ids[$row['module_id']])) ? 'y' : 'n';
  1098. }
  1099. }
  1100. $vars['module_names'] = $module_names;
  1101. $vars['module_perms'] = $module_perms;
  1102. // Fetch the names and IDs of all template groups
  1103. $this->db->select('group_id, group_name, site_id');
  1104. $this->db->order_by('group_name');
  1105. $query = $this->db->get('template_groups');
  1106. $template_names = array();
  1107. $template_perms = array();
  1108. if ($id == 1)
  1109. {
  1110. foreach ($query->result_array() as $row)
  1111. {
  1112. $template_names['template_id_'.$row['group_id']] = $row['group_name'];
  1113. $template_perms[$row['site_id']]['template_id_'.$row['group_id']] = 'y';
  1114. }
  1115. }
  1116. else
  1117. {
  1118. $this->db->select('template_group_id');
  1119. $this->db->where('group_id', $id);
  1120. $res = $this->db->get('template_member_groups');
  1121. $template_ids = array();
  1122. if ($res->num_rows() > 0)
  1123. {
  1124. foreach ($res->result_array() as $row)
  1125. {
  1126. $template_ids[$row['template_group_id']] = TRUE;
  1127. }
  1128. }
  1129. foreach($query->result_array() as $row)
  1130. {
  1131. $template_names['template_id_'.$row['group_id']] = $row['group_name'];
  1132. $template_perms[$row['site_id']]['template_id_'.$row['group_id']] = (isset($template_ids[$row['group_id']])) ? 'y' : 'n';
  1133. }
  1134. }
  1135. $vars['template_names'] = $template_names;
  1136. /** ----------------------------------------------------
  1137. /** Assign clusters of member groups
  1138. /** ----------------------------------------------------*/
  1139. // NOTE: the associative value (y/n) is the default setting used
  1140. // only when we are showing the "create new group" form
  1141. $G = array(
  1142. 'site_access' => array (
  1143. 'can_view_online_system' => 'n',
  1144. 'can_view_offline_system' => 'n'
  1145. ),
  1146. 'mbr_account_privs' => array (
  1147. 'can_view_profiles' => 'n',
  1148. 'can_email_from_profile' => 'n',
  1149. 'include_in_authorlist' => 'n',
  1150. 'include_in_memberlist' => 'n',
  1151. 'include_in_mailinglists' => 'y',
  1152. 'can_delete_self' => 'n',
  1153. 'mbr_delete_notify_emails' => $this->config->item('webmaster_email')
  1154. ),
  1155. 'commenting_privs' => array (
  1156. 'can_post_comments' => 'n',
  1157. 'exclude_from_moderation' => 'n'
  1158. ),
  1159. 'search_privs' => array (
  1160. 'can_search' => 'n',
  1161. 'search_flood_control' => '30'
  1162. ),
  1163. 'priv_msg_privs' => array (
  1164. 'can_send_private_messages' => 'n',
  1165. 'prv_msg_send_limit' => '20',
  1166. 'prv_msg_storage_limit' => '60',
  1167. 'can_attach_in_private_messages' => 'n',
  1168. 'can_send_bulletins' => 'n'
  1169. ),
  1170. 'global_cp_access' => array (
  1171. 'can_access_cp' => 'n',
  1172. 'can_access_content' => 'n',
  1173. 'can_access_publish' => 'n',
  1174. 'can_access_edit' => 'n',
  1175. 'can_access_files' => 'n',
  1176. 'can_access_design' => 'n',
  1177. 'can_access_addons' => 'n',
  1178. 'can_access_modules' => 'n',
  1179. 'can_access_extensions' => 'n',
  1180. 'can_access_accessories' => 'n',
  1181. 'can_access_plugins' => 'n',
  1182. 'can_access_fieldtypes' => 'n',
  1183. 'can_access_members' => 'n',
  1184. 'can_access_admin' => 'n',
  1185. 'can_access_sys_prefs' => 'n',
  1186. 'can_access_content_prefs' => 'n',
  1187. 'can_access_tools' => 'n',
  1188. 'can_access_comm' => 'n',
  1189. 'can_access_utilities' => 'n',
  1190. 'can_access_data' => 'n',
  1191. 'can_access_logs' => 'n'
  1192. ),
  1193. 'cp_admin_privs' => array (
  1194. 'can_admin_channels' => 'n',
  1195. 'can_admin_templates' => 'n',
  1196. 'can_admin_design' => 'n',
  1197. 'can_admin_members' => 'n',
  1198. 'can_admin_mbr_groups' => 'n',
  1199. 'can_admin_mbr_templates' => 'n',
  1200. 'can_delete_members' => 'n',
  1201. 'can_ban_users' => 'n',
  1202. 'can_admin_modules' => 'n'
  1203. ),
  1204. 'cp_email_privs' => array (
  1205. 'can_send_email' => 'n',
  1206. 'can_email_member_groups' => 'n',
  1207. 'can_email_mailinglist' => 'n',
  1208. 'can_send_cached_email' => 'n',
  1209. ),
  1210. 'cp_channel_privs' => array(
  1211. 'can_view_other_entries' => 'n',
  1212. 'can_delete_self_entries' => 'n',
  1213. 'can_edit_other_entries' => 'n',
  1214. 'can_delete_all_entries' => 'n',
  1215. 'can_assign_post_authors' => 'n',
  1216. 'can_edit_categories' => 'n',
  1217. 'can_delete_categories' => 'n',
  1218. ),
  1219. 'cp_channel_post_privs' => $channel_perms,
  1220. 'cp_comment_privs' => array (
  1221. 'can_moderate_comments' => 'n',
  1222. 'can_view_other_comments' => 'n',
  1223. 'can_edit_own_comments' => 'n',
  1224. 'can_delete_own_comments' => 'n',
  1225. 'can_edit_all_comments' => 'n',
  1226. 'can_delete_all_comments' => 'n'
  1227. ),
  1228. 'cp_template_access_privs' => $template_perms,
  1229. // 'cp_module_access_privs' => $module_perms, // handled via $vars['module_names'] and $vars['module_perms']
  1230. );
  1231. // Super Admin Group can not be edited
  1232. // If the form being viewed is the Super Admin one we only allow the name to be changed.
  1233. if ($group_id == 1)
  1234. {
  1235. $G = array('mbr_account_privs' => array ('include_in_authorlist' => 'n', 'include_in_memberlist' => 'n'));
  1236. }
  1237. // Assign items we want to highlight
  1238. $vars['alert'] = array(
  1239. 'can_view_offline_system',
  1240. 'can_access_cp',
  1241. 'can_admin_channels',
  1242. 'can_admin_templates',
  1243. 'can_delete_members',
  1244. 'can_admin_mbr_groups',
  1245. 'can_admin_mbr_templates',
  1246. 'can_ban_users',
  1247. 'can_admin_members',
  1248. 'can_admin_design',
  1249. 'can_admin_modules',
  1250. 'can_edit_categories',
  1251. 'can_delete_categories',
  1252. 'can_delete_self'
  1253. );
  1254. // Items that should be shown in an input box
  1255. $vars['textbox'] = array(
  1256. 'search_flood_control',
  1257. 'prv_msg_send_limit',
  1258. 'prv_msg_storage_limit',
  1259. 'mbr_delete_notify_emails'
  1260. );
  1261. $s = 0;
  1262. //echo '<pre>'; print_r($G); exit;
  1263. foreach($sites_query->result_array() as $sites)
  1264. {
  1265. $vars['sites_dropdown'][$sites['site_id']] = $sites['site_label'];
  1266. foreach ($G as $g_key => $g_val)
  1267. {
  1268. if ($g_key == 'cp_module_access_privs')
  1269. {
  1270. if ($s == 0)
  1271. {
  1272. $add = '';
  1273. }
  1274. else
  1275. {
  1276. continue;
  1277. }
  1278. }
  1279. else
  1280. {
  1281. $add = $sites['site_id'].'_';
  1282. }
  1283. foreach($g_val as $key => $val)
  1284. {
  1285. if ($g_key == 'cp_module_access_privs')
  1286. {
  1287. $vars['group_data'][$sites['site_id']][$add.$key] = $group_data[$key];
  1288. }
  1289. elseif (isset($group_data[$sites['site_id']][$key]) && $group_data[$sites['site_id']][$key] != '')
  1290. {
  1291. $vars['group_data'][$sites['site_id']][$g_key][$add.$key] = $group_data[$sites['site_id']][$key];
  1292. }
  1293. elseif ($key == $sites['site_id'])
  1294. {
  1295. foreach($val as $p => $a)
  1296. {
  1297. $vars['group_data'][$sites['site_id']][$g_key][$add.$p] = $a;
  1298. }
  1299. }
  1300. else // probably redundant
  1301. {
  1302. //$vars['group_data'][$sites['site_id']][$g_key][$add.$key] = $val;
  1303. }
  1304. }
  1305. }
  1306. ++$s;
  1307. }
  1308. // Submit button lang key
  1309. $vars['action'] = ($group_id == '') ? 'submit' : 'update';
  1310. $this->cp->set_variable('cp_page_title', $title);
  1311. $this->load->view('members/edit_member_group', $vars);
  1312. }
  1313. // --------------------------------------------------------------------
  1314. /**
  1315. * Member Config
  1316. *
  1317. * @access public
  1318. * @return mixed
  1319. */
  1320. function member_config()
  1321. {
  1322. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  1323. {
  1324. show_error($this->lang->line('unauthorized_access'));
  1325. }
  1326. $this->lang->loadfile('admin');
  1327. $this->load->library('table');
  1328. $this->load->helper('form');
  1329. $f_data = array(
  1330. 'general_cfg' => array(
  1331. 'allow_member_registration' => array('r', array('y' => 'yes', 'n' => 'no')),
  1332. 'req_mbr_activation' => array('s', array('none' => 'no_activation', 'email' => 'email_activation', 'manual' => 'manual_activation')),
  1333. 'require_terms_of_service' => array('r', array('y' => 'yes', 'n' => 'no')),
  1334. 'allow_member_localization' => array('r', array('y' => 'yes', 'n' => 'no')),
  1335. 'use_membership_captcha' => array('r', array('y' => 'yes', 'n' => 'no')),
  1336. 'default_member_group' => array('f', 'member_groups'),
  1337. 'member_theme' => array('f', 'member_theme_menu'),
  1338. 'profile_trigger' => ''
  1339. ),
  1340. 'memberlist_cfg' => array(
  1341. 'memberlist_order_by' => array('s', array('total_posts' => 'total_posts',
  1342. 'screen_name' => 'screen_name',
  1343. 'total_comments' => 'total_comments',
  1344. 'total_entries' => 'total_entries',
  1345. 'join_date' => 'join_date')),
  1346. 'memberlist_sort_order' => array('s', array('desc' => 'memberlist_desc', 'asc' => 'memberlist_asc')),
  1347. 'memberlist_row_limit' => array('s', array('10' => '10', '20' => '20', '30' => '30', '40' => '40', '50' => '50', '75' => '75', '100' => '100'))
  1348. ),
  1349. 'notification_cfg' => array(
  1350. 'new_member_notification' => array('r', array('y' => 'yes', 'n' => 'no')),
  1351. 'mbr_notification_emails' => ''
  1352. ),
  1353. 'pm_cfg' => array(
  1354. 'prv_msg_max_chars' => '',
  1355. 'prv_msg_html_format' => array('s', array('safe' => 'html_safe', 'none' => 'html_none', 'all' => 'html_all')),
  1356. 'prv_msg_auto_links' => array('r', array('y' => 'yes', 'n' => 'no')),
  1357. 'prv_msg_upload_path' => '',
  1358. 'prv_msg_max_attachments' => '',
  1359. 'prv_msg_attach_maxsize' => '',
  1360. 'prv_msg_attach_total' => ''
  1361. ),
  1362. 'avatar_cfg' => array(
  1363. 'enable_avatars' => array('r', array('y' => 'yes', 'n' => 'no')),
  1364. 'allow_avatar_uploads' => array('r', array('y' => 'yes', 'n' => 'no')),
  1365. 'avatar_url' => '',
  1366. 'avatar_path' => '',
  1367. 'avatar_max_width' => '',
  1368. 'avatar_max_height' => '',
  1369. 'avatar_max_kb' => ''
  1370. ),
  1371. 'photo_cfg' => array(
  1372. 'enable_photos' => array('r', array('y' => 'yes', 'n' => 'no')),
  1373. 'photo_url' => '',
  1374. 'photo_path' => '',
  1375. 'photo_max_width' => '',
  1376. 'photo_max_height' => '',
  1377. 'photo_max_kb' => ''
  1378. ),
  1379. 'signature_cfg' => array(
  1380. 'allow_signatures' => array('r', array('y' => 'yes', 'n' => 'no')),
  1381. 'sig_maxlength' => '',
  1382. 'sig_allow_img_hotlink' => array('r', array('y' => 'yes', 'n' => 'no')),
  1383. 'sig_allow_img_upload' => array('r', array('y' => 'yes', 'n' => 'no')),
  1384. 'sig_img_url' => '',
  1385. 'sig_img_path' => '',
  1386. 'sig_img_max_width' => '',
  1387. 'sig_img_max_height' => '',
  1388. 'sig_img_max_kb' => ''
  1389. )
  1390. );
  1391. $subtext = array(
  1392. 'profile_trigger' => array('profile_trigger_notes'),
  1393. 'mbr_notification_emails' => array('separate_emails'),
  1394. 'default_member_group' => array('group_assignment_defaults_to_two'),
  1395. 'avatar_path' => array('must_be_path'),
  1396. 'photo_path' => array('must_be_path'),
  1397. 'sig_img_path' => array('must_be_path'),
  1398. 'allow_member_localization' => array('allow_member_loc_notes')
  1399. );
  1400. /** -----------------------------
  1401. /** Blast through the array
  1402. /** -----------------------------*/
  1403. foreach ($f_data as $menu_head => $menu_array)
  1404. {
  1405. $vars['menu_head'][$menu_head] = array();
  1406. foreach ($menu_array as $key => $val)
  1407. {
  1408. $vars['menu_head'][$menu_head][$key]['preference'] = $this->lang->line($key, $key);
  1409. $vars['menu_head'][$menu_head][$key]['preference_subtext'] = '';
  1410. // Preference sub-heading
  1411. if (isset($subtext[$key]))
  1412. {
  1413. foreach ($subtext[$key] as $sub)
  1414. {
  1415. $vars['menu_head'][$menu_head][$key]['preference_subtext'] = $this->lang->line($sub);
  1416. }
  1417. }
  1418. $preference_controls = '';
  1419. if (is_array($val))
  1420. {
  1421. if ($val['0'] == 's')
  1422. {
  1423. /** -----------------------------
  1424. /** Drop-down menus
  1425. /** -----------------------------*/
  1426. $options = array();
  1427. foreach ($val['1'] as $k => $v)
  1428. {
  1429. $options[$k] = $this->lang->line($v);
  1430. }
  1431. $preference_controls['type'] = "dropdown";
  1432. $preference_controls['id'] = $key;
  1433. $preference_controls['options'] = $options;
  1434. $preference_controls['default'] = $this->config->item($key);
  1435. }
  1436. elseif ($val['0'] == 'r')
  1437. {
  1438. /** -----------------------------
  1439. /** Radio buttons
  1440. /** -----------------------------*/
  1441. $radios = array();
  1442. foreach ($val['1'] as $k => $v)
  1443. {
  1444. $selected = ($k == $this->config->item($key)) ? TRUE : FALSE;
  1445. $radios[] = array(
  1446. 'label' => $this->lang->line($v, "{$key}_{$k}"),
  1447. 'radio' => array(
  1448. 'name' => $key,
  1449. 'id' => "{$key}_{$k}",
  1450. 'value' => $k,
  1451. 'checked' => ($k == $this->config->item($key)) ? TRUE : FALSE
  1452. )
  1453. );
  1454. }
  1455. $preference_controls['type'] = "radio";
  1456. $preference_controls['radio'] = $radios;
  1457. }
  1458. elseif ($val['0'] == 'f')
  1459. {
  1460. /** -----------------------------
  1461. /** Function calls
  1462. /** -----------------------------*/
  1463. switch ($val['1'])
  1464. {
  1465. case 'member_groups' :
  1466. $groups = $this->member_model->get_member_groups('', array('group_id !='=>'1'));
  1467. $selected = ($this->config->item('default_member_group') != '') ? $this->config->item('default_member_group') : '4';
  1468. $options = array();
  1469. foreach ($groups->result() as $group)
  1470. {
  1471. $options[$group->group_id] = $group->group_title;
  1472. }
  1473. $preference_controls['type'] = "dropdown";
  1474. $preference_controls['id'] = 'default_member_group';
  1475. $preference_controls['options'] = $options;
  1476. $preference_controls['default'] = $selected;
  1477. break;
  1478. case 'member_theme_menu' :
  1479. $themes = $this->member_model->get_theme_list(PATH_MBR_THEMES);
  1480. $options = array();
  1481. foreach ($themes as $file=>$name)
  1482. {
  1483. $options[$file] = $name;
  1484. }
  1485. $preference_controls['type'] = "dropdown";
  1486. $preference_controls['id'] = 'member_theme';
  1487. $preference_controls['options'] = $options;
  1488. $preference_controls['default'] = $this->config->item($key);
  1489. break;
  1490. }
  1491. }
  1492. }
  1493. else
  1494. {
  1495. /** -----------------------------
  1496. /** Text input fields
  1497. /** -----------------------------*/
  1498. $item = str_replace("\\'", "'", $this->config->item($key));
  1499. $preference_controls['type'] = "text";
  1500. $preference_controls['data'] = array(
  1501. 'id' => $key,
  1502. 'name' => $key,
  1503. 'value' => $item,
  1504. 'class' => 'field'
  1505. );
  1506. }
  1507. $vars['menu_head'][$menu_head][$key]['preference_controls'] = $preference_controls;
  1508. }
  1509. }
  1510. $this->cp->set_variable('cp_page_title', $this->lang->line('member_cfg'));
  1511. $this->cp->add_js_script('ui', 'accordion');
  1512. $this->jquery->tablesorter('table', '{
  1513. headers: {},
  1514. widgets: ["zebra"]
  1515. }');
  1516. $this->javascript->output('
  1517. $("#member_group_details").accordion({autoHeight: false,header: "h3"});
  1518. ');
  1519. $this->javascript->compile();
  1520. $this->load->view('members/member_config', $vars);
  1521. }
  1522. // --------------------------------------------------------------------
  1523. /**
  1524. * Update Config
  1525. *
  1526. * Update general preferences
  1527. *
  1528. * @access public
  1529. * @return mixed
  1530. */
  1531. function update_config()
  1532. {
  1533. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  1534. {
  1535. show_error($this->lang->line('unauthorized_access'));
  1536. }
  1537. $config_update = $this->config->update_site_prefs($_POST);
  1538. $loc = BASE.AMP.'C=members'.AMP.'M=member_config';
  1539. if ( ! empty($config_update))
  1540. {
  1541. $this->load->helper('html');
  1542. $this->session->set_flashdata('message_failure', ul($config_update, array('class' => 'bad_path_error_list')));
  1543. }
  1544. else
  1545. {
  1546. $this->session->set_flashdata('message_success', $this->lang->line('preferences_updated'));
  1547. }
  1548. $this->functions->redirect($loc);
  1549. }
  1550. // --------------------------------------------------------------------
  1551. /**
  1552. * Update Member Group
  1553. *
  1554. * Create/update a member group
  1555. *
  1556. * @access public
  1557. * @return mixed
  1558. */
  1559. function update_member_group()
  1560. {
  1561. // Only super admins can administrate member groups
  1562. if ($this->session->userdata['group_id'] != 1)
  1563. {
  1564. show_error($this->lang->line('only_superadmins_can_admin_groups'));
  1565. }
  1566. $edit = TRUE;
  1567. $group_id = $this->input->post('group_id');
  1568. $clone_id = $this->input->post('clone_id');
  1569. unset($_POST['group_id']);
  1570. unset($_POST['clone_id']);
  1571. // Only super admins can edit the "super admin" group
  1572. if ($group_id == 1 AND $this->session->userdata['group_id'] != 1)
  1573. {
  1574. show_error($this->lang->line('unauthorized_access'));
  1575. }
  1576. // No group name
  1577. if ( ! $this->input->post('group_title'))
  1578. {
  1579. show_error($this->lang->line('missing_group_title'));
  1580. }
  1581. $return = ($this->input->get_post('return')) ? TRUE : FALSE;
  1582. unset($_POST['return']);
  1583. // New Group? Find Max
  1584. if (empty($group_id))
  1585. {
  1586. $edit = FALSE;
  1587. $query = $this->db->query("SELECT MAX(group_id) as max_group FROM exp_member_groups");
  1588. $group_id = $query->row('max_group') + 1;
  1589. }
  1590. // get existing category privileges if necessary
  1591. if ($edit == TRUE)
  1592. {
  1593. $query = $this->db->query("SELECT site_id, can_edit_categories, can_delete_categories FROM exp_member_groups WHERE group_id = '".$this->db->escape_str($group_id)."'");
  1594. $old_cat_privs = array();
  1595. foreach ($query->result_array() as $row)
  1596. {
  1597. $old_cat_privs[$row['site_id']]['can_edit_categories'] = $row['can_edit_categories'];
  1598. $old_cat_privs[$row['site_id']]['can_delete_categories'] = $row['can_delete_categories'];
  1599. }
  1600. }
  1601. $query = $this->db->query("SELECT site_id FROM exp_sites");
  1602. $module_ids = array();
  1603. $channel_ids = array();
  1604. $template_ids = array();
  1605. $cat_group_privs = array('can_edit_categories', 'can_delete_categories');
  1606. foreach($query->result_array() as $row)
  1607. {
  1608. $site_id = $row['site_id'];
  1609. /** ----------------------------------------------------
  1610. /** Remove and Store Channel and Template Permissions
  1611. /** ----------------------------------------------------*/
  1612. $data = array('group_title' => $this->input->post('group_title'),
  1613. 'group_description' => $this->input->post('group_description'),
  1614. 'is_locked' => $this->input->post('is_locked'),
  1615. 'site_id' => $site_id,
  1616. 'group_id' => $group_id);
  1617. foreach ($_POST as $key => $val)
  1618. {
  1619. if (substr($key, 0, strlen($site_id.'_channel_id_')) == $site_id.'_channel_id_')
  1620. {
  1621. if ($val == 'y')
  1622. {
  1623. $channel_ids[] = substr($key, strlen($site_id.'_channel_id_'));
  1624. }
  1625. }
  1626. elseif (substr($key, 0, strlen('module_id_')) == 'module_id_')
  1627. {
  1628. if ($val == 'y')
  1629. {
  1630. $module_ids[] = substr($key, strlen('module_id_'));
  1631. }
  1632. }
  1633. elseif (substr($key, 0, strlen($site_id.'_template_id_')) == $site_id.'_template_id_')
  1634. {
  1635. if ($val == 'y')
  1636. {
  1637. $template_ids[] = substr($key, strlen($site_id.'_template_id_'));
  1638. }
  1639. }
  1640. elseif (substr($key, 0, strlen($site_id.'_')) == $site_id.'_')
  1641. {
  1642. $data[substr($key, strlen($site_id.'_'))] = $_POST[$key];
  1643. }
  1644. else
  1645. {
  1646. continue;
  1647. }
  1648. unset($_POST[$key]);
  1649. }
  1650. if ($edit === FALSE)
  1651. {
  1652. $this->db->query($this->db->insert_string('exp_member_groups', $data));
  1653. $uploads = $this->db->query("SELECT exp_upload_prefs.id FROM exp_upload_prefs WHERE site_id = '".$this->db->escape_str($site_id)."'");
  1654. if ($uploads->num_rows() > 0)
  1655. {
  1656. foreach($uploads->result_array() as $yeeha)
  1657. {
  1658. $this->db->query("INSERT INTO exp_upload_no_access (upload_id, upload_loc, member_group) VALUES ('".$this->db->escape_str($yeeha['id'])."', 'cp', '{$group_id}')");
  1659. }
  1660. }
  1661. if ($group_id != 1)
  1662. {
  1663. foreach ($cat_group_privs as $field)
  1664. {
  1665. $privs = array(
  1666. 'member_group' => $group_id,
  1667. 'field' => $field,
  1668. 'allow' => ($data[$field] == 'y') ? TRUE : FALSE,
  1669. 'site_id' => $site_id,
  1670. 'clone_id' => $clone_id
  1671. );
  1672. $this->_update_cat_group_privs($privs);
  1673. }
  1674. }
  1675. $cp_message = $this->lang->line('member_group_created').NBS.NBS.$_POST['group_title'];
  1676. }
  1677. else
  1678. {
  1679. unset($data['group_id']);
  1680. $this->db->query($this->db->update_string('exp_member_groups', $data, "group_id = '$group_id' AND site_id = '{$site_id}'"));
  1681. if ($group_id != 1)
  1682. {
  1683. // update category group discrete privileges
  1684. foreach ($cat_group_privs as $field)
  1685. {
  1686. // only modify category group privs if value changed, so we do not
  1687. // globally overwrite existing defined privileges carelessly
  1688. if ($old_cat_privs[$site_id][$field] != $data[$field])
  1689. {
  1690. $privs = array(
  1691. 'member_group' => $group_id,
  1692. 'field' => $field,
  1693. 'allow' => ($data[$field] == 'y') ? TRUE : FALSE,
  1694. 'site_id' => $site_id,
  1695. 'clone_id' => $clone_id
  1696. );
  1697. $this->_update_cat_group_privs($privs);
  1698. }
  1699. }
  1700. }
  1701. $cp_message = $this->lang->line('member_group_updated').NBS.NBS.$_POST['group_title'];
  1702. }
  1703. }
  1704. // Update groups
  1705. $this->db->query("DELETE FROM exp_channel_member_groups WHERE group_id = '$group_id'");
  1706. $this->db->query("DELETE FROM exp_module_member_groups WHERE group_id = '$group_id'");
  1707. $this->db->query("DELETE FROM exp_template_member_groups WHERE group_id = '$group_id'");
  1708. if (count($channel_ids) > 0)
  1709. {
  1710. foreach ($channel_ids as $val)
  1711. {
  1712. $this->db->query("INSERT INTO exp_channel_member_groups (group_id, channel_id) VALUES ('$group_id', '$val')");
  1713. }
  1714. }
  1715. if (count($module_ids) > 0)
  1716. {
  1717. foreach ($module_ids as $val)
  1718. {
  1719. $this->db->query("INSERT INTO exp_module_member_groups (group_id, module_id) VALUES ('$group_id', '$val')");
  1720. }
  1721. }
  1722. if (count($template_ids) > 0)
  1723. {
  1724. foreach ($template_ids as $val)
  1725. {
  1726. $this->db->query("INSERT INTO exp_template_member_groups (group_id, template_group_id) VALUES ('$group_id', '$val')");
  1727. }
  1728. }
  1729. // Update CP log
  1730. $this->logger->log_action($cp_message);
  1731. $_POST['group_id'] = $group_id;
  1732. $this->session->set_flashdata('message_success', $cp_message);
  1733. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=member_group_manager');
  1734. }
  1735. // --------------------------------------------------------------------
  1736. /**
  1737. * Update Category Group Privileges
  1738. *
  1739. * Updates exp_category_groups privilege lists for
  1740. * editing and deleting categories
  1741. *
  1742. * @access public
  1743. * @return mixed
  1744. */
  1745. function _update_cat_group_privs($params)
  1746. {
  1747. if ( ! is_array($params) OR empty($params))
  1748. {
  1749. return FALSE;
  1750. }
  1751. $expected = array('member_group', 'field', 'allow', 'site_id', 'clone_id');
  1752. // turn parameters into variables
  1753. foreach ($expected as $key)
  1754. {
  1755. // naughty!
  1756. if ( ! isset($params[$key]))
  1757. {
  1758. return FALSE;
  1759. }
  1760. $$key = $params[$key];
  1761. }
  1762. $query = $this->db->query("SELECT group_id, ".$this->db->escape_str($field)." FROM exp_category_groups WHERE site_id = '".$this->db->escape_str($site_id)."'");
  1763. // nothing to do?
  1764. if ($query->num_rows() == 0)
  1765. {
  1766. return FALSE;
  1767. }
  1768. foreach ($query->result_array() as $row)
  1769. {
  1770. $can_do = explode('|', rtrim($row[$field], '|'));
  1771. if ($allow === TRUE)
  1772. {
  1773. if (is_numeric($clone_id))
  1774. {
  1775. if (in_array($clone_id, $can_do) OR $clone_id == 1)
  1776. {
  1777. $can_do[] = $member_group;
  1778. }
  1779. }
  1780. elseif ($clone_id === FALSE)
  1781. {
  1782. $can_do[] = $member_group;
  1783. }
  1784. }
  1785. else
  1786. {
  1787. $can_do = array_diff($can_do, array($member_group));
  1788. }
  1789. $this->db->query($this->db->update_string('exp_category_groups', array($field => implode('|', $can_do)), "group_id = '{$row['group_id']}'"));
  1790. }
  1791. }
  1792. // --------------------------------------------------------------------
  1793. /**
  1794. * Delete member group confirm
  1795. *
  1796. * Warning message shown when you try to delete a group
  1797. *
  1798. * @access public
  1799. * @return mixed
  1800. */
  1801. function delete_member_group_conf()
  1802. {
  1803. // Only super admins can delete member groups
  1804. if ($this->session->userdata['group_id'] != 1)
  1805. {
  1806. show_error($this->lang->line('only_superadmins_can_admin_groups'));
  1807. }
  1808. if ( ! $group_id = $this->input->get_post('group_id'))
  1809. {
  1810. return FALSE;
  1811. }
  1812. // You can't delete these groups
  1813. if (in_array($group_id, $this->no_delete))
  1814. {
  1815. show_error($this->lang->line('unauthorized_access'));
  1816. }
  1817. $this->load->model('member_model');
  1818. $this->load->helper('form');
  1819. // Are there any members that are assigned to this group?
  1820. $vars['member_count'] = $this->member_model->count_members($group_id);
  1821. $query = $this->db->query("SELECT group_title FROM exp_member_groups WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."' AND group_id = '".$this->db->escape_str($group_id)."'");
  1822. $vars['group_title'] = $query->row('group_title');
  1823. $vars['group_id'] = $group_id;
  1824. $vars['form_hidden']['group_id'] = $group_id;
  1825. $vars['form_hidden']['reassign'] = ($vars['member_count'] > 0) ? 'y' : 'n';
  1826. if ($vars['member_count'] > 0)
  1827. {
  1828. $query = $this->db->query("SELECT group_title, group_id FROM exp_member_groups WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."' AND group_id != '{$group_id}' order by group_title");
  1829. foreach ($query->result() as $row)
  1830. {
  1831. $group_name = $row->group_title;
  1832. if (in_array($group_name, $this->english))
  1833. {
  1834. $group_name = $this->lang->line(strtolower(str_replace(" ", "_", $group_name)));
  1835. }
  1836. $vars['new_group_id'][$row->group_id] = $group_name;
  1837. }
  1838. }
  1839. $this->cp->set_variable('cp_page_title', $this->lang->line('delete_member_group'));
  1840. $this->javascript->compile();
  1841. $this->load->view('members/delete_member_group_conf', $vars);
  1842. }
  1843. // --------------------------------------------------------------------
  1844. /**
  1845. * Delete Member Group
  1846. *
  1847. * @access public
  1848. * @return mixed
  1849. */
  1850. function delete_member_group()
  1851. {
  1852. // Only super admins can delete member groups
  1853. if ($this->session->userdata['group_id'] != 1)
  1854. {
  1855. show_error($this->lang->line('only_superadmins_can_admin_groups'));
  1856. }
  1857. if ( ! $group_id = $this->input->post('group_id'))
  1858. {
  1859. return FALSE;
  1860. }
  1861. if (in_array($group_id, $this->no_delete))
  1862. {
  1863. show_error($this->lang->line('unauthorized_access'));
  1864. }
  1865. $this->load->model('member_model');
  1866. if ($this->input->get_post('reassign') == 'y' AND $this->input->get_post('new_group_id') != FALSE)
  1867. {
  1868. $new_group = $this->input->get_post('new_group_id');
  1869. }
  1870. else
  1871. {
  1872. $new_group = '';
  1873. }
  1874. $this->member_model->delete_member_group($group_id, $new_group);
  1875. $this->session->set_flashdata('message_success', $this->lang->line('member_group_deleted'));
  1876. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=member_group_manager');
  1877. }
  1878. // --------------------------------------------------------------------
  1879. /**
  1880. * New Member Form
  1881. *
  1882. * Create a member profile form
  1883. *
  1884. * @access public
  1885. * @return mixed
  1886. */
  1887. function new_member_form()
  1888. {
  1889. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  1890. {
  1891. show_error($this->lang->line('unauthorized_access'));
  1892. }
  1893. $this->load->library('form_validation');
  1894. $this->load->helper(array('form', 'string'));
  1895. $this->lang->loadfile('myaccount');
  1896. $this->load->library('table');
  1897. $config = array(
  1898. array(
  1899. 'field' => 'username',
  1900. 'label' => 'lang:username',
  1901. 'rules' => 'required|valid_username[new]'
  1902. ),
  1903. array(
  1904. 'field' => 'screen_name',
  1905. 'label' => 'lang:screen_name',
  1906. 'rules' => 'valid_screen_name[new]'
  1907. ),
  1908. array(
  1909. 'field' => 'password',
  1910. 'label' => 'lang:password',
  1911. 'rules' => 'required|valid_password[username]'
  1912. ),
  1913. array(
  1914. 'field' => 'password_confirm',
  1915. 'label' => 'lang:password_confirm',
  1916. 'rules' => 'required|matches[password]'
  1917. ),
  1918. array(
  1919. 'field' => 'email',
  1920. 'label' => 'lang:email',
  1921. 'rules' => 'trim|required|valid_user_email[new]'
  1922. ),
  1923. array(
  1924. 'field' => 'group_id',
  1925. 'label' => 'lang:member_group_assignment',
  1926. 'rules' => 'required|integer'
  1927. )
  1928. );
  1929. $this->form_validation->set_rules($config);
  1930. $this->form_validation->set_error_delimiters('<br /><span class="notice">', '</span>');
  1931. $this->cp->set_variable('cp_page_title', $this->lang->line('register_member'));
  1932. if ($this->form_validation->run() === FALSE)
  1933. {
  1934. $this->javascript->compile();
  1935. $is_locked = ($this->session->userdata['group_id'] == 1) ? array() : array('is_locked' => 'n');
  1936. $member_groups = $this->member_model->get_member_groups('', $is_locked);
  1937. $vars['member_groups'] = array();
  1938. foreach($member_groups->result() as $group)
  1939. {
  1940. // construct member_groups dropdown associative array
  1941. $vars['member_groups'][$group->group_id] = $group->group_title;
  1942. }
  1943. $this->load->view('members/register', $vars);
  1944. }
  1945. else
  1946. {
  1947. $this->_register_member();
  1948. }
  1949. }
  1950. // --------------------------------------------------------------------
  1951. /**
  1952. * Register Member
  1953. *
  1954. * Create a member profile
  1955. *
  1956. * @access public
  1957. * @return mixed
  1958. */
  1959. function _register_member()
  1960. {
  1961. $this->load->helper('security');
  1962. $data = array();
  1963. if ($this->input->post('group_id'))
  1964. {
  1965. if ( ! $this->cp->allowed_group('can_admin_mbr_groups'))
  1966. {
  1967. show_error($this->lang->line('unauthorized_access'));
  1968. }
  1969. $data['group_id'] = $this->input->post('group_id');
  1970. }
  1971. // -------------------------------------------
  1972. // 'cp_members_member_create_start' hook.
  1973. // - Take over member creation when done through the CP
  1974. // - Added 1.4.2
  1975. //
  1976. $edata = $this->extensions->call('cp_members_member_create_start');
  1977. if ($this->extensions->end_script === TRUE) return;
  1978. //
  1979. // -------------------------------------------
  1980. // If the screen name field is empty, we'll assign is
  1981. // from the username field.
  1982. $data['screen_name'] = ($this->input->post('screen_name')) ? $this->input->post('screen_name') : $this->input->post('username');
  1983. // Assign the query data
  1984. $data['username'] = $this->input->post('username');
  1985. $data['password'] = do_hash($this->input->post('password'));
  1986. $data['email'] = $this->input->post('email');
  1987. $data['ip_address'] = $this->input->ip_address();
  1988. $data['unique_id'] = random_string('encrypt');
  1989. $data['join_date'] = $this->localize->now;
  1990. $data['language'] = $this->config->item('deft_lang');
  1991. $data['timezone'] = ($this->config->item('default_site_timezone') && $this->config->item('default_site_timezone') != '') ? $this->config->item('default_site_timezone') : $this->config->item('server_timezone');
  1992. $data['daylight_savings'] = ($this->config->item('default_site_dst') && $this->config->item('default_site_dst') != '') ? $this->config->item('default_site_dst') : $this->config->item('daylight_savings');
  1993. $data['time_format'] = ($this->config->item('time_format') && $this->config->item('time_format') != '') ? $this->config->item('time_format') : 'us';
  1994. // Was a member group ID submitted?
  1995. $data['group_id'] = ( ! $this->input->post('group_id')) ? 2 : $_POST['group_id'];
  1996. $member_id = $this->member_model->create_member($data);
  1997. // Write log file
  1998. $message = $this->lang->line('new_member_added');
  1999. $this->logger->log_action($message.NBS.NBS.stripslashes($data['username']));
  2000. // -------------------------------------------
  2001. // 'cp_members_member_create' hook.
  2002. // - Additional processing when a member is created through the CP
  2003. //
  2004. $edata = $this->extensions->call('cp_members_member_create', $member_id, $data);
  2005. if ($this->extensions->end_script === TRUE) return;
  2006. //
  2007. // -------------------------------------------
  2008. // Update Stats
  2009. $this->stats->update_member_stats();
  2010. $this->session->set_flashdata(array(
  2011. 'message_success' => $message.NBS.'<b>'.stripslashes($data['username']).'</b>',
  2012. 'username' => stripslashes($data['screen_name'])
  2013. ));
  2014. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=view_all_members');
  2015. }
  2016. // --------------------------------------------------------------------
  2017. /**
  2018. * Member Banning
  2019. *
  2020. * Member banning forms
  2021. *
  2022. * @access public
  2023. * @return mixed
  2024. */
  2025. function member_banning()
  2026. {
  2027. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_ban_users'))
  2028. {
  2029. show_error($this->lang->line('unauthorized_access'));
  2030. }
  2031. $this->load->library('table');
  2032. $banned_ips = $this->config->item('banned_ips');
  2033. $banned_emails = $this->config->item('banned_emails');
  2034. $banned_usernames = $this->config->item('banned_usernames');
  2035. $banned_screen_names = $this->config->item('banned_screen_names');
  2036. $vars['banned_ips'] = '';
  2037. $vars['banned_emails'] = '';
  2038. $vars['banned_usernames'] = '';
  2039. $vars['banned_screen_names'] = '';
  2040. $vars['ban_action'] = $this->config->item('ban_action');
  2041. $vars['ban_message'] = $this->config->item('ban_message');
  2042. $vars['ban_destination'] = $this->config->item('ban_destination');
  2043. $out = '';
  2044. $ips = '';
  2045. $email = '';
  2046. $users = '';
  2047. $screens = '';
  2048. if ($banned_ips != '')
  2049. {
  2050. foreach (explode('|', $banned_ips) as $val)
  2051. {
  2052. $vars['banned_ips'] .= $val.NL;
  2053. }
  2054. }
  2055. if ($banned_emails != '')
  2056. {
  2057. foreach (explode('|', $banned_emails) as $val)
  2058. {
  2059. $vars['banned_emails'] .= $val.NL;
  2060. }
  2061. }
  2062. if ($banned_usernames != '')
  2063. {
  2064. foreach (explode('|', $banned_usernames) as $val)
  2065. {
  2066. $vars['banned_usernames'] .= $val.NL;
  2067. }
  2068. }
  2069. if ($banned_screen_names != '')
  2070. {
  2071. foreach (explode('|', $banned_screen_names) as $val)
  2072. {
  2073. $vars['banned_screen_names'] .= $val.NL;
  2074. }
  2075. }
  2076. $this->cp->set_variable('cp_page_title', $this->lang->line('user_banning'));
  2077. $this->load->helper('form');
  2078. $this->load->view('members/member_banning', $vars);
  2079. }
  2080. // --------------------------------------------------------------------
  2081. /**
  2082. * Update Banning Data
  2083. *
  2084. * @access public
  2085. * @return mixed
  2086. */
  2087. function update_banning_data()
  2088. {
  2089. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_ban_users'))
  2090. {
  2091. show_error($this->lang->line('unauthorized_access'));
  2092. }
  2093. $this->load->model('site_model');
  2094. foreach ($_POST as $key => $val)
  2095. {
  2096. $_POST[$key] = stripslashes($val);
  2097. }
  2098. $this->load->helper('string');
  2099. $this->load->model('site_model');
  2100. $banned_ips = str_replace(NL, '|', $_POST['banned_ips']);
  2101. $banned_emails = str_replace(NL, '|', $_POST['banned_emails']);
  2102. $banned_usernames = str_replace(NL, '|', $_POST['banned_usernames']);
  2103. $banned_screen_names = str_replace(NL, '|', $_POST['banned_screen_names']);
  2104. $destination = ($_POST['ban_destination'] == 'http://') ? '' : $_POST['ban_destination'];
  2105. $data = array(
  2106. 'banned_ips' => $banned_ips,
  2107. 'banned_emails' => $banned_emails,
  2108. 'banned_emails' => $banned_emails,
  2109. 'banned_usernames' => $banned_usernames,
  2110. 'banned_screen_names' => $banned_screen_names,
  2111. 'ban_action' => $this->input->post('ban_action'),
  2112. 'ban_message' => $this->input->post('ban_message'),
  2113. 'ban_destination' => $destination
  2114. );
  2115. // Preferences Stored in Database For Site
  2116. $query = $this->site_model->get_site();
  2117. foreach($query->result() AS $row)
  2118. {
  2119. $prefs = array_merge(unserialize(base64_decode($row->site_system_preferences)), $data);
  2120. $this->site_model->update_site_system_preferences($prefs);
  2121. }
  2122. $this->session->set_flashdata('message_success', $this->lang->line('ban_preferences_updated'));
  2123. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=member_banning');
  2124. }
  2125. // --------------------------------------------------------------------
  2126. /**
  2127. * Custom Profile Fields
  2128. *
  2129. * This function show a list of current member fields and the
  2130. * form that allows you to create a new field.
  2131. *
  2132. * @access public
  2133. * @return mixed
  2134. */
  2135. function custom_profile_fields($group_id = '')
  2136. {
  2137. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2138. {
  2139. show_error($this->lang->line('unauthorized_access'));
  2140. }
  2141. // Fetch language file
  2142. // There are some lines in the publish administration language file that we need.
  2143. $this->lang->loadfile('admin_content');
  2144. $this->load->library('table');
  2145. $vars['fields'] = $this->member_model->get_custom_member_fields();
  2146. $this->cp->set_variable('cp_page_title', $this->lang->line('custom_profile_fields'));
  2147. $this->jquery->tablesorter('.mainTable', '{headers: {3: {sorter: false}, 4: {sorter: false}}, widgets: ["zebra"]}');
  2148. $this->javascript->compile();
  2149. $this->cp->set_right_nav(array('create_new_profile_field' => BASE.AMP.'C=members'.AMP.'M=edit_profile_field'));
  2150. $this->load->view('members/custom_profile_fields', $vars);
  2151. }
  2152. // --------------------------------------------------------------------
  2153. /**
  2154. * Edit Profile Field
  2155. *
  2156. * This function lets you edit an existing custom field
  2157. *
  2158. * @access public
  2159. * @return mixed
  2160. */
  2161. function edit_profile_field()
  2162. {
  2163. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2164. {
  2165. show_error($this->lang->line('unauthorized_access'));
  2166. }
  2167. $this->load->library('form_validation');
  2168. $this->load->model('member_model');
  2169. $this->load->helper('form');
  2170. $this->load->library('table');
  2171. // Fetch language file
  2172. // There are some lines in the publish administration language file that we need.
  2173. $this->lang->loadfile('admin_content');
  2174. $this->cp->set_breadcrumb(BASE.AMP.'C=members'.AMP.'M=custom_profile_fields', $this->lang->line('custom_profile_fields'));
  2175. $type = ($m_field_id = $this->input->get_post('m_field_id')) ? 'edit' : 'new';
  2176. $total_fields = '';
  2177. if ($type == 'new')
  2178. {
  2179. $query = $this->db->count_all('member_fields');
  2180. $total_fields = $query + 1;
  2181. $vars['submit_label'] = $this->lang->line('submit');
  2182. }
  2183. else
  2184. {
  2185. $vars['submit_label'] = $this->lang->line('update');
  2186. }
  2187. $query = $this->db->get_where('member_fields', array('m_field_id'=>$m_field_id));
  2188. if ($query->num_rows() == 0)
  2189. {
  2190. foreach ($this->db->list_fields('member_fields') as $f)
  2191. {
  2192. $$f = '';
  2193. }
  2194. }
  2195. else
  2196. {
  2197. foreach ($query->row_array() as $key => $val)
  2198. {
  2199. $$key = $val;
  2200. }
  2201. }
  2202. $vars['hidden_form_fields'] = array(
  2203. 'm_field_id' => $m_field_id,
  2204. 'cur_field_name' => $m_field_name
  2205. );
  2206. $title = ($type == 'edit') ? 'edit_member_field' : 'create_member_field';
  2207. // Field values
  2208. // If a validation value is found, use it first, otherwise drop to the database provided value
  2209. if ($type == 'new')
  2210. {
  2211. $m_field_order = $total_fields;
  2212. }
  2213. if ($m_field_width == '')
  2214. {
  2215. $m_field_width = '100%';
  2216. }
  2217. if ($m_field_maxl == '')
  2218. {
  2219. $m_field_maxl = '100';
  2220. }
  2221. if ($m_field_ta_rows == '')
  2222. {
  2223. $m_field_ta_rows = '10';
  2224. }
  2225. if ($m_field_required == '')
  2226. {
  2227. $m_field_required = 'n';
  2228. }
  2229. if ($m_field_public == '')
  2230. {
  2231. $m_field_public = 'y';
  2232. }
  2233. if ($m_field_reg == '')
  2234. {
  2235. $m_field_reg = 'n';
  2236. }
  2237. $vars['m_field_name'] = $m_field_name;
  2238. $vars['m_field_label'] = $m_field_label;
  2239. $vars['m_field_description'] = $m_field_description;
  2240. $vars['m_field_order'] = $m_field_order;
  2241. $vars['m_field_width'] = $m_field_width;
  2242. $vars['m_field_maxl'] = $m_field_maxl;
  2243. $vars['m_field_ta_rows'] = $m_field_ta_rows;
  2244. $vars['m_field_list_items'] = $m_field_list_items;
  2245. /** ---------------------------------
  2246. /** Field type
  2247. /** ---------------------------------*/
  2248. $vars['text_js'] = ($type == 'edit') ? 'none' : 'block';
  2249. $vars['textarea_js'] = 'none';
  2250. $vars['select_js'] = 'none';
  2251. $vars['select_opt_js'] = 'none';
  2252. switch ($m_field_type)
  2253. {
  2254. case 'select' : $vars['select_js'] = 'block'; $vars['select_opt_js'] = 'block';
  2255. break;
  2256. case 'textarea' : $vars['textarea_js'] = 'block';
  2257. break;
  2258. case 'text' : $vars['text_js'] = 'block';
  2259. break;
  2260. }
  2261. /** Create the pull-down menu **/
  2262. $vars['m_field_type_options'] = array(
  2263. 'text'=>$this->lang->line('text_input'),
  2264. 'textarea'=>$this->lang->line('textarea'),
  2265. 'select'=>$this->lang->line('select_list')
  2266. );
  2267. $vars['m_field_type'] = $m_field_type;
  2268. /** Field formatting **/
  2269. $vars['m_field_fmt_options'] = array(
  2270. 'none'=>$this->lang->line('none'),
  2271. 'br'=>$this->lang->line('auto_br'),
  2272. 'xhtml'=>$this->lang->line('xhtml')
  2273. );
  2274. $vars['m_field_fmt'] = $m_field_fmt;
  2275. /** Is field required? **/
  2276. $vars['m_field_required_options'] = array(
  2277. 'n' => lang('no'),
  2278. 'y' => lang('yes')
  2279. );
  2280. $vars['m_field_required'] = $m_field_required;
  2281. /** Is field public? **/
  2282. $vars['m_field_public_options'] = array(
  2283. 'n' => lang('no'),
  2284. 'y' => lang('yes')
  2285. );
  2286. $vars['m_field_public'] = $m_field_public;
  2287. /** Is field visible in reg page? **/
  2288. $vars['m_field_reg_options'] = array(
  2289. 'n' => lang('no'),
  2290. 'y' => lang('yes')
  2291. );
  2292. $vars['m_field_reg'] = $m_field_reg;
  2293. $this->cp->set_variable('cp_page_title', $this->lang->line($title));
  2294. $additional = '<script type="text/javascript">
  2295. function showhide_element(id)
  2296. {
  2297. // set everything hidden
  2298. document.getElementById("text_block").style.display = "none";
  2299. document.getElementById("textarea_block").style.display = "none";
  2300. document.getElementById("select_block").style.display = "none";
  2301. // reveal the shown element
  2302. document.getElementById(id+"_block").style.display = "block";
  2303. }
  2304. </script>';
  2305. $this->cp->add_to_foot($additional);
  2306. $this->javascript->compile();
  2307. $this->load->view('members/edit_profile_field', $vars);
  2308. }
  2309. function _validate_custom_field($edit)
  2310. {
  2311. $this->load->library('form_validation');
  2312. $is_edit = ($edit == TRUE) ? 'y' : 'n';
  2313. $this->form_validation->set_rules("m_field_name", 'lang:fieldname', 'required|callback__valid_fieldname['.$is_edit.']');
  2314. $this->form_validation->set_rules("m_field_label", 'lang:fieldlabel', 'required');
  2315. //$error[] = $this->lang->line('no_field_name');
  2316. //$error[] = $this->lang->line('no_field_label');
  2317. $this->form_validation->set_rules("m_field_description", '', '');
  2318. $this->form_validation->set_rules("m_field_order", '', '');
  2319. $this->form_validation->set_rules("m_field_width", '', '');
  2320. $this->form_validation->set_rules("m_field_list_items", '', '');
  2321. $this->form_validation->set_rules("m_field_maxl", '', '');
  2322. $this->form_validation->set_rules("m_field_ta_rows", '', '');
  2323. $this->form_validation->set_rules("m_field_fmt", '', '');
  2324. $this->form_validation->set_rules("m_field_required", '', '');
  2325. $this->form_validation->set_rules("m_field_public", '', '');
  2326. $this->form_validation->set_rules("m_field_reg", '', '');
  2327. $this->form_validation->set_error_delimiters('<br /><span class="notice">', '</span>');
  2328. }
  2329. function _valid_fieldname($str, $edit)
  2330. {
  2331. $this->lang->loadfile('admin_content');
  2332. if (in_array($str, $this->cp->invalid_custom_field_names()))
  2333. {
  2334. $this->form_validation->set_message('_valid_fieldname', $this->lang->line('reserved_word'));
  2335. return FALSE;
  2336. }
  2337. if (preg_match('/[^a-z0-9\_\-]/i', $str))
  2338. {
  2339. $this->form_validation->set_message('_valid_fieldname', $this->lang->line('invalid_characters'));
  2340. return FALSE;
  2341. }
  2342. // Is the field name taken?
  2343. $this->db->where('m_field_name', $str);
  2344. $this->db->from('member_fields');
  2345. $count = $this->db->count_all_results();
  2346. if (($edit == 'n' OR ($edit == 'y' && $str != $this->input->post('cur_field_name')))
  2347. && $count > 0)
  2348. {
  2349. $this->form_validation->set_message('_valid_fieldname', $this->lang->line('duplicate_field_name'));
  2350. return FALSE;
  2351. }
  2352. return TRUE;
  2353. }
  2354. // --------------------------------------------------------------------
  2355. /**
  2356. * Update Profile Fields
  2357. *
  2358. * This function alters the "exp_member_data" table, adding
  2359. * the new custom fields.
  2360. *
  2361. * @access public
  2362. * @return mixed
  2363. */
  2364. function update_profile_fields()
  2365. {
  2366. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2367. {
  2368. show_error($this->lang->line('unauthorized_access'));
  2369. }
  2370. // If the $field_id variable is present we are editing an
  2371. // existing field, otherwise we are creating a new one
  2372. $edit = (isset($_POST['m_field_id']) AND $_POST['m_field_id'] != '') ? TRUE : FALSE;
  2373. $this->_validate_custom_field($edit);
  2374. if ($this->form_validation->run() === FALSE)
  2375. {
  2376. return $this->edit_profile_field();
  2377. }
  2378. $this->lang->loadfile('admin_content');
  2379. $this->load->model('member_model');
  2380. unset($_POST['cur_field_name']);
  2381. if ($this->input->post('m_field_list_items') != '')
  2382. {
  2383. // Load the string helper
  2384. $this->load->helper('string');
  2385. $_POST['m_field_list_items'] = quotes_to_entities($_POST['m_field_list_items']);
  2386. }
  2387. // Construct the query based on whether we are updating or inserting
  2388. if ($edit === TRUE)
  2389. {
  2390. $n = $_POST['m_field_maxl'];
  2391. if ($_POST['m_field_type'] == 'text')
  2392. {
  2393. if ( ! is_numeric($n) OR $n == '' OR $n == 0)
  2394. {
  2395. $n = '100';
  2396. }
  2397. $f_type = 'varchar('.$n.') NULL DEFAULT NULL';
  2398. }
  2399. else
  2400. {
  2401. $f_type = 'text NULL DEFAULT NULL';
  2402. }
  2403. $this->db->query("ALTER table exp_member_data CHANGE m_field_id_".$_POST['m_field_id']." m_field_id_".$_POST['m_field_id']." $f_type");
  2404. $id = $_POST['m_field_id'];
  2405. unset($_POST['m_field_id']);
  2406. $this->db->query($this->db->update_string('exp_member_fields', $_POST, 'm_field_id='.$id));
  2407. }
  2408. else
  2409. {
  2410. if ($_POST['m_field_order'] == 0 OR $_POST['m_field_order'] == '')
  2411. {
  2412. $query = $this->member_model->count_records('member_fields');
  2413. $total = $query->row('count') + 1;
  2414. $_POST['m_field_order'] = $total;
  2415. }
  2416. $n = $_POST['m_field_maxl'];
  2417. if ($_POST['m_field_type'] == 'text')
  2418. {
  2419. if ( ! is_numeric($n) OR $n == '' OR $n == 0)
  2420. {
  2421. $n = '100';
  2422. }
  2423. $f_type = 'varchar('.$n.') NULL DEFAULT NULL';
  2424. }
  2425. else
  2426. {
  2427. $f_type = 'text NULL DEFAULT NULL';
  2428. }
  2429. unset($_POST['m_field_id']);
  2430. $this->db->query($this->db->insert_string('exp_member_fields', $_POST));
  2431. $this->db->query('ALTER table exp_member_data add column m_field_id_'.$this->db->insert_id().' '.$f_type);
  2432. $sql = "SELECT exp_members.member_id
  2433. FROM exp_members
  2434. LEFT JOIN exp_member_data ON exp_members.member_id = exp_member_data.member_id
  2435. WHERE exp_member_data.member_id IS NULL
  2436. ORDER BY exp_members.member_id";
  2437. $query = $this->db->query($sql);
  2438. if ($query->num_rows() > 0)
  2439. {
  2440. foreach ($query->result_array() as $row)
  2441. {
  2442. $this->db->query("INSERT INTO exp_member_data (member_id) values ('{$row['member_id']}')");
  2443. }
  2444. }
  2445. }
  2446. $cp_message = ($edit) ? $this->lang->line('field_updated') : $this->lang->line('field_created');
  2447. $this->session->set_flashdata('message_success', $cp_message);
  2448. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=custom_profile_fields');
  2449. }
  2450. // --------------------------------------------------------------------
  2451. /**
  2452. * Delete Profile Field Confirm
  2453. *
  2454. * Warning message if you try to delete a custom profile field
  2455. *
  2456. * @access public
  2457. * @return mixed
  2458. */
  2459. function delete_profile_field_conf()
  2460. {
  2461. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2462. {
  2463. show_error($this->lang->line('unauthorized_access'));
  2464. }
  2465. if ( ! ($m_field_id = $this->input->get_post('m_field_id')))
  2466. {
  2467. return FALSE;
  2468. }
  2469. $this->lang->loadfile('admin_content');
  2470. $this->load->helper('form');
  2471. $this->db->select('m_field_label');
  2472. $this->db->from('member_fields');
  2473. $this->db->where('m_field_id', $m_field_id);
  2474. $query = $this->db->get();
  2475. $vars['form_action'] = 'C=members'.AMP.'M=delete_profile_field'.AMP.'m_field_id='.$m_field_id;
  2476. $vars['form_hidden'] = array('m_field_id'=>$m_field_id);
  2477. $vars['field_name'] = $query->row('m_field_label');
  2478. $this->cp->set_variable('cp_page_title', $this->lang->line('delete_field'));
  2479. $this->load->view('members/delete_profile_fields_confirm', $vars);
  2480. }
  2481. // --------------------------------------------------------------------
  2482. /**
  2483. * Delete member profile field
  2484. *
  2485. * @access public
  2486. * @return mixed
  2487. */
  2488. function delete_profile_field()
  2489. {
  2490. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2491. {
  2492. show_error($this->lang->line('unauthorized_access'));
  2493. }
  2494. if ( ! $m_field_id = $this->input->get_post('m_field_id'))
  2495. {
  2496. return false;
  2497. }
  2498. $query = $this->db->query("SELECT m_field_label FROM exp_member_fields WHERE m_field_id = '$m_field_id'");
  2499. $m_field_label = $query->row('m_field_label') ;
  2500. $this->db->query("ALTER TABLE exp_member_data DROP COLUMN m_field_id_".$m_field_id);
  2501. $this->db->query("DELETE FROM exp_member_fields WHERE m_field_id = '$m_field_id'");
  2502. $cp_message = $this->lang->line('profile_field_deleted').NBS.NBS.$m_field_label;
  2503. $this->logger->log_action($cp_message);
  2504. $this->session->set_flashdata('message_success', $cp_message);
  2505. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=custom_profile_fields');
  2506. }
  2507. // --------------------------------------------------------------------
  2508. /**
  2509. * Edit Field Order
  2510. *
  2511. * @access public
  2512. * @return mixed
  2513. */
  2514. function edit_field_order()
  2515. {
  2516. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2517. {
  2518. show_error($this->lang->line('unauthorized_access'));
  2519. }
  2520. $this->load->model('member_model');
  2521. $this->lang->loadfile('admin_content');
  2522. $this->load->library('table');
  2523. $this->load->helper('form');
  2524. $custom_fields = $this->member_model->get_custom_member_fields();
  2525. $fields = array();
  2526. foreach ($custom_fields->result() as $field)
  2527. {
  2528. $fields[] = array(
  2529. 'id' => $field->m_field_id,
  2530. 'label' => $field->m_field_label,
  2531. 'name' => $field->m_field_name,
  2532. 'value' => $field->m_field_order
  2533. );
  2534. }
  2535. $vars['fields'] = $fields;
  2536. $this->cp->set_variable('cp_page_title', $this->lang->line('edit_field_order'));
  2537. $this->cp->set_breadcrumb(BASE.AMP.'C=members'.AMP.'M=custom_profile_fields', $this->lang->line('custom_profile_fields'));
  2538. $this->load->view('members/edit_field_order', $vars);
  2539. }
  2540. // --------------------------------------------------------------------
  2541. /**
  2542. * Update field order
  2543. *
  2544. * This function receives the field order submission
  2545. *
  2546. * @access public
  2547. * @return mixed
  2548. */
  2549. function update_field_order()
  2550. {
  2551. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2552. {
  2553. show_error($this->lang->line('unauthorized_access'));
  2554. }
  2555. foreach ($_POST as $key => $val)
  2556. {
  2557. $this->db->set('m_field_order', $val);
  2558. $this->db->where('m_field_name', $key);
  2559. $this->db->update('member_fields');
  2560. }
  2561. $this->session->set_flashdata('message_success', $this->lang->line('field_order_updated'));
  2562. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=edit_field_order');
  2563. }
  2564. // --------------------------------------------------------------------
  2565. /**
  2566. * IP Search
  2567. *
  2568. * IP Search Form
  2569. *
  2570. * @access public
  2571. * @return mixed
  2572. */
  2573. function ip_search()
  2574. {
  2575. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2576. {
  2577. show_error($this->lang->line('unauthorized_access'));
  2578. }
  2579. $message = '';
  2580. $ip = ($this->input->get_post('ip_address') != FALSE) ? str_replace('_', '.',$this->input->get_post('ip_address')) : '';
  2581. if ($this->input->get_post('error') == 2)
  2582. {
  2583. $message = $this->lang->line('ip_search_no_results');
  2584. }
  2585. elseif ($this->input->get_post('error') == 1)
  2586. {
  2587. $message = $this->lang->line('ip_search_too_short');
  2588. }
  2589. $this->load->helper('form');
  2590. $this->load->library('table');
  2591. $this->cp->set_variable('cp_page_title', $this->lang->line('ip_search'));
  2592. $this->javascript->compile();
  2593. $vars['message'] = $message;
  2594. $this->load->view('members/ip_search', $vars);
  2595. }
  2596. // --------------------------------------------------------------------
  2597. /**
  2598. * Do IP Search
  2599. *
  2600. * Executes the search for IP address
  2601. *
  2602. * @access public
  2603. * @return mixed
  2604. */
  2605. function do_ip_search()
  2606. {
  2607. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2608. {
  2609. show_error($this->lang->line('unauthorized_access'));
  2610. }
  2611. $this->lang->loadfile('members');
  2612. $this->load->library('table');
  2613. $this->load->library('pagination');
  2614. $this->load->helper(array('form', 'url'));
  2615. $this->load->model('member_model');
  2616. $grand_total = 0;
  2617. $ip = str_replace('_', '.', $this->input->get_post('ip_address'));
  2618. $url_ip = str_replace('.', '_', $ip);
  2619. if ($ip == '')
  2620. {
  2621. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=ip_search');
  2622. }
  2623. if (strlen($ip) < 3)
  2624. {
  2625. $this->functions->redirect(BASE.AMP.'C=members'.AMP.'M=ip_search'.AMP.'error=1'.AMP.'ip_address='.$url_ip);
  2626. }
  2627. // Set some defaults for pagination
  2628. $per_page = ($this->input->get('per_page') != '') ? $this->input->get('per_page') : '0';
  2629. // Find Member Accounts with IP
  2630. $this->db->from('members');
  2631. $this->db->like('ip_address', $ip);
  2632. $total = $this->db->count_all_results(); // for paging
  2633. $config['base_url'] = BASE.AMP.'C=members'.AMP.'M=do_ip_search'.AMP.'ip_address='.$url_ip;
  2634. $config['per_page'] = '10';
  2635. $config['total_rows'] = $total;
  2636. $config['page_query_string'] = TRUE;
  2637. $config['full_tag_open'] = '<p id="paginationLinks">';
  2638. $config['full_tag_close'] = '</p>';
  2639. $config['prev_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_prev_button.gif" width="13" height="13" alt="&lt;" />';
  2640. $config['next_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_next_button.gif" width="13" height="13" alt="&gt;" />';
  2641. $config['first_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_first_button.gif" width="13" height="13" alt="&lt; &lt;" />';
  2642. $config['last_link'] = '<img src="'.$this->cp->cp_theme_url.'images/pagination_last_button.gif" width="13" height="13" alt="&gt; &gt;" />';
  2643. $this->pagination->initialize($config);
  2644. $vars['member_accounts_pagination'] = $this->pagination->create_links();
  2645. $vars['members_accounts'] = $this->member_model->get_ip_members($ip, 10, $per_page);
  2646. // Find Channel Entries with IP
  2647. $sql = "SELECT COUNT(*) AS count
  2648. FROM exp_channel_titles t, exp_members m, exp_sites s
  2649. WHERE t.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2650. AND t.site_id = s.site_id
  2651. AND t.author_id = m.member_id
  2652. ORDER BY entry_id desc ";
  2653. $query = $this->db->query($sql);
  2654. $total = $query->row('count');
  2655. $grand_total += $total;
  2656. $config['total_rows'] = $total;
  2657. $this->pagination->initialize($config);
  2658. $sql = "SELECT s.site_label, t.entry_id, t.channel_id, t.title, t.ip_address, m.member_id, m.username, m.screen_name, m.email
  2659. FROM exp_channel_titles t, exp_members m, exp_sites s
  2660. WHERE t.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2661. AND t.site_id = s.site_id
  2662. AND t.author_id = m.member_id
  2663. ORDER BY entry_id desc
  2664. LIMIT {$per_page}, 10";
  2665. $vars['channel_entries_pagination'] = $this->pagination->create_links();
  2666. $vars['channel_entries'] = $this->db->query($sql);
  2667. // Find Comments with IP
  2668. // But only if the comment module is installed
  2669. $this->db->from('modules');
  2670. $this->db->where('module_name', 'Comment');
  2671. $comment_installed = $this->db->count_all_results();
  2672. if ($comment_installed == 1)
  2673. {
  2674. $sql = "SELECT COUNT(*) AS count
  2675. FROM exp_channel_titles t, exp_members m, exp_sites s
  2676. WHERE t.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2677. AND t.site_id = s.site_id
  2678. AND t.author_id = m.member_id
  2679. ORDER BY entry_id desc ";
  2680. $query = $this->db->query($sql);
  2681. $total = $query->row('count');
  2682. $grand_total += $total;
  2683. $config['total_rows'] = $total;
  2684. $this->pagination->initialize($config);
  2685. $sql = "SELECT s.site_label, t.entry_id, t.channel_id, t.title, t.ip_address, m.member_id, m.username, m.screen_name, m.email
  2686. FROM exp_channel_titles t, exp_members m, exp_sites s
  2687. WHERE t.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2688. AND t.site_id = s.site_id
  2689. AND t.author_id = m.member_id
  2690. ORDER BY entry_id desc
  2691. LIMIT {$per_page}, 10";
  2692. $vars['channel_entries_pagination'] = $this->pagination->create_links();
  2693. $vars['channel_entries'] = $this->db->query($sql);
  2694. }
  2695. // Find Forum Topics with IP
  2696. // But only if the forum module is installed
  2697. $this->db->from('modules');
  2698. $this->db->where('module_name', 'Forum');
  2699. $forum_installed = $this->db->count_all_results();
  2700. if ($forum_installed == 1)
  2701. {
  2702. $sql = "SELECT COUNT(*) AS count
  2703. FROM exp_forum_topics f, exp_members m, exp_forum_boards b
  2704. WHERE f.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2705. AND f.board_id = b.board_id
  2706. AND f.author_id = m.member_id
  2707. ORDER BY f.topic_id desc";
  2708. $query = $this->db->query($sql);
  2709. $total = $query->row('count');
  2710. $grand_total += $total;
  2711. $config['total_rows'] = $total;
  2712. $this->pagination->initialize($config);
  2713. $sql = "SELECT f.topic_id, f.forum_id, f.title, f.ip_address, m.member_id, m.screen_name, m.email, b.board_forum_url
  2714. FROM exp_forum_topics f, exp_members m, exp_forum_boards b
  2715. WHERE f.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2716. AND f.board_id = b.board_id
  2717. AND f.author_id = m.member_id
  2718. ORDER BY f.topic_id desc
  2719. LIMIT {$per_page}, 10";
  2720. $vars['forum_topics_pagination'] = $this->pagination->create_links();
  2721. $vars['forum_topics'] = $this->db->query($sql);
  2722. // Find Forum Posts with IP
  2723. $sql = "SELECT COUNT(*) AS count
  2724. FROM exp_forum_posts p, exp_members m
  2725. WHERE p.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2726. AND p.author_id = m.member_id
  2727. ORDER BY p.topic_id desc";
  2728. $query = $this->db->query($sql);
  2729. $total = $query->row('count');
  2730. $grand_total += $total;
  2731. $config['total_rows'] = $total;
  2732. $this->pagination->initialize($config);
  2733. $sql = "SELECT p.post_id, p.forum_id, p.body, p.ip_address, m.member_id, m.screen_name, m.email, b.board_forum_url
  2734. FROM exp_forum_posts p, exp_members m, exp_forum_boards b
  2735. WHERE p.ip_address LIKE '%".$this->db->escape_like_str($ip)."%'
  2736. AND p.author_id = m.member_id
  2737. AND p.board_id = b.board_id
  2738. ORDER BY p.topic_id desc
  2739. LIMIT {$per_page}, 10";
  2740. $vars['forum_posts_pagination'] = $this->pagination->create_links();
  2741. $vars['forum_posts'] = $this->db->query($sql);
  2742. }
  2743. $this->cp->set_variable('cp_page_title', $this->lang->line('ip_search'));
  2744. $this->javascript->compile();
  2745. $vars['grand_total'] = $grand_total;
  2746. $this->load->view('members/ip_search_results', $vars);
  2747. }
  2748. // --------------------------------------------------------------------
  2749. /**
  2750. * Member Validation
  2751. *
  2752. * @access public
  2753. * @return mixed
  2754. */
  2755. function member_validation()
  2756. {
  2757. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members'))
  2758. {
  2759. show_error($this->lang->line('unauthorized_access'));
  2760. }
  2761. $this->load->library('table');
  2762. $this->load->helper(array('form', 'url'));
  2763. $vars['message'] = FALSE;
  2764. $this->cp->set_variable('cp_page_title', $this->lang->line('member_validation'));
  2765. $this->jquery->tablesorter('.mainTable', '{headers: {1: {sorter: false}}, widgets: ["zebra"]}');
  2766. $this->javascript->output('
  2767. $("#toggle_all").click(function() {
  2768. var checked_status = this.checked;
  2769. $("input.toggle").each(function() {
  2770. this.checked = checked_status;
  2771. });
  2772. });
  2773. ');
  2774. $this->javascript->compile();
  2775. $group_members = $this->member_model->get_group_members(4);
  2776. if ($group_members->num_rows() == 0)
  2777. {
  2778. $vars['message'] = $this->lang->line('no_members_to_validate');
  2779. }
  2780. $vars['member_list'] = $group_members;
  2781. $this->load->view('members/activate', $vars);
  2782. }
  2783. // --------------------------------------------------------------------
  2784. /**
  2785. * Validate Members
  2786. *
  2787. * Validate/Delete Selected Members
  2788. *
  2789. * @access public
  2790. * @return mixed
  2791. */
  2792. function validate_members()
  2793. {
  2794. if ( ! $this->cp->allowed_group('can_access_members') OR ! $this->cp->allowed_group('can_admin_members') OR ! $this->cp->allowed_group('can_delete_members'))
  2795. {
  2796. show_error($this->lang->line('unauthorized_access'));
  2797. }
  2798. if ( ! $this->input->post('toggle'))
  2799. {
  2800. return $this->member_validation();
  2801. }
  2802. $send_email = (isset($_POST['send_notification'])) ? TRUE : FALSE;
  2803. if ($send_email == TRUE)
  2804. {
  2805. if ($this->input->post('action') == 'activate')
  2806. {
  2807. $template = $this->functions->fetch_email_template('validated_member_notify');
  2808. }
  2809. else
  2810. {
  2811. $template = $this->functions->fetch_email_template('decline_member_validation');
  2812. }
  2813. $this->load->library('email');
  2814. $this->email->wordwrap = true;
  2815. }
  2816. $group_id = $this->config->item('default_member_group');
  2817. // Load the text helper
  2818. $this->load->helper('text');
  2819. foreach ($_POST['toggle'] as $key => $val)
  2820. {
  2821. if ($send_email == TRUE)
  2822. {
  2823. $this->db->select('username, screen_name, email');
  2824. $this->db->from('members');
  2825. $this->db->where('member_id', $val);
  2826. $this->db->where('email != ""');
  2827. $query = $this->db->get();
  2828. if ($query->num_rows() == 1)
  2829. {
  2830. $swap = array(
  2831. 'name' => ($query->row('screen_name') != '') ? $query->row('screen_name') : $query->row('username') ,
  2832. 'site_name' => stripslashes($this->config->item('site_name')),
  2833. 'site_url' => $this->config->item('site_url')
  2834. );
  2835. $email_tit = $this->functions->var_swap($template['title'], $swap);
  2836. $email_msg = $this->functions->var_swap($template['data'], $swap);
  2837. $this->email->EE_initialize();
  2838. $this->email->from($this->config->item('webmaster_email'), $this->config->item('webmaster_name'));
  2839. $this->email->to($query->row('email') );
  2840. $this->email->subject($email_tit);
  2841. $this->email->message(entities_to_ascii($email_msg));
  2842. $this->email->send();
  2843. }
  2844. }
  2845. if ($this->input->post('action') == 'activate')
  2846. {
  2847. $this->db->set('group_id', $group_id);
  2848. $this->db->where('member_id', $val);
  2849. $this->db->update('members');
  2850. }
  2851. else
  2852. {
  2853. $this->db->query("DELETE FROM exp_members WHERE member_id = '$val'");
  2854. $this->db->query("DELETE FROM exp_member_data WHERE member_id = '$val'");
  2855. $this->db->query("DELETE FROM exp_member_homepage WHERE member_id = '$val'");
  2856. $message_query = $this->db->query("SELECT DISTINCT recipient_id FROM exp_message_copies WHERE sender_id = '$val' AND message_read = 'n'");
  2857. $this->db->query("DELETE FROM exp_message_copies WHERE sender_id = '$val'");
  2858. $this->db->query("DELETE FROM exp_message_data WHERE sender_id = '$val'");
  2859. $this->db->query("DELETE FROM exp_message_folders WHERE member_id = '$val'");
  2860. $this->db->query("DELETE FROM exp_message_listed WHERE member_id = '$val'");
  2861. if ($message_query->num_rows() > 0)
  2862. {
  2863. foreach($message_query->result_array() as $row)
  2864. {
  2865. $count_query = $this->db->query("SELECT COUNT(*) AS count FROM exp_message_copies WHERE recipient_id = '".$row['recipient_id']."' AND message_read = 'n'");
  2866. $this->db->query($this->db->update_string('exp_members', array('private_messages' => $count_query->row('count') ), "member_id = '".$row['recipient_id']."'"));
  2867. }
  2868. }
  2869. }
  2870. }
  2871. $this->stats->update_member_stats();
  2872. /* -------------------------------------------
  2873. /* 'cp_members_validate_members' hook.
  2874. /* - Additional processing when member(s) are validated in the CP
  2875. /* - Added 1.5.2, 2006-12-28
  2876. */
  2877. $edata = $this->extensions->call('cp_members_validate_members');
  2878. if ($this->extensions->end_script === TRUE) return;
  2879. /*
  2880. /* -------------------------------------------*/
  2881. $vars['message'] = ($this->input->post('action') == 'activate') ? $this->lang->line('members_are_validated') : $this->lang->line('members_are_deleted');
  2882. $this->cp->set_variable('cp_page_title', $vars['message']);
  2883. $this->load->view("members/message", $vars);
  2884. }
  2885. }
  2886. /* End of file members.php */
  2887. /* Location: ./system/expressionengine/controllers/cp/members.php */