PageRenderTime 55ms CodeModel.GetById 13ms 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

Large files files are truncated, but you can click here to view the full file

  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…

Large files files are truncated, but you can click here to view the full file