PageRenderTime 90ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/system/cp/cp.members.php

https://github.com/danboy/Croissierd
PHP | 5601 lines | 3639 code | 1365 blank | 597 comment | 544 complexity | 2223e2fee1dd8e25ecf455659a1e1645 MD5 | raw file
  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: cp.members.php
  15. -----------------------------------------------------
  16. Purpose: Member management functions
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  22. }
  23. class Members {
  24. // Default member groups. We used these for translation purposes
  25. var $english = array('Guests', 'Banned', 'Members', 'Pending', 'Super Admins');
  26. var $perpage = 50; // Number of results on the "View all member" page
  27. var $no_delete = array('1', '2', '3', '4'); // Member groups that can not be deleted
  28. /** -----------------------------
  29. /** Constructor
  30. /** -----------------------------*/
  31. function Members()
  32. {
  33. global $LANG;
  34. // Fetch the language files
  35. $LANG->fetch_language_file('myaccount');
  36. $LANG->fetch_language_file('members');
  37. }
  38. /* END */
  39. /** -----------------------------
  40. /** View all members
  41. /** -----------------------------*/
  42. function view_all_members($message = '')
  43. {
  44. global $IN, $LANG, $DSP, $LOC, $DB, $PREFS;
  45. // These variables are only set when one of the pull-down menus is used
  46. // We use it to construct the SQL query with
  47. $group_id = $IN->GBL('group_id', 'GP');
  48. $order = $IN->GBL('order', 'GP');
  49. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members");
  50. $total_members = $query->row['count'];
  51. // Begin building the page output
  52. $r = $DSP->qdiv('tableHeading', $LANG->line('view_members'));
  53. if ($message != '')
  54. {
  55. $r .= $DSP->qdiv('box', $message);
  56. }
  57. // Declare the "filtering" form
  58. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=view_members'));
  59. $DSP->right_crumb($LANG->line('new_member_search'), BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=member_search');
  60. // Table start
  61. $r .= $DSP->div('box');
  62. $r .= $DSP->table('', '0', '', '100%').
  63. $DSP->tr().
  64. $DSP->td('itemWrapper', '', '5').NL;
  65. // Member group selection pull-down menu
  66. $r .= $DSP->input_select_header('group_id').
  67. $DSP->input_select_option('', $LANG->line('member_groups')).
  68. $DSP->input_select_option('', $LANG->line('all'));
  69. // Fetch the names of all member groups and write each one in an <option> field
  70. $query = $DB->query("SELECT group_title, group_id FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' order by group_title");
  71. foreach ($query->result as $row)
  72. {
  73. $group_name = $row['group_title'];
  74. if (in_array($group_name, $this->english))
  75. {
  76. $group_name = $LANG->line(strtolower(str_replace(" ", "_", $group_name)));
  77. }
  78. $r .= $DSP->input_select_option($row['group_id'], $group_name, ($group_id == $row['group_id']) ? 1 : '');
  79. }
  80. $r .= $DSP->input_select_footer().
  81. $DSP->nbs(2);
  82. // "display order" pull-down menu
  83. $sel_1 = ($order == 'desc') ? 1 : '';
  84. $sel_2 = ($order == 'asc') ? 1 : '';
  85. $sel_3 = ($order == 'username') ? 1 : '';
  86. $sel_4 = ($order == 'username_desc') ? 1 : '';
  87. $sel_5 = ($order == 'screen_name') ? 1 : '';
  88. $sel_6 = ($order == 'screen_name_desc') ? 1 : '';
  89. $sel_7 = ($order == 'email') ? 1 : '';
  90. $sel_8 = ($order == 'email_desc') ? 1 : '';
  91. $r .= $DSP->input_select_header('order').
  92. $DSP->input_select_option('desc', $LANG->line('sort_order'), $sel_1).
  93. $DSP->input_select_option('asc', $LANG->line('ascending'), $sel_2).
  94. $DSP->input_select_option('desc', $LANG->line('descending'), $sel_1).
  95. $DSP->input_select_option('username_asc', $LANG->line('username_asc'), $sel_3).
  96. $DSP->input_select_option('username_desc', $LANG->line('username_desc'), $sel_4).
  97. $DSP->input_select_option('screen_name_asc', $LANG->line('screen_name_asc'), $sel_5).
  98. $DSP->input_select_option('screen_name_desc', $LANG->line('screen_name_desc'), $sel_6).
  99. $DSP->input_select_option('email_asc', $LANG->line('email_asc'), $sel_7).
  100. $DSP->input_select_option('email_desc', $LANG->line('email_desc'), $sel_8).
  101. $DSP->input_select_footer().
  102. $DSP->nbs(2);
  103. // Submit button and close filtering form
  104. $r .= $DSP->input_submit($LANG->line('submit'), 'submit');
  105. $r .= $DSP->td_c().
  106. $DSP->td('defaultRight', '', 2).
  107. $DSP->heading($LANG->line('total_members').NBS.NBS.$total_members.NBS.NBS.NBS.NBS.NBS, 5).
  108. $DSP->td_c().
  109. $DSP->tr_c().
  110. $DSP->table_c();
  111. $r .= $DSP->div_c();
  112. $r .= $DSP->form_close();
  113. // Build the SQL query as well as the query string for the paginate links
  114. $pageurl = BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=view_members';
  115. if ($group_id)
  116. {
  117. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE group_id = ".$group_id);
  118. $total_count = $query->row['count'];
  119. }
  120. else
  121. {
  122. $total_count = $total_members;
  123. }
  124. // No result? Show the "no results" message
  125. if ($total_count == 0)
  126. {
  127. $r .= $DSP->qdiv('', BR.$LANG->line('no_members_matching_that_criteria'));
  128. return $DSP->set_return_data( $LANG->line('view_members'),
  129. $r,
  130. $LANG->line('view_members')
  131. );
  132. }
  133. // Get the current row number and add the LIMIT clause to the SQL query
  134. if ( ! $rownum = $IN->GBL('rownum', 'GP'))
  135. {
  136. $rownum = 0;
  137. }
  138. $sql = "SELECT member_id FROM exp_members ";
  139. if ($group_id)
  140. {
  141. $sql .= " WHERE group_id = $group_id";
  142. $pageurl .= AMP.'group_id='.$group_id;
  143. }
  144. $o_sql = " ORDER BY ";
  145. if ($order)
  146. {
  147. $pageurl .= AMP.'order='.$order;
  148. switch ($order)
  149. {
  150. case 'asc' : $o_sql .= "join_date asc";
  151. break;
  152. case 'desc' : $o_sql .= "join_date desc";
  153. break;
  154. case 'username_asc' : $o_sql .= "username asc";
  155. break;
  156. case 'username_desc' : $o_sql .= "username desc";
  157. break;
  158. case 'screen_name_asc' : $o_sql .= "screen_name asc";
  159. break;
  160. case 'screen_name_desc' : $o_sql .= "screen_name desc";
  161. break;
  162. case 'email_asc' : $o_sql .= "email asc";
  163. break;
  164. case 'email_desc' : $o_sql .= "email desc";
  165. break;
  166. default : $o_sql .= "join_date desc";
  167. }
  168. }
  169. else
  170. {
  171. $o_sql .= "join_date desc";
  172. }
  173. $query = $DB->query($sql.$o_sql." LIMIT ".$rownum.", ".$this->perpage);
  174. $sql = "SELECT exp_members.username,
  175. exp_members.member_id,
  176. exp_members.screen_name,
  177. exp_members.email,
  178. exp_members.join_date,
  179. exp_members.last_visit,
  180. exp_member_groups.group_title
  181. FROM exp_members, exp_member_groups
  182. WHERE exp_members.group_id = exp_member_groups.group_id
  183. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  184. AND exp_members.member_id IN (";
  185. foreach ($query->result as $row)
  186. {
  187. $sql .= $row['member_id'].',';
  188. }
  189. $sql = substr($sql, 0, -1).')';
  190. $query = $DB->query($sql.$o_sql);
  191. // "select all" checkbox
  192. $r .= $DSP->toggle();
  193. $DSP->body_props .= ' onload="magic_check()" ';
  194. $r .= $DSP->magic_checkboxes();
  195. // Declare the "delete" form
  196. $r .= $DSP->form_open(
  197. array(
  198. 'action' => 'C=admin'.AMP.'M=members'.AMP.'P=mbr_conf',
  199. 'name' => 'target',
  200. 'id' => 'target'
  201. )
  202. );
  203. // Build the table heading
  204. $r .= $DSP->table('tableBorder', '0', '', '100%').
  205. $DSP->tr().
  206. $DSP->table_qcell('tableHeadingAlt', $LANG->line('username')).
  207. $DSP->table_qcell('tableHeadingAlt', $LANG->line('screen_name')).
  208. $DSP->table_qcell('tableHeadingAlt', $LANG->line('email')).
  209. $DSP->table_qcell('tableHeadingAlt', $LANG->line('join_date')).
  210. $DSP->table_qcell('tableHeadingAlt', $LANG->line('last_visit')).
  211. $DSP->table_qcell('tableHeadingAlt', $LANG->line('member_group')).
  212. $DSP->table_qcell('tableHeadingAlt', $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"")).
  213. $DSP->tr_c();
  214. // Loop through the query result and write each table row
  215. $i = 0;
  216. foreach($query->result as $row)
  217. {
  218. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  219. $r .= $DSP->tr();
  220. // Username
  221. $r .= $DSP->table_qcell($style,
  222. $DSP->anchor(
  223. BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'],
  224. '<b>'.$row['username'].'</b>'
  225. )
  226. );
  227. // Screen name
  228. $screen = ($row['screen_name'] == '') ? "--" : '<b>'.$row['screen_name'].'</b>';
  229. $r .= $DSP->table_qcell($style, $screen);
  230. // Email
  231. $r .= $DSP->table_qcell($style,
  232. $DSP->mailto($row['email'], $row['email'])
  233. );
  234. // Join date
  235. $r .= $DSP->td($style).
  236. $LOC->convert_timestamp('%Y', $row['join_date']).'-'.
  237. $LOC->convert_timestamp('%m', $row['join_date']).'-'.
  238. $LOC->convert_timestamp('%d', $row['join_date']).
  239. $DSP->td_c();
  240. // Last visit date
  241. $r .= $DSP->td($style);
  242. if ($row['last_visit'] != 0)
  243. {
  244. $r .= $LOC->set_human_time($row['last_visit']);
  245. }
  246. else
  247. {
  248. $r .= "--";
  249. }
  250. $r .= $DSP->td_c();
  251. // Member group
  252. $r .= $DSP->td($style);
  253. $group_name = $row['group_title'];
  254. if (in_array($group_name, $this->english))
  255. {
  256. $group_name = $LANG->line(strtolower(str_replace(" ", "_", $group_name)));
  257. }
  258. $r .= $group_name;
  259. $r .= $DSP->td_c();
  260. // Delete checkbox
  261. $r .= $DSP->table_qcell($style, $DSP->input_checkbox('toggle[]', $row['member_id'], '', ' id="delete_box_'.$row['member_id'].'"'));
  262. $r .= $DSP->tr_c();
  263. } // End foreach
  264. $r .= $DSP->table_c();
  265. $r .= $DSP->table('', '0', '', '98%');
  266. $r .= $DSP->tr().
  267. $DSP->td();
  268. // Pass the relevant data to the paginate class so it can display the "next page" links
  269. $r .= $DSP->div('crumblinks').
  270. $DSP->pager(
  271. $pageurl,
  272. $total_count,
  273. $this->perpage,
  274. $rownum,
  275. 'rownum'
  276. ).
  277. $DSP->div_c().
  278. $DSP->td_c().
  279. $DSP->td('defaultRight');
  280. // Delete button
  281. $r .= $DSP->input_submit($LANG->line('submit'));
  282. $r .= NBS.$DSP->input_select_header('action');
  283. if ($group_id == '4' && $PREFS->ini('req_mbr_activation') == 'email' && $DSP->allowed_group('can_admin_members'))
  284. {
  285. $r .= $DSP->input_select_option('resend', $LANG->line('resend_activation_emails'));
  286. }
  287. $r .= $DSP->input_select_option('delete', $LANG->line('delete_selected')).
  288. $DSP->input_select_footer().
  289. $DSP->td_c().
  290. $DSP->tr_c();
  291. // Table end
  292. $r .= $DSP->table_c().
  293. $DSP->form_close();
  294. // Set output data
  295. $DSP->title = $LANG->line('view_members');
  296. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  297. $DSP->crumb_item($LANG->line('view_members'));
  298. $DSP->body = $r;
  299. }
  300. /* END */
  301. /** -----------------------------------------------------------
  302. /** Member Action Confirm
  303. /** -----------------------------------------------------------*/
  304. function member_confirm()
  305. {
  306. if (isset($_POST['action']) && $_POST['action'] == 'resend')
  307. {
  308. $this->resend_activation_emails();
  309. }
  310. else
  311. {
  312. $this->member_delete_confirm();
  313. }
  314. }
  315. /* END */
  316. /** -----------------------------------------------------------
  317. /** Resend Pending Member's Activation Emails
  318. /** -----------------------------------------------------------*/
  319. function resend_activation_emails()
  320. {
  321. global $DSP, $LANG, $DB, $PREFS, $IN, $FNS, $REGX;
  322. if ( ! $DSP->allowed_group('can_admin_members') OR $PREFS->ini('req_mbr_activation') !== 'email')
  323. {
  324. return $DSP->no_access_message();
  325. }
  326. if ($IN->GBL('mid', 'GET') !== FALSE)
  327. {
  328. $_POST['toggle'] = $IN->GBL('mid', 'GET');
  329. }
  330. if ( ! $IN->GBL('toggle', 'POST'))
  331. {
  332. return $this->view_all_members();
  333. }
  334. $damned = array();
  335. foreach ($_POST as $key => $val)
  336. {
  337. if (strstr($key, 'toggle') AND ! is_array($val))
  338. {
  339. $damned[] = $DB->escape_str($val);
  340. }
  341. }
  342. if (sizeof($damned) == 0)
  343. {
  344. return $this->view_all_members();
  345. }
  346. $query = $DB->query("SELECT screen_name, username, email, authcode FROM exp_members WHERE member_id IN ('".implode("','", $damned)."')");
  347. if ($query->num_rows == 0)
  348. {
  349. return $this->view_all_members();
  350. }
  351. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  352. $action_id = $FNS->fetch_action_id('Member', 'activate_member');
  353. $template = $FNS->fetch_email_template('mbr_activation_instructions');
  354. $swap = array(
  355. 'site_name' => stripslashes($PREFS->ini('site_name')),
  356. 'site_url' => $PREFS->ini('site_url')
  357. );
  358. if ( ! class_exists('EEmail'))
  359. {
  360. require PATH_CORE.'core.email'.EXT;
  361. }
  362. $email = new EEmail;
  363. foreach($query->result as $row)
  364. {
  365. $swap['name'] = ($row['screen_name'] != '') ? $row['screen_name'] : $row['username'];
  366. $swap['activation_url'] = $FNS->fetch_site_index(0, 0).$qs.'ACT='.$action_id.'&id='.$row['authcode'];
  367. $swap['username'] = $row['username'];
  368. $swap['email'] = $row['email'];
  369. /** ----------------------------
  370. /** Send email
  371. /** ----------------------------*/
  372. $email->initialize();
  373. $email->wordwrap = true;
  374. $email->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));
  375. $email->to($row['email']);
  376. $email->subject($FNS->var_swap($template['title'], $swap));
  377. $email->message($REGX->entities_to_ascii($FNS->var_swap($template['data'], $swap)));
  378. $email->Send();
  379. }
  380. return $this->view_all_members($DSP->qdiv('success', $LANG->line(($IN->GBL('mid', 'GET') !== FALSE) ? 'activation_email_resent' : 'activation_emails_resent')));
  381. }
  382. /* END */
  383. /** -----------------------------------------------------------
  384. /** Delete Member (confirm)
  385. /** -----------------------------------------------------------*/
  386. // Warning message if you try to delete members
  387. //-----------------------------------------------------------
  388. function member_delete_confirm()
  389. {
  390. global $IN, $DSP, $LANG, $DB, $SESS, $PREFS;
  391. if ( ! $DSP->allowed_group('can_delete_members'))
  392. {
  393. return $DSP->no_access_message();
  394. }
  395. $from_myaccount = FALSE;
  396. $entries_exit = FALSE;
  397. if ($IN->GBL('mid', 'GET') !== FALSE)
  398. {
  399. $from_myaccount = TRUE;
  400. $_POST['toggle'] = $IN->GBL('mid', 'GET');
  401. }
  402. if ( ! $IN->GBL('toggle', 'POST'))
  403. {
  404. return $this->view_all_members();
  405. }
  406. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=mbr_delete'));
  407. $i = 0;
  408. $damned = array();
  409. foreach ($_POST as $key => $val)
  410. {
  411. if (strstr($key, 'toggle') AND ! is_array($val))
  412. {
  413. $r .= $DSP->input_hidden('delete[]', $val);
  414. // Is the user trying to delete himself?
  415. if ($SESS->userdata('member_id') == $val)
  416. {
  417. return $DSP->error_message($LANG->line('can_not_delete_self'));
  418. }
  419. $damned[] = $DB->escape_str($val);
  420. $i++;
  421. }
  422. }
  423. $r .= $DSP->qdiv('alertHeading', $LANG->line('delete_member'));
  424. $r .= $DSP->div('box');
  425. if ($i == 1)
  426. {
  427. $r .= $DSP->qdiv('itemWrapper', '<b>'.$LANG->line('delete_member_confirm').'</b>');
  428. $query = $DB->query("SELECT screen_name FROM exp_members WHERE member_id = '".$DB->escape_str($damned['0'])."'");
  429. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $query->row['screen_name']));
  430. }
  431. else
  432. {
  433. $r .= '<b>'.$LANG->line('delete_members_confirm').'</b>';
  434. }
  435. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('alert', $LANG->line('action_can_not_be_undone')));
  436. /** ----------------------------------------------------------
  437. /** Do the users being deleted have entries assigned to them?
  438. /** ----------------------------------------------------------*/
  439. $sql = "SELECT COUNT(entry_id) AS count FROM exp_weblog_titles WHERE author_id ";
  440. if ($i == 1)
  441. {
  442. $sqlb = "= '".$DB->escape_str($damned['0'])."'";
  443. }
  444. else
  445. {
  446. $sqlb = " IN ('".implode("','",$damned)."')";
  447. }
  448. $query = $DB->query($sql.$sqlb);
  449. if ($query->row['count'] > 0)
  450. {
  451. $entries_exit = TRUE;
  452. $r .= $DSP->input_hidden('entries_exit', 'yes');
  453. }
  454. if ($DB->table_exists('exp_gallery_entries') === TRUE)
  455. {
  456. $sql = "SELECT COUNT(entry_id) AS count FROM exp_gallery_entries WHERE author_id ";
  457. $query = $DB->query($sql.$sqlb);
  458. if ($query->row['count'] > 0)
  459. {
  460. $entries_exit = TRUE;
  461. $r .= $DSP->input_hidden('gallery_entries_exit', 'yes');
  462. }
  463. }
  464. /** ----------------------------------------------------------
  465. /** If so, fetch the member names for reassigment
  466. /** ----------------------------------------------------------*/
  467. if ($entries_exit == TRUE)
  468. {
  469. // Fetch the member_group of each user being deleted
  470. $sql = "SELECT group_id FROM exp_members WHERE member_id ";
  471. if ($i == 1)
  472. {
  473. $sql .= " = '".$DB->escape_str($damned['0'])."'";
  474. }
  475. else
  476. {
  477. $sql .= " IN ('".implode("','",$damned)."')";
  478. }
  479. $query = $DB->query($sql);
  480. $group_ids[] = 1;
  481. if ($query->num_rows > 0)
  482. {
  483. foreach($query->result as $row)
  484. {
  485. $group_ids[] = $row['group_id'];
  486. }
  487. }
  488. $group_ids = array_unique($group_ids);
  489. // Find Valid Member Replacements
  490. $query = $DB->query("SELECT exp_members.member_id, username, screen_name
  491. FROM exp_members
  492. LEFT JOIN exp_member_groups on exp_member_groups.group_id = exp_members.group_id
  493. WHERE exp_member_groups.group_id IN (".implode(",",$group_ids).")
  494. AND exp_members.member_id NOT IN ('".implode("','",$damned)."')
  495. AND (exp_members.in_authorlist = 'y' OR exp_member_groups.include_in_authorlist = 'y')
  496. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  497. ORDER BY screen_name asc, username asc");
  498. if ($query->num_rows == 0)
  499. {
  500. $query = $DB->query("SELECT member_id, username, screen_name
  501. FROM exp_members
  502. WHERE group_id = 1
  503. AND member_id NOT IN ('".implode("','",$damned)."')
  504. ORDER BY screen_name asc, username asc");
  505. }
  506. $r .= $DSP->div('itemWrapper');
  507. $r .= $DSP->div('defaultBold');
  508. $r .= ($i == 1) ? $LANG->line('heir_to_member_entries') : $LANG->line('heir_to_members_entries');
  509. $r .= $DSP->div_c();
  510. $r .= $DSP->div('itemWrapper');
  511. $r .= $DSP->input_select_header('heir');
  512. foreach($query->result as $row)
  513. {
  514. $r .= $DSP->input_select_option($row['member_id'], ($row['screen_name'] != '') ? $row['screen_name'] : $row['username']);
  515. }
  516. $r .= $DSP->input_select_footer();
  517. $r .= $DSP->div_c();
  518. $r .= $DSP->div_c();
  519. }
  520. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('delete'))).
  521. $DSP->div_c().
  522. $DSP->form_close();
  523. $DSP->title = $LANG->line('delete_member');
  524. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  525. $DSP->crumb_item($LANG->line('delete_member'));
  526. $DSP->body = $r;
  527. }
  528. /* END */
  529. /** ----------------------------------------------
  530. /** Login as Member - SuperAdmins only!
  531. /** ----------------------------------------------*/
  532. function login_as_member()
  533. {
  534. global $IN, $DSP, $LANG, $DB, $SESS, $PREFS, $FNS, $LOG;
  535. if ($SESS->userdata['group_id'] != 1)
  536. {
  537. return $DSP->no_access_message();
  538. }
  539. if (($id = $IN->GBL('mid', 'GET')) === FALSE)
  540. {
  541. return $DSP->no_access_message();
  542. }
  543. if ($SESS->userdata['member_id'] == $id)
  544. {
  545. return $DSP->no_access_message();
  546. }
  547. /** ----------------------------------------
  548. /** Fetch member data
  549. /** ----------------------------------------*/
  550. $sql = "SELECT exp_members.screen_name, exp_member_groups.can_access_cp
  551. FROM exp_members, exp_member_groups
  552. WHERE member_id = '".$DB->escape_str($id)."'
  553. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  554. AND exp_members.group_id = exp_member_groups.group_id";
  555. $query = $DB->query($sql);
  556. if ($query->num_rows == 0)
  557. {
  558. return $DSP->no_access_message();
  559. }
  560. $DSP->title = $LANG->line('login_as_member');
  561. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  562. $DSP->crumb_item($LANG->line('login_as_member'));
  563. /** ----------------------------------------
  564. /** Create Our Little Redirect Form
  565. /** ----------------------------------------*/
  566. $r = $DSP->form_open(
  567. array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=do_login_as_member'),
  568. array('mid' => $id)
  569. );
  570. $r .= $DSP->qdiv('default', '', 'menu_contents');
  571. $r .= $DSP->table('tableBorder', '0', '', '100%');
  572. $r .= $DSP->tr().
  573. $DSP->td('tableHeadingAlt', '', '2').$LANG->line('login_as_member').
  574. $DSP->td_c().
  575. $DSP->tr_c();
  576. $r .= $DSP->tr().
  577. $DSP->td('tableCellOne').
  578. $DSP->qdiv('alert', $LANG->line('action_can_not_be_undone')).
  579. $DSP->qdiv('itemWrapper', str_replace('%screen_name%', $query->row['screen_name'], $LANG->line('login_as_member_description'))).
  580. $DSP->td_c().
  581. $DSP->tr_c();
  582. $r .= $DSP->tr().
  583. $DSP->td('tableCellTwo');
  584. $r .= $DSP->qdiv('',
  585. $DSP->input_radio('return_destination', 'site', 1).$DSP->nbs(3).
  586. $LANG->line('site_homepage')
  587. );
  588. if ($query->row['can_access_cp'] == 'y')
  589. {
  590. $r .= $DSP->qdiv('',
  591. $DSP->input_radio('return_destination', 'cp').$DSP->nbs(3).
  592. $LANG->line('control_panel')
  593. );
  594. }
  595. $r .= $DSP->qdiv('',
  596. $DSP->input_radio('return_destination', 'other', '').$DSP->nbs(3).
  597. $LANG->line('other').NBS.':'.NBS.$DSP->input_text('other_url', $FNS->fetch_site_index(), '30', '80', 'input', '500px')
  598. );
  599. $r .= $DSP->td_c().
  600. $DSP->tr_c().
  601. $DSP->tr().
  602. $DSP->td('tableCellOne').
  603. $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('submit'), 'submit')).
  604. $DSP->td_c().
  605. $DSP->tr_c().
  606. $DSP->table_c().
  607. $DSP->div_c();
  608. $DSP->body = $r;
  609. }
  610. /* END */
  611. /** ----------------------------------------------
  612. /** Login as Member - SuperAdmins only!
  613. /** ----------------------------------------------*/
  614. function do_login_as_member()
  615. {
  616. global $IN, $DSP, $LANG, $DB, $SESS, $PREFS, $FNS, $LOG, $REGX;
  617. if ($SESS->userdata['group_id'] != 1)
  618. {
  619. return $DSP->no_access_message();
  620. }
  621. if (($id = $IN->GBL('mid')) === FALSE)
  622. {
  623. return $DSP->no_access_message();
  624. }
  625. if ($SESS->userdata['member_id'] == $id)
  626. {
  627. return $DSP->no_access_message();
  628. }
  629. /** ----------------------------------------
  630. /** Fetch member data
  631. /** ----------------------------------------*/
  632. $sql = "SELECT exp_members.username, exp_members.password, exp_members.unique_id, exp_members.member_id, exp_members.group_id, exp_member_groups.can_access_cp
  633. FROM exp_members, exp_member_groups
  634. WHERE member_id = '".$DB->escape_str($id)."'
  635. AND exp_member_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  636. AND exp_members.group_id = exp_member_groups.group_id";
  637. $query = $DB->query($sql);
  638. if ($query->num_rows == 0)
  639. {
  640. return $DSP->no_access_message();
  641. }
  642. $LANG->fetch_language_file('login');
  643. /** --------------------------------------------------
  644. /** Do we allow multiple logins on the same account?
  645. /** --------------------------------------------------*/
  646. if ($PREFS->ini('allow_multi_logins') == 'n')
  647. {
  648. // Kill old sessions first
  649. $SESS->gc_probability = 100;
  650. $SESS->delete_old_sessions();
  651. $expire = time() - $SESS->session_length;
  652. // See if there is a current session
  653. $result = $DB->query("SELECT ip_address, user_agent
  654. FROM exp_sessions
  655. WHERE member_id = '".$query->row['member_id']."'
  656. AND last_activity > $expire");
  657. // If a session exists, trigger the error message
  658. if ($result->num_rows == 1)
  659. {
  660. if ($SESS->userdata['ip_address'] != $result->row['ip_address'] ||
  661. $SESS->userdata['user_agent'] != $result->row['user_agent'] )
  662. {
  663. return $DSP->error_message($LANG->line('multi_login_warning'));
  664. }
  665. }
  666. }
  667. /** ----------------------------------------
  668. /** Log the SuperAdmin login
  669. /** ----------------------------------------*/
  670. $LOG->log_action($LANG->line('login_as_user').':'.NBS.$query->row['username']);
  671. /** ----------------------------------------
  672. /** Set cookies
  673. /** ----------------------------------------*/
  674. // Set cookie expiration to one year if the "remember me" button is clicked
  675. $expire = 0;
  676. $type = (isset($_POST['return_destination']) && $_POST['return_destination'] == 'cp') ? $PREFS->ini('admin_session_type') : $PREFS->ini('user_session_type');
  677. if ($type != 's')
  678. {
  679. $FNS->set_cookie($SESS->c_expire , time()+$expire, $expire);
  680. $FNS->set_cookie($SESS->c_uniqueid , $query->row['unique_id'], $expire);
  681. $FNS->set_cookie($SESS->c_password , $query->row['password'], $expire);
  682. $FNS->set_cookie($SESS->c_anon , 1, $expire);
  683. }
  684. /** ----------------------------------------
  685. /** Create a new session
  686. /** ----------------------------------------*/
  687. $session_id = $SESS->create_new_session($query->row['member_id'], TRUE);
  688. /** ----------------------------------------
  689. /** Delete old password lockouts
  690. /** ----------------------------------------*/
  691. $SESS->delete_password_lockout();
  692. /** ----------------------------------------
  693. /** Redirect the user to the return page
  694. /** ----------------------------------------*/
  695. $return_path = $FNS->fetch_site_index();
  696. if (isset($_POST['return_destination']))
  697. {
  698. if ($_POST['return_destination'] == 'cp')
  699. {
  700. $s = ($PREFS->ini('admin_session_type') != 'c') ? $SESS->userdata['session_id'] : 0;
  701. $return_path = $PREFS->ini('cp_url', FALSE).'?S='.$s;
  702. }
  703. elseif ($_POST['return_destination'] == 'other' && isset($_POST['other_url']) && stristr($_POST['other_url'], 'http'))
  704. {
  705. $return_path = $REGX->xss_clean(strip_tags($_POST['other_url']));
  706. }
  707. }
  708. $FNS->redirect($return_path);
  709. exit;
  710. }
  711. /* END */
  712. /** ---------------------------------------------
  713. /** Delete Members
  714. /** ---------------------------------------------*/
  715. function member_delete()
  716. {
  717. global $IN, $DSP, $PREFS, $LANG, $SESS, $FNS, $DB, $STAT, $EXT;
  718. if ( ! $DSP->allowed_group('can_delete_members'))
  719. {
  720. return $DSP->no_access_message();
  721. }
  722. if ( ! $IN->GBL('delete', 'POST'))
  723. {
  724. return $this->view_all_members();
  725. }
  726. /** ---------------------------------------------
  727. /** Fetch member ID numbers and build the query
  728. /** ---------------------------------------------*/
  729. $ids = array();
  730. $mids = array();
  731. foreach ($_POST as $key => $val)
  732. {
  733. if (strstr($key, 'delete') AND ! is_array($val) AND $val != '')
  734. {
  735. $ids[] = "member_id = '".$DB->escape_str($val)."'";
  736. $mids[] = $DB->escape_str($val);
  737. }
  738. }
  739. $IDS = implode(" OR ", $ids);
  740. // SAFETY CHECK
  741. // Let's fetch the Member Group ID of each member being deleted
  742. // If there is a Super Admin in the bunch we'll run a few more safeties
  743. $super_admins = 0;
  744. $query = $DB->query("SELECT group_id FROM exp_members WHERE ".$IDS);
  745. foreach ($query->result as $row)
  746. {
  747. if ($query->row['group_id'] == 1)
  748. {
  749. $super_admins++;
  750. }
  751. }
  752. if ($super_admins > 0)
  753. {
  754. // You must be a Super Admin to delete a Super Admin
  755. if ($SESS->userdata['group_id'] != 1)
  756. {
  757. return $DSP->error_message($LANG->line('must_be_superadmin_to_delete_one'));
  758. }
  759. // You can't detete the only Super Admin
  760. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE group_id = '1'");
  761. if ($super_admins >= $query->row['count'])
  762. {
  763. return $DSP->error_message($LANG->line('can_not_delete_super_admin'));
  764. }
  765. }
  766. // If we got this far we're clear to delete the members
  767. $DB->query("DELETE FROM exp_members WHERE ".$IDS);
  768. $DB->query("DELETE FROM exp_member_data WHERE ".$IDS);
  769. $DB->query("DELETE FROM exp_member_homepage WHERE ".$IDS);
  770. foreach($mids as $val)
  771. {
  772. $message_query = $DB->query("SELECT DISTINCT recipient_id FROM exp_message_copies WHERE sender_id = '$val' AND message_read = 'n'");
  773. $DB->query("DELETE FROM exp_message_copies WHERE sender_id = '$val'");
  774. $DB->query("DELETE FROM exp_message_data WHERE sender_id = '$val'");
  775. $DB->query("DELETE FROM exp_message_folders WHERE member_id = '$val'");
  776. $DB->query("DELETE FROM exp_message_listed WHERE member_id = '$val'");
  777. if ($message_query->num_rows > 0)
  778. {
  779. foreach($message_query->result as $row)
  780. {
  781. $count_query = $DB->query("SELECT COUNT(*) AS count FROM exp_message_copies WHERE recipient_id = '".$row['recipient_id']."' AND message_read = 'n'");
  782. $DB->query($DB->update_string('exp_members', array('private_messages' => $count_query->row['count']), "member_id = '".$row['recipient_id']."'"));
  783. }
  784. }
  785. }
  786. /** ----------------------------------
  787. /** Are there forum posts to delete?
  788. /** ----------------------------------*/
  789. if ($PREFS->ini('forum_is_installed') == "y")
  790. {
  791. $DB->query("DELETE FROM exp_forum_subscriptions WHERE ".$IDS);
  792. $DB->query("DELETE FROM exp_forum_pollvotes WHERE ".$IDS);
  793. $IDS = str_replace('member_id', 'admin_member_id', $IDS);
  794. $DB->query("DELETE FROM exp_forum_administrators WHERE ".$IDS);
  795. $IDS = str_replace('admin_member_id', 'mod_member_id', $IDS);
  796. $DB->query("DELETE FROM exp_forum_moderators WHERE ".$IDS);
  797. $IDS = str_replace('mod_member_id', 'author_id', $IDS);
  798. $DB->query("DELETE FROM exp_forum_topics WHERE ".$IDS);
  799. // Snag the affected topic id's before deleting the members for the update afterwards
  800. $query = $DB->query("SELECT topic_id FROM exp_forum_posts WHERE ".$IDS);
  801. if ($query->num_rows > 0)
  802. {
  803. $topic_ids = array();
  804. foreach ($query->result as $row)
  805. {
  806. $topic_ids[] = $row['topic_id'];
  807. }
  808. $topic_ids = array_unique($topic_ids);
  809. }
  810. $DB->query("DELETE FROM exp_forum_posts WHERE ".$IDS);
  811. $DB->query("DELETE FROM exp_forum_polls WHERE ".$IDS);
  812. // Kill any attachments
  813. $query = $DB->query("SELECT attachment_id, filehash, extension, board_id FROM exp_forum_attachments WHERE ".str_replace('author_id', 'member_id', $IDS));
  814. if ($query->num_rows > 0)
  815. {
  816. // Grab the upload path
  817. $res = $DB->query('SELECT board_id, board_upload_path FROM exp_forum_boards');
  818. $paths = array();
  819. foreach ($res->result as $row)
  820. {
  821. $paths[$row['board_id']] = $row['board_upload_path'];
  822. }
  823. foreach ($query->result as $row)
  824. {
  825. if ( ! isset($paths[$row['board_id']]))
  826. {
  827. continue;
  828. }
  829. $file = $paths[$row['board_id']].$row['filehash'].$row['extension'];
  830. $thumb = $paths[$row['board_id']].$row['filehash'].'_t'.$row['extension'];
  831. @unlink($file);
  832. @unlink($thumb);
  833. $DB->query("DELETE FROM exp_forum_attachments WHERE attachment_id = '{$row['attachment_id']}'");
  834. }
  835. }
  836. // Update the forum stats
  837. $query = $DB->query("SELECT forum_id FROM exp_forums WHERE forum_is_cat = 'n'");
  838. if ( ! class_exists('Forum'))
  839. {
  840. require PATH_MOD.'forum/mod.forum'.EXT;
  841. require PATH_MOD.'forum/mod.forum_core'.EXT;
  842. }
  843. $FRM = new Forum_Core;
  844. foreach ($query->result as $row)
  845. {
  846. $FRM->_update_post_stats($row['forum_id']);
  847. }
  848. if (isset($topic_ids))
  849. {
  850. foreach ($topic_ids as $topic_id)
  851. {
  852. $FRM->_update_topic_stats($topic_id);
  853. }
  854. }
  855. }
  856. /** -------------------------------------
  857. /** Delete comments and update entry stats
  858. /** -------------------------------------*/
  859. $weblog_ids = array();
  860. $IDS = str_replace('member_id', 'author_id', $IDS);
  861. $query = $DB->query("SELECT DISTINCT(entry_id), weblog_id FROM exp_comments WHERE ".$IDS);
  862. if ($query->num_rows > 0)
  863. {
  864. $DB->query("DELETE FROM exp_comments WHERE ".$IDS);
  865. foreach ($query->result as $row)
  866. {
  867. $weblog_ids[] = $row['weblog_id'];
  868. $query = $DB->query("SELECT MAX(comment_date) AS max_date FROM exp_comments WHERE status = 'o' AND entry_id = '".$DB->escape_str($row['entry_id'])."'");
  869. $comment_date = ($query->num_rows == 0 OR !is_numeric($query->row['max_date'])) ? 0 : $query->row['max_date'];
  870. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '{$row['entry_id']}' AND status = 'o'");
  871. $DB->query("UPDATE exp_weblog_titles
  872. SET comment_total = '".$DB->escape_str($query->row['count'])."', recent_comment_date = '$comment_date'
  873. WHERE entry_id = '{$row['entry_id']}'");
  874. }
  875. }
  876. if (count($weblog_ids) > 0)
  877. {
  878. foreach (array_unique($weblog_ids) as $weblog_id)
  879. {
  880. $STAT->update_comment_stats($weblog_id);
  881. }
  882. }
  883. /** ----------------------------------
  884. /** Reassign Entires to Heir
  885. /** ----------------------------------*/
  886. $heir_id = $IN->GBL('heir', 'POST');
  887. $entries_exit = $IN->GBL('entries_exit', 'POST');
  888. $gallery_entries_exit = $IN->GBL('gallery_entries_exit', 'POST');
  889. if ($heir_id !== FALSE && is_numeric($heir_id))
  890. {
  891. if ($entries_exit == 'yes')
  892. {
  893. $DB->query("UPDATE exp_weblog_titles SET author_id = '{$heir_id}' WHERE
  894. ".str_replace('member_id', 'author_id', $IDS));
  895. $query = $DB->query("SELECT COUNT(entry_id) AS count, MAX(entry_date) AS entry_date
  896. FROM exp_weblog_titles
  897. WHERE author_id = '{$heir_id}'");
  898. $DB->query("UPDATE exp_members
  899. SET total_entries = '".$DB->escape_str($query->row['count'])."', last_entry_date = '".$DB->escape_str($query->row['entry_date'])."'
  900. WHERE member_id = '{$heir_id}'");
  901. }
  902. if ($gallery_entries_exit == 'yes')
  903. {
  904. $DB->query("UPDATE exp_gallery_entries SET author_id = '{$heir_id}' WHERE ".str_replace('member_id', 'author_id', $IDS));
  905. }
  906. }
  907. // -------------------------------------------
  908. // 'cp_members_member_delete_end' hook.
  909. // - Additional processing when a member is deleted through the CP
  910. //
  911. $edata = $EXT->call_extension('cp_members_member_delete_end');
  912. if ($EXT->end_script === TRUE) return;
  913. //
  914. // -------------------------------------------
  915. // Update global stats
  916. $STAT->update_member_stats();
  917. $message = (count($ids) == 1) ? $DSP->qdiv('success', $LANG->line('member_deleted')) :
  918. $DSP->qdiv('success', $LANG->line('members_deleted'));
  919. return $this->view_all_members($message);
  920. }
  921. /* END */
  922. /** -----------------------------
  923. /** Member group overview
  924. /** -----------------------------*/
  925. function member_group_manager($message = '')
  926. {
  927. global $LANG, $DSP, $DB, $IN, $PREFS;
  928. $row_limit = 20;
  929. $paginate = '';
  930. if ( ! $DSP->allowed_group('can_admin_mbr_groups'))
  931. {
  932. return $DSP->no_access_message();
  933. }
  934. $sql = "SELECT group_id, group_title, can_access_cp, is_locked
  935. FROM exp_member_groups
  936. WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  937. ORDER BY exp_member_groups.group_title";
  938. $g_query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  939. if ($g_query->num_rows > $row_limit)
  940. {
  941. $row_count = ( ! $IN->GBL('row')) ? 0 : $IN->GBL('row');
  942. $paginate = $DSP->pager( BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=mbr_group_manager',
  943. $g_query->num_rows,
  944. $row_limit,
  945. $row_count,
  946. 'row'
  947. );
  948. $sql .= " LIMIT ".$row_count.", ".$row_limit;
  949. }
  950. $query = $DB->query($sql);
  951. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('member_groups'));
  952. if ($message != '')
  953. $DSP->body .= $DSP->qdiv('box', $message);
  954. $DSP->body .= $DSP->table('tableBorder', '0', '', '100%').
  955. $DSP->tr().
  956. $DSP->table_qcell('tableHeadingAlt',
  957. array(
  958. $LANG->line('group_title'),
  959. $LANG->line('edit_group'),
  960. $LANG->line('security_lock'),
  961. $LANG->line('group_id'),
  962. $LANG->line('mbrs'),
  963. $LANG->line('delete')
  964. )
  965. ).
  966. $DSP->tr_c();
  967. $i = 0;
  968. foreach($query->result as $row)
  969. {
  970. $group_name = $row['group_title'];
  971. if (in_array($group_name, $this->english))
  972. {
  973. $group_name = $LANG->line(strtolower(str_replace(" ", "_", $group_name)));
  974. }
  975. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  976. $DSP->body .= $DSP->tr();
  977. $title = ($row['can_access_cp'] == 'y') ? $DSP->qspan('highlight', $DSP->required().NBS.$group_name) : $group_name;
  978. $DSP->body .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $title), '25%');
  979. $DSP->body .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_mbr_group'.AMP.'group_id='.$row['group_id'], $LANG->line('edit_group')), '18%');
  980. $status = ($row['is_locked'] == 'y') ? $DSP->qdiv('highlight', $LANG->line('locked')) : $DSP->qdiv('highlight_alt', $LANG->line('unlocked'));
  981. $DSP->body .= $DSP->table_qcell($style, $status, '17%');
  982. $DSP->body .= $DSP->table_qcell($style, $row['group_id'], '15%');
  983. $group_id = $row['group_id'];
  984. $cquery = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE group_id = '{$group_id}'");
  985. $DSP->body .= $DSP->table_qcell($style, $DSP->qspan('lightLinks', '('.$cquery->row['count'].')').NBS.
  986. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=view_members'.AMP.'group_id='.$row['group_id'],
  987. $LANG->line('view')), '15%');
  988. $delete = ( ! in_array($row['group_id'], $this->no_delete)) ? $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=mbr_group_del_conf'.AMP.'group_id='.$row['group_id'], $LANG->line('delete')) : '--';
  989. $DSP->body .= $DSP->table_qcell($style, $delete, '10%');
  990. $DSP->body .= $DSP->tr_c();
  991. }
  992. $DSP->body .= $DSP->table_c();
  993. if ($paginate != '')
  994. {
  995. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $paginate));
  996. }
  997. $DSP->body .= $DSP->qdiv('bigPad', $DSP->qspan('alert', '*').NBS.$LANG->line('member_has_cp_access'));
  998. $DSP->body .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=edit_mbr_group'));
  999. $DSP->body .= $DSP->div('box');
  1000. $DSP->body .= NBS.NBS.$LANG->line('create_group_based_on_old').$DSP->nbs(3);
  1001. $DSP->body .= $DSP->input_select_header('clone_id');
  1002. foreach($g_query->result as $row)
  1003. {
  1004. $DSP->body .= $DSP->input_select_option($row['group_id'], $row['group_title']);
  1005. }
  1006. $DSP->body .= $DSP->input_select_footer();
  1007. $DSP->body .= $DSP->nbs(2).$DSP->input_submit();
  1008. $DSP->body .= $DSP->div_c();
  1009. $DSP->body .= $DSP->form_close();
  1010. $DSP->title = $LANG->line('member_groups');
  1011. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  1012. $DSP->crumb_item($LANG->line('member_groups'));
  1013. $DSP->right_crumb($LANG->line('create_new_member_group'), BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_mbr_group');
  1014. }
  1015. /* END */
  1016. /** ----------------------------------
  1017. /** Edit/Create a member group form
  1018. /** ----------------------------------*/
  1019. function edit_member_group_form($msg='')
  1020. {
  1021. global $IN, $DSP, $DB, $SESS, $LANG, $PREFS;
  1022. /** ----------------------------------------------------
  1023. /** Only super admins can administrate member groups
  1024. /** ----------------------------------------------------*/
  1025. if ($SESS->userdata['group_id'] != 1)
  1026. {
  1027. return $DSP->no_access_message($LANG->line('only_superadmins_can_admin_groups'));
  1028. }
  1029. $group_id = $IN->GBL('group_id');
  1030. $clone_id = $IN->GBL('clone_id');
  1031. $id = ( ! $group_id) ? '3' : $group_id;
  1032. // Assign the page title
  1033. $title = ($group_id != '') ? $LANG->line('edit_member_group') : $LANG->line('create_member_group');
  1034. /** ----------------------------------
  1035. /** Fetch the Sites
  1036. /** ----------------------------------*/
  1037. if ($PREFS->ini('multiple_sites_enabled') == 'y')
  1038. {
  1039. $sites_query = $DB->query("SELECT * FROM exp_sites ORDER BY site_label");
  1040. }
  1041. else
  1042. {
  1043. $sites_query = $DB->query("SELECT * FROM exp_sites WHERE site_id = '1'");
  1044. }
  1045. /** ----------------------------------
  1046. /** Fetch the member group data
  1047. /** ----------------------------------*/
  1048. if ($clone_id != '') $id = $clone_id;
  1049. $query = $DB->query("SELECT * FROM exp_member_groups WHERE group_id = '".$DB->escape_str($id)."'");
  1050. $result = ($query->num_rows == 0) ? FALSE : TRUE;
  1051. $group_data = array();
  1052. foreach($query->result as $row)
  1053. {
  1054. $group_data[$row['site_id']] = $row;
  1055. }
  1056. $default_id = $query->row['site_id'];
  1057. /** ----------------------------------
  1058. /** Translate the group title
  1059. /** ----------------------------------*/
  1060. // We only translate this if it has not been edited
  1061. $group_title = ($group_id == '') ? '' : $group_data[$default_id]['group_title'];
  1062. $group_description = ($group_id == '') ? '' : $group_data[$default_id]['group_description'];
  1063. if (isset($this->english[$group_title]))
  1064. {
  1065. $group_title = $LANG->line(strtolower(str_replace(" ", "_", $group_title)));
  1066. }
  1067. if ($msg != '')
  1068. {
  1069. $DSP->body .= $DSP->qdiv('box', $DSP->qdiv('success', $msg));
  1070. }
  1071. $DSP->body_props .= ' onload="showHideMenu(\'group_name\');"';
  1072. /** ----------------------------------
  1073. /** Declare form and page heading
  1074. /** ----------------------------------*/
  1075. ob_start();
  1076. ?>
  1077. <script type="text/javascript">
  1078. <!--
  1079. var lastShownObj = '';
  1080. var lastShownColor = '';
  1081. function showHideMenu(objValue)
  1082. {
  1083. if (lastShownObj != '')
  1084. {
  1085. if (document.getElementById(lastShownObj+'_pointer'))
  1086. {
  1087. document.getElementById(lastShownObj+'_pointer').getElementsByTagName('a')[0].style.color = lastShownColor;
  1088. }
  1089. document.getElementById(lastShownObj + '_on').style.display = 'none';
  1090. }
  1091. lastShownObj = objValue;
  1092. if (document.getElementById(objValue+'_pointer'))
  1093. {
  1094. lastShownColor = document.getElementById(objValue+'_pointer').getElementsByTagName('a')[0].style.color;
  1095. }
  1096. document.getElementById(objValue + '_on').style.display = 'block';
  1097. if (document.getElementById(objValue+'_pointer'))
  1098. {
  1099. document.getElementById(objValue+'_pointer').getElementsByTagName('a')[0].style.color = '#000';
  1100. }
  1101. }
  1102. function switchSite(site_id)
  1103. {
  1104. document.getElementById('site_loader').style.display = 'inline';
  1105. // The site loader image is given a second to be seen before we switch to the new Site
  1106. // Origins of image: http://www.ajaxload.info/
  1107. setTimeout('switchSite_action(' + site_id + ')', 1000)
  1108. }
  1109. function switchSite_action(site_id)
  1110. {
  1111. if (document.getElementById('membersMenu'))
  1112. {
  1113. var menuDivs = document.getElementById('membersMenu').getElementsByTagName('div');
  1114. for(var i = 0, s = menuDivs.length; i < s; i++)
  1115. {
  1116. if (menuDivs[i].id.indexOf('site_options_') != -1)
  1117. {
  1118. menuDivs[i].style.display = 'none';
  1119. }
  1120. }
  1121. }
  1122. if (document.getElementById('site_options_' + site_id + '_on'))
  1123. {
  1124. document.getElementById('site_options_' + site_id + '_on').style.display = 'block';
  1125. }
  1126. if (lastShownObj != lastShownObj.replace(/^\d+?\_/, ''))
  1127. {
  1128. showHideMenu(site_id + '_' + lastShownObj.replace(/^\d+?\_/, ''));
  1129. }
  1130. else
  1131. {
  1132. showHideMenu(lastShownObj);
  1133. }
  1134. document.getElementById('site_loader').style.display = 'none';
  1135. }
  1136. //-->
  1137. </script>
  1138. <?php
  1139. $buffer = ob_get_contents();
  1140. ob_end_clean();
  1141. $DSP->body .= $buffer;
  1142. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=update_mbr_group'));
  1143. $r .= $DSP->qdiv('default', '', 'menu_contents');
  1144. if ($clone_id != '')
  1145. {
  1146. $group_title = '';
  1147. $group_description = '';
  1148. $r .= $DSP->input_hidden('clone_id', $clone_id);
  1149. }
  1150. $r .= $DSP->input_hidden('group_id', $group_id);
  1151. /** ----------------------------------
  1152. /** Group name form field
  1153. /** ----------------------------------*/
  1154. $r .= '<div id="group_name_on" style="display: none; padding:0; margin: 0;">'.
  1155. $DSP->table('tableBorder', '0', '', '100%').
  1156. $DSP->tr().
  1157. "<td class='tableHeadingAlt' colspan='2'>".
  1158. NBS.$LANG->line('group_name').
  1159. $DSP->tr_c().
  1160. $DSP->tr().
  1161. $DSP->td('tableCellOne', '40%').
  1162. $DSP->qdiv('defaultBold', $LANG->line('group_name', 'group_title')).
  1163. $DSP->td_c().
  1164. $DSP->td('tableCellOne', '60%').
  1165. $DSP->input_text('group_title', $group_title, '50', '70', 'input', '100%').
  1166. $DSP->td_c().
  1167. $DSP->tr_c().
  1168. $DSP->tr_c().
  1169. $DSP->tr().
  1170. $DSP->td('tableCellTwo', '40%', '', '', 'top').
  1171. $DSP->qdiv('defaultBold', $LANG->line('group_description', 'group_description')).
  1172. $DSP->td_c().
  1173. $DSP->td('tableCellTwo', '60%').
  1174. $DSP->input_textarea('group_description', $group_description, 10).
  1175. $DSP->td_c().
  1176. $DSP->tr_c().
  1177. $DSP->table_c().
  1178. $DSP->qdiv('defaultSmall', '');
  1179. /** ----------------------------------
  1180. /** Top section of page
  1181. /** ----------------------------------*/
  1182. if ($group_id == 1)
  1183. {
  1184. $r .= $DSP->qdiv('box', $LANG->line('super_admin_edit_note'));
  1185. }
  1186. else
  1187. {
  1188. $r .= $DSP->qdiv('box', $DSP->qspan('alert', $LANG->line('warning')).$DSP->nbs(2).$LANG->line('be_careful_assigning_groups'));
  1189. }
  1190. $r .= $DSP->qdiv('defaultSmall', '');
  1191. $r .= $DSP->div_c();
  1192. /** ----------------------------------
  1193. /** Group lock
  1194. /** ----------------------------------*/
  1195. $r .= '<div id="group_lock_on" style="display: none; padding:0; margin: 0;">';
  1196. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1197. $r .= $DSP->tr().
  1198. $DSP->td('tableHeadingAlt', '', '2').$LANG->line('group_lock').
  1199. $DSP->td_c().
  1200. $DSP->tr_c();
  1201. $r .= $DSP->tr().
  1202. $DSP->td('tableCellTwo', '60%').
  1203. $DSP->qdiv('alert', $LANG->line('enable_lock')).
  1204. $DSP->qdiv('itemWrapper', $LANG->line('lock_description')).
  1205. $DSP->td_c().
  1206. $DSP->td('tableCellTwo', '40%');
  1207. $selected = ($group_data[$default_id]['is_locked'] == 'y') ? 1 : '';
  1208. $r .= $LANG->line('locked').NBS.
  1209. $DSP->input_radio('is_locked', 'y', $selected).$DSP->nbs(3);
  1210. $selected = ($group_data[$default_id]['is_locked'] == 'n') ? 1 : '';
  1211. $r .= $LANG->line('unlocked').NBS.
  1212. $DSP->input_radio('is_locked', 'n', $selected).$DSP->nbs(3);
  1213. $r .= $DSP->td_c().
  1214. $DSP->tr_c().
  1215. $DSP->table_c().
  1216. $DSP->div_c();
  1217. /** ----------------------------------------------------
  1218. /** Fetch the names and IDs of all weblogs
  1219. /** ----------------------------------------------------*/
  1220. $blog_names = array();
  1221. $blog_ids = array();
  1222. $query = $DB->query("SELECT weblog_id, site_id, blog_title FROM exp_weblogs WHERE is_user_blog = 'n' ORDER BY blog_title");
  1223. if ($id == 1)
  1224. {
  1225. foreach($query->result as $row)
  1226. {
  1227. $blog_names['weblog_id_'.$row['weblog_id']] = $row['blog_title'];
  1228. $group_data[$row['site_id']]['weblog_id_'.$row['weblog_id']] = 'y';
  1229. }
  1230. }
  1231. else
  1232. {
  1233. $res = $DB->query("SELECT weblog_id FROM exp_weblog_member_groups WHERE group_id = '".$DB->escape_str($id)."' ");
  1234. if ($res->num_rows > 0)
  1235. {
  1236. foreach ($res->result as $row)
  1237. {
  1238. $blog_ids[$row['weblog_id']] = TRUE;
  1239. }
  1240. }
  1241. foreach($query->result as $row)
  1242. {
  1243. $status = (isset($blog_ids[$row['weblog_id']])) ? 'y' : 'n';
  1244. $blog_names['weblog_id_'.$row['weblog_id']] = $row['blog_title'];
  1245. $group_data[$row['site_id']]['weblog_id_'.$row['weblog_id']] = $status;
  1246. }
  1247. }
  1248. /** ----------------------------------------------------
  1249. /** Fetch the names and IDs of all modules
  1250. /** ----------------------------------------------------*/
  1251. $module_names = array();
  1252. $module_ids = array();
  1253. $query = $DB->query("SELECT module_id, module_name FROM exp_modules WHERE has_cp_backend = 'y' ORDER BY module_name");
  1254. if ($id == 1)
  1255. {
  1256. foreach($query->result as $row)
  1257. {
  1258. $module_names['module_id_'.$row['module_id']] = $row['module_name'];
  1259. $group_data['module_id_'.$row['module_id']] = 'y';
  1260. }
  1261. }
  1262. else
  1263. {
  1264. $res = $DB->query("SELECT module_id FROM exp_module_member_groups WHERE group_id = '".$DB->escape_str($id)."' ");
  1265. if ($res->num_rows > 0)
  1266. {
  1267. foreach ($res->result as $row)
  1268. {
  1269. $module_ids[$row['module_id']] = TRUE;
  1270. }
  1271. }
  1272. foreach($query->result as $row)
  1273. {
  1274. $status = (isset($module_ids[$row['module_id']])) ? 'y' : 'n';
  1275. $module_names['module_id_'.$row['module_id']] = $row['module_name'];
  1276. $group_data['module_id_'.$row['module_id']] = $status;
  1277. }
  1278. }
  1279. /** ----------------------------------------------------
  1280. /** Fetch the names and IDs of all template groups
  1281. /** ----------------------------------------------------*/
  1282. $template_names = array();
  1283. $template_ids = array();
  1284. $query = $DB->query("SELECT group_id, group_name, site_id FROM exp_template_groups WHERE is_user_blog = 'n' ORDER BY group_name");
  1285. if ($id == 1)
  1286. {
  1287. foreach($query->result as $row)
  1288. {
  1289. $template_names['template_id_'.$row['group_id']] = $row['group_name'];
  1290. $group_data[$row['site_id']]['template_id_'.$row['group_id']] = 'y';
  1291. }
  1292. }
  1293. else
  1294. {
  1295. $res = $DB->query("SELECT template_group_id FROM exp_template_member_groups WHERE group_id = '".$DB->escape_str($id)."' ");
  1296. if ($res->num_rows > 0)
  1297. {
  1298. foreach ($res->result as $row)
  1299. {
  1300. $template_ids[$row['template_group_id']] = TRUE;
  1301. }
  1302. }
  1303. foreach($query->result as $row)
  1304. {
  1305. $status = (isset($template_ids[$row['group_id']])) ? 'y' : 'n';
  1306. $template_names['template_id_'.$row['group_id']] = $row['group_name'];
  1307. $group_data[$row['site_id']]['template_id_'.$row['group_id']] = $status;
  1308. }
  1309. }
  1310. /** ----------------------------------------------------
  1311. /** Assign clusters of member groups
  1312. /** ----------------------------------------------------*/
  1313. // NOTE: the associative value (y/n) is the default setting used
  1314. // only when we are showing the "create new group" form
  1315. $G = array(
  1316. 'site_access' => array (
  1317. 'can_view_online_system' => 'n',
  1318. 'can_view_offline_system' => 'n'
  1319. ),
  1320. 'mbr_account_privs' => array (
  1321. 'can_view_profiles' => 'n',
  1322. 'can_email_from_profile' => 'n',
  1323. 'include_in_authorlist' => 'n',
  1324. 'include_in_memberlist' => 'n',
  1325. 'include_in_mailinglists' => 'y',
  1326. 'can_delete_self' => 'n',
  1327. 'mbr_delete_notify_emails' => $PREFS->ini('webmaster_email')
  1328. ),
  1329. 'commenting_privs' => array (
  1330. 'can_post_comments' => 'n',
  1331. 'exclude_from_moderation' => 'n'
  1332. ),
  1333. 'search_privs' => array (
  1334. 'can_search' => 'n',
  1335. 'search_flood_control' => '30'
  1336. ),
  1337. 'priv_msg_privs' => array (
  1338. 'can_send_private_messages' => 'n',
  1339. 'prv_msg_send_limit' => '20',
  1340. 'prv_msg_storage_limit' => '60',
  1341. 'can_attach_in_private_messages' => 'n',
  1342. 'can_send_bulletins' => 'n'
  1343. ),
  1344. 'global_cp_access' => array (
  1345. 'can_access_cp' => 'n'
  1346. ),
  1347. 'cp_section_access' => array (
  1348. 'can_access_publish' => 'n',
  1349. 'can_access_edit' => 'n',
  1350. 'can_access_design' => 'n',
  1351. 'can_access_comm' => 'n',
  1352. 'can_access_modules' => 'n',
  1353. 'can_access_admin' => 'n'
  1354. ),
  1355. 'cp_admin_privs' => array (
  1356. 'can_admin_weblogs' => 'n',
  1357. 'can_admin_templates' => 'n',
  1358. 'can_admin_members' => 'n',
  1359. 'can_admin_mbr_groups' => 'n',
  1360. 'can_admin_mbr_templates' => 'n',
  1361. 'can_delete_members' => 'n',
  1362. 'can_ban_users' => 'n',
  1363. 'can_admin_utilities' => 'n',
  1364. 'can_admin_preferences' => 'n',
  1365. 'can_admin_modules' => 'n'
  1366. ),
  1367. 'cp_email_privs' => array (
  1368. 'can_send_email' => 'n',
  1369. 'can_email_member_groups' => 'n',
  1370. 'can_email_mailinglist' => 'n',
  1371. 'can_send_cached_email' => 'n',
  1372. ),
  1373. 'cp_weblog_privs' => array(
  1374. 'can_view_other_entries' => 'n',
  1375. 'can_delete_self_entries' => 'n',
  1376. 'can_edit_other_entries' => 'n',
  1377. 'can_delete_all_entries' => 'n',
  1378. 'can_assign_post_authors' => 'n',
  1379. 'can_edit_categories' => 'n',
  1380. 'can_delete_categories' => 'n',
  1381. ),
  1382. 'cp_weblog_post_privs' => $blog_names,
  1383. 'cp_comment_privs' => array (
  1384. 'can_moderate_comments' => 'n',
  1385. 'can_view_other_comments' => 'n',
  1386. 'can_edit_own_comments' => 'n',
  1387. 'can_delete_own_comments' => 'n',
  1388. 'can_edit_all_comments' => 'n',
  1389. 'can_delete_all_comments' => 'n'
  1390. ),
  1391. 'cp_template_access_privs' => $template_names,
  1392. 'cp_module_access_privs' => $module_names,
  1393. );
  1394. /** --------------------------------------
  1395. /** Super Admin Group can not be edited
  1396. /** --------------------------------------*/
  1397. // If the form being viewed is the Super Admin one we only allow the name to be changed.
  1398. if ($group_id == 1)
  1399. {
  1400. $G = array('mbr_account_privs' => array ('include_in_authorlist' => 'n', 'include_in_memberlist' => 'n'));
  1401. }
  1402. /** ---------------------------------------
  1403. /** Assign items we want to highlight
  1404. /** ---------------------------------------*/
  1405. $alert = array(
  1406. 'can_view_offline_system',
  1407. 'can_access_cp',
  1408. 'can_admin_weblogs',
  1409. 'can_admin_templates',
  1410. 'can_delete_members',
  1411. 'can_admin_mbr_groups',
  1412. 'can_admin_mbr_templates',
  1413. 'can_ban_users',
  1414. 'can_admin_members',
  1415. 'can_admin_preferences',
  1416. 'can_admin_modules',
  1417. 'can_admin_utilities',
  1418. 'can_edit_categories',
  1419. 'can_delete_categories',
  1420. 'can_delete_self'
  1421. );
  1422. /** ---------------------------------------
  1423. /** Items that should be shown in an input box
  1424. /** ---------------------------------------*/
  1425. $tbox = array(
  1426. 'search_flood_control',
  1427. 'prv_msg_send_limit',
  1428. 'prv_msg_storage_limit',
  1429. 'mbr_delete_notify_emails'
  1430. );
  1431. /** ---------------------------------------
  1432. /** Render the group matrix
  1433. /** ---------------------------------------*/
  1434. $s = 0;
  1435. foreach($sites_query->result as $sites)
  1436. {
  1437. foreach ($G as $g_key => $g_val)
  1438. {
  1439. if ($g_key == 'cp_module_access_privs')
  1440. {
  1441. if ($s == 0)
  1442. {
  1443. $add = '';
  1444. }
  1445. else
  1446. {
  1447. continue;
  1448. }
  1449. }
  1450. else
  1451. {
  1452. $add = $sites['site_id'].'_';
  1453. }
  1454. /** ----------------------------------
  1455. /** Start the Table
  1456. /** ----------------------------------*/
  1457. $r .= '<div id="'.$add.$g_key.'_on" style="display: none; padding:0; margin: 0;">';
  1458. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1459. $r .= $DSP->tr();
  1460. $r .= "<td class='tableHeadingAlt' id='".$g_key."2' colspan='2'>";
  1461. $r .= NBS.$LANG->line($g_key);
  1462. $r .= $DSP->tr_c();
  1463. $i = 0;
  1464. foreach($g_val as $key => $val)
  1465. {
  1466. if ($g_key == 'cp_module_access_privs')
  1467. {
  1468. $group_data[$sites['site_id']][$key] = $group_data[$key];
  1469. }
  1470. elseif ( ! isset($group_data[$sites['site_id']][$key]))
  1471. {
  1472. continue;
  1473. }
  1474. if ($result == FALSE)
  1475. {
  1476. $group_data[$sites['site_id']][$key] = $val;
  1477. }
  1478. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  1479. $line = $LANG->line($key);
  1480. if (substr($key, 0, 10) == 'weblog_id_')
  1481. {
  1482. $line = $LANG->line('can_post_in').NBS.NBS.$DSP->qspan('alert', $blog_names[$key]);
  1483. }
  1484. if (substr($key, 0, 10) == 'module_id_')
  1485. {
  1486. $line = $LANG->line('can_access_mod').NBS.NBS.$DSP->qspan('alert', $module_names[$key]);
  1487. }
  1488. if (substr($key, 0, 12) == 'template_id_')
  1489. {
  1490. $line = $LANG->line('can_access_tg').NBS.NBS.$DSP->qspan('alert', $template_names[$key]);
  1491. }
  1492. $mark = (in_array($key, $alert)) ? $DSP->qspan('alert', $line) : $DSP->qspan('defaultBold', $line);
  1493. $r .= $DSP->tr().
  1494. $DSP->td($style, '60%').
  1495. $mark;
  1496. $r .= $DSP->td_c().
  1497. $DSP->td($style, '40%');
  1498. if (in_array($key, $tbox))
  1499. {
  1500. $width = ($key == 'mbr_delete_notify_emails') ? '100%' : '100px';
  1501. $length = ($key == 'mbr_delete_notify_emails') ? '255' : '5';
  1502. $r .= $DSP->input_text($add.$key, $group_data[$sites['site_id']][$key], '15', $length, 'input', $width);
  1503. }
  1504. else
  1505. {
  1506. $r .= $LANG->line('yes').NBS.
  1507. $DSP->input_radio($add.$key, 'y', ($group_data[$sites['site_id']][$key] == 'y') ? 1 : '').$DSP->nbs(3);
  1508. $r .= $LANG->line('no').NBS.
  1509. $DSP->input_radio($add.$key, 'n', ($group_data[$sites['site_id']][$key] == 'n') ? 1 : '').$DSP->nbs(3);
  1510. }
  1511. $r .= $DSP->td_c();
  1512. $r .= $DSP->tr_c();
  1513. }
  1514. $r .= $DSP->table_c();
  1515. $r .= $DSP->div_c();
  1516. }
  1517. ++$s;
  1518. }
  1519. /** ---------------------------------------
  1520. /** Submit button
  1521. /** ---------------------------------------*/
  1522. if ($group_id == '')
  1523. {
  1524. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')).NBS.$DSP->input_submit($LANG->line('submit_and_return'),'return'));
  1525. }
  1526. else
  1527. {
  1528. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')).NBS.$DSP->input_submit($LANG->line('update_and_return'),'return'));
  1529. }
  1530. $r .= $DSP->form_close();
  1531. /** ----------------------------------
  1532. /** Create List of Sites
  1533. /** ----------------------------------*/
  1534. if ($PREFS->ini('multiple_sites_enabled') == 'y')
  1535. {
  1536. $sites_menu = '<select name="site_list_pulldown" class="select" onchange="switchSite(this.value)">';
  1537. foreach($sites_query->result as $sites)
  1538. {
  1539. $sites_menu .= $DSP->input_select_option($sites['site_id'], $sites['site_label']);
  1540. }
  1541. $sites_menu = $DSP->div('profileMenuInner')
  1542. . $sites_menu
  1543. .$DSP->input_select_footer()
  1544. .'<span id="site_loader" style="display:none;"><img src="'.PATH_CP_IMG.'loader.gif" width="16" height="16" style="vertical-align:sub;" /></span>'
  1545. .$DSP->div_c();
  1546. }
  1547. else
  1548. {
  1549. $sites_menu = '';
  1550. }
  1551. /** ----------------------------------
  1552. /** Create Our All Encompassing Table of Weblog Goodness
  1553. /** ----------------------------------*/
  1554. $DSP->body .= $DSP->table('', '0', '', '100%');
  1555. $menu = '';
  1556. $menu .= $DSP->qdiv('navPad', ' <span id="group_name_pointer">&#8226; '.$DSP->anchor("#", $LANG->line('group_name'), 'onclick="showHideMenu(\'group_name\');"').'</span>');
  1557. if ($group_id != 1)
  1558. {
  1559. $menu .= $DSP->qdiv('navPad', ' <span id="group_lock_pointer">&#8226; '.$DSP->anchor("#", $LANG->line('security_lock'), 'onclick="showHideMenu(\'group_lock\');"').'</span>');
  1560. }
  1561. $i = 0;
  1562. foreach($sites_query->result as $sites)
  1563. {
  1564. if ($i != 0)
  1565. {
  1566. $menu .= '<div id="site_options_'.$sites['site_id'].'_on" style="display: none; padding:0; margin: 0;">';
  1567. }
  1568. else
  1569. {
  1570. $menu .= '<div id="site_options_'.$sites['site_id'].'_on" style="display: block; padding:0; margin: 0;">';
  1571. }
  1572. foreach ($G as $g_key => $g_val)
  1573. {
  1574. if ($g_key == 'cp_module_access_privs')
  1575. {
  1576. continue;
  1577. }
  1578. else
  1579. {
  1580. $add = $sites['site_id'].'_';
  1581. }
  1582. $menu .= $DSP->qdiv('navPad', ' <span id="'.$add.$g_key.'_pointer">&#8226; '.$DSP->anchor("#", $LANG->line($g_key), 'onclick="showHideMenu(\''.$add.$g_key.'\');"').'</span>');
  1583. }
  1584. $menu .= $DSP->div_c();
  1585. ++$i;
  1586. }
  1587. if ($group_id != 1)
  1588. {
  1589. // Modules item, which is the same for all sites
  1590. $menu .= $DSP->qdiv('navPad', ' <span id="cp_module_access_privs_pointer">&#8226; '.$DSP->anchor("#", $LANG->line('cp_module_access_privs'), 'onclick="showHideMenu(\'cp_module_access_privs\');"').'</span>');
  1591. }
  1592. $first_text = $DSP->div('tableHeadingAlt')
  1593. . $title
  1594. .$DSP->div_c()
  1595. .$sites_menu
  1596. .$DSP->div('profileMenuInner', '', 'membersMenu')
  1597. . $menu
  1598. .$DSP->div_c();
  1599. // Create the Table
  1600. $table_row = array( 'first' => array('valign' => "top", 'width' => "220px", 'text' => $first_text),
  1601. 'second' => array('class' => "default", 'width' => "8px"),
  1602. 'third' => array('valign' => "top", 'text' => $r));
  1603. $DSP->body .= $DSP->table_row($table_row).
  1604. $DSP->table_c();
  1605. /** ---------------------------------------
  1606. /** Assign output data
  1607. /** ---------------------------------------*/
  1608. $DSP->title = $title;
  1609. if ($group_id != '')
  1610. {
  1611. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  1612. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=mbr_group_manager', $LANG->line('member_groups'))).
  1613. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_mbr_group'.AMP.'group_id='.$group_data[$default_id]['group_id'], $title)).
  1614. $DSP->crumb_item($group_data[$default_id]['group_title']);
  1615. }
  1616. else
  1617. {
  1618. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  1619. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=mbr_group_manager', $LANG->line('member_groups'))).
  1620. $DSP->crumb_item($title);
  1621. }
  1622. }
  1623. /* END */
  1624. /** -----------------------------
  1625. /** Create/update a member group
  1626. /** -----------------------------*/
  1627. function update_member_group()
  1628. {
  1629. global $IN, $DSP, $DB, $SESS, $LOG, $LANG;
  1630. /** ----------------------------------------------------
  1631. /** Only super admins can administrate member groups
  1632. /** ----------------------------------------------------*/
  1633. if ($SESS->userdata['group_id'] != 1)
  1634. {
  1635. return $DSP->no_access_message($LANG->line('only_superadmins_can_admin_groups'));
  1636. }
  1637. $edit = TRUE;
  1638. $group_id = $IN->GBL('group_id', 'POST');
  1639. $clone_id = $IN->GBL('clone_id', 'POST');
  1640. unset($_POST['group_id']);
  1641. unset($_POST['clone_id']);
  1642. // Only super admins can edit the "super admin" group
  1643. if ($group_id == 1 AND $SESS->userdata['group_id'] != 1)
  1644. {
  1645. return $DSP->no_access_message();
  1646. }
  1647. // No group name
  1648. if ( ! $IN->GBL('group_title', 'POST'))
  1649. {
  1650. return $DSP->error_message($LANG->line('missing_group_title'));
  1651. }
  1652. $return = ($IN->GBL('return')) ? TRUE : FALSE;
  1653. unset($_POST['return']);
  1654. // New Group? Find Max
  1655. if (empty($group_id))
  1656. {
  1657. $edit = FALSE;
  1658. $query = $DB->query("SELECT MAX(group_id) as max_group FROM exp_member_groups");
  1659. $group_id = $query->row['max_group'] + 1;
  1660. }
  1661. // get existing category privileges if necessary
  1662. if ($edit == TRUE)
  1663. {
  1664. $query = $DB->query("SELECT site_id, can_edit_categories, can_delete_categories FROM exp_member_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  1665. $old_cat_privs = array();
  1666. foreach ($query->result as $row)
  1667. {
  1668. $old_cat_privs[$row['site_id']]['can_edit_categories'] = $row['can_edit_categories'];
  1669. $old_cat_privs[$row['site_id']]['can_delete_categories'] = $row['can_delete_categories'];
  1670. }
  1671. }
  1672. $query = $DB->query("SELECT site_id FROM exp_sites");
  1673. $module_ids = array();
  1674. $weblog_ids = array();
  1675. $template_ids = array();
  1676. $cat_group_privs = array('can_edit_categories', 'can_delete_categories');
  1677. foreach($query->result as $row)
  1678. {
  1679. $site_id = $row['site_id'];
  1680. /** ----------------------------------------------------
  1681. /** Remove and Store Weblog and Template Permissions
  1682. /** ----------------------------------------------------*/
  1683. $data = array('group_title' => $IN->GBL('group_title', 'POST'),
  1684. 'group_description' => $IN->GBL('group_description', 'POST'),
  1685. 'is_locked' => $IN->GBL('is_locked', 'POST'),
  1686. 'site_id' => $site_id,
  1687. 'group_id' => $group_id);
  1688. foreach ($_POST as $key => $val)
  1689. {
  1690. if (substr($key, 0, strlen($site_id.'_weblog_id_')) == $site_id.'_weblog_id_')
  1691. {
  1692. if ($val == 'y')
  1693. {
  1694. $weblog_ids[] = substr($key, strlen($site_id.'_weblog_id_'));
  1695. }
  1696. }
  1697. elseif (substr($key, 0, strlen('module_id_')) == 'module_id_')
  1698. {
  1699. if ($val == 'y')
  1700. {
  1701. $module_ids[] = substr($key, strlen('module_id_'));
  1702. }
  1703. }
  1704. elseif (substr($key, 0, strlen($site_id.'_template_id_')) == $site_id.'_template_id_')
  1705. {
  1706. if ($val == 'y')
  1707. {
  1708. $template_ids[] = substr($key, strlen($site_id.'_template_id_'));
  1709. }
  1710. }
  1711. elseif (substr($key, 0, strlen($site_id.'_')) == $site_id.'_')
  1712. {
  1713. $data[substr($key, strlen($site_id.'_'))] = $_POST[$key];
  1714. }
  1715. else
  1716. {
  1717. continue;
  1718. }
  1719. unset($_POST[$key]);
  1720. }
  1721. if ($edit === FALSE)
  1722. {
  1723. $DB->query($DB->insert_string('exp_member_groups', $data));
  1724. $uploads = $DB->query("SELECT exp_upload_prefs.id FROM exp_upload_prefs WHERE site_id = '".$DB->escape_str($site_id)."'");
  1725. if ($uploads->num_rows > 0)
  1726. {
  1727. foreach($uploads->result as $yeeha)
  1728. {
  1729. $DB->query("INSERT INTO exp_upload_no_access (upload_id, upload_loc, member_group) VALUES ('".$DB->escape_str($yeeha['id'])."', 'cp', '{$group_id}')");
  1730. }
  1731. }
  1732. if ($group_id != 1)
  1733. {
  1734. foreach ($cat_group_privs as $field)
  1735. {
  1736. $privs = array(
  1737. 'member_group' => $group_id,
  1738. 'field' => $field,
  1739. 'allow' => ($data[$field] == 'y') ? TRUE : FALSE,
  1740. 'site_id' => $site_id,
  1741. 'clone_id' => $clone_id
  1742. );
  1743. $this->_update_cat_group_privs($privs);
  1744. }
  1745. }
  1746. $message = $LANG->line('member_group_created').$DSP->nbs(2).$_POST['group_title'];
  1747. }
  1748. else
  1749. {
  1750. unset($data['group_id']);
  1751. $DB->query($DB->update_string('exp_member_groups', $data, "group_id = '$group_id' AND site_id = '{$site_id}'"));
  1752. if ($group_id != 1)
  1753. {
  1754. // update category group discrete privileges
  1755. foreach ($cat_group_privs as $field)
  1756. {
  1757. // only modify category group privs if valye changed, so we do not
  1758. // globally overwrite existing defined privileges carelessly
  1759. if ($old_cat_privs[$site_id][$field] != $data[$field])
  1760. {
  1761. $privs = array(
  1762. 'member_group' => $group_id,
  1763. 'field' => $field,
  1764. 'allow' => ($data[$field] == 'y') ? TRUE : FALSE,
  1765. 'site_id' => $site_id,
  1766. 'clone_id' => $clone_id
  1767. );
  1768. $this->_update_cat_group_privs($privs);
  1769. }
  1770. }
  1771. }
  1772. $message = $LANG->line('member_group_updated').$DSP->nbs(2).$_POST['group_title'];
  1773. }
  1774. }
  1775. // Update groups
  1776. $DB->query("DELETE FROM exp_weblog_member_groups WHERE group_id = '$group_id'");
  1777. $DB->query("DELETE FROM exp_module_member_groups WHERE group_id = '$group_id'");
  1778. $DB->query("DELETE FROM exp_template_member_groups WHERE group_id = '$group_id'");
  1779. if (count($weblog_ids) > 0)
  1780. {
  1781. foreach ($weblog_ids as $val)
  1782. {
  1783. $DB->query("INSERT INTO exp_weblog_member_groups (group_id, weblog_id) VALUES ('$group_id', '$val')");
  1784. }
  1785. }
  1786. if (count($module_ids) > 0)
  1787. {
  1788. foreach ($module_ids as $val)
  1789. {
  1790. $DB->query("INSERT INTO exp_module_member_groups (group_id, module_id) VALUES ('$group_id', '$val')");
  1791. }
  1792. }
  1793. if (count($template_ids) > 0)
  1794. {
  1795. foreach ($template_ids as $val)
  1796. {
  1797. $DB->query("INSERT INTO exp_template_member_groups (group_id, template_group_id) VALUES ('$group_id', '$val')");
  1798. }
  1799. }
  1800. // Update CP log
  1801. $LOG->log_action($message);
  1802. if ($return == TRUE)
  1803. {
  1804. return $this->member_group_manager($DSP->qdiv('success', $message));
  1805. }
  1806. $_POST['group_id'] = $group_id;
  1807. return $this->edit_member_group_form($DSP->qdiv('success', $message));
  1808. }
  1809. /* END */
  1810. /** -----------------------------------------------------------
  1811. /** Update Category Group Discrete Privileges
  1812. /** -----------------------------------------------------------*/
  1813. // Updates exp_category_groups privilege lists for
  1814. // editing and deleting categories
  1815. //-----------------------------------------------------------
  1816. function _update_cat_group_privs($params)
  1817. {
  1818. global $DB;
  1819. if (! is_array($params) OR empty($params))
  1820. {
  1821. return FALSE;
  1822. }
  1823. $expected = array('member_group', 'field', 'allow', 'site_id', 'clone_id');
  1824. // turn parameters into variables
  1825. foreach ($expected as $key)
  1826. {
  1827. // naughty!
  1828. if (! isset($params[$key]))
  1829. {
  1830. return FALSE;
  1831. }
  1832. $$key = $params[$key];
  1833. }
  1834. $query = $DB->query("SELECT group_id, ".$DB->escape_str($field)." FROM exp_category_groups WHERE site_id = '".$DB->escape_str($site_id)."'");
  1835. // nothing to do?
  1836. if ($query->num_rows == 0)
  1837. {
  1838. return FALSE;
  1839. }
  1840. foreach ($query->result as $row)
  1841. {
  1842. $can_do = explode('|', rtrim($row[$field], '|'));
  1843. if ($allow === TRUE)
  1844. {
  1845. if (is_numeric($clone_id) AND in_array($clone_id, $can_do))
  1846. {
  1847. $can_do[] = $member_group;
  1848. }
  1849. elseif ($clone_id === FALSE)
  1850. {
  1851. $can_do[] = $member_group;
  1852. }
  1853. }
  1854. else
  1855. {
  1856. $can_do = array_diff($can_do, array($member_group));
  1857. }
  1858. $DB->query($DB->update_string('exp_category_groups', array($field => implode('|', $can_do)), "group_id = '{$row['group_id']}'"));
  1859. }
  1860. }
  1861. /* END */
  1862. /** -----------------------------------------------------------
  1863. /** Delete member group confirm
  1864. /** -----------------------------------------------------------*/
  1865. // Warning message shown when you try to delete a group
  1866. //-----------------------------------------------------------
  1867. function delete_member_group_conf()
  1868. {
  1869. global $DSP, $IN, $DB, $SESS, $LANG, $PREFS;
  1870. /** ----------------------------------------------------
  1871. /** Only super admins can delete member groups
  1872. /** ----------------------------------------------------*/
  1873. if ($SESS->userdata['group_id'] != 1)
  1874. {
  1875. return $DSP->no_access_message($LANG->line('only_superadmins_can_admin_groups'));
  1876. }
  1877. if ( ! $group_id = $IN->GBL('group_id'))
  1878. {
  1879. return false;
  1880. }
  1881. // You can't delete these groups
  1882. if (in_array($group_id, $this->no_delete))
  1883. {
  1884. return $DSP->no_access_message();
  1885. }
  1886. // Are there any members that are assigned to this group?
  1887. $result = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE group_id = '{$group_id}'");
  1888. $members_exist = ($result->row['count'] > 0) ? TRUE : FALSE;
  1889. $query = $DB->query("SELECT group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id = '".$DB->escape_str($group_id)."'");
  1890. $DSP->title = $LANG->line('delete_member_group');
  1891. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  1892. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=group_manager', $LANG->line('member_groups'))).
  1893. $DSP->crumb_item($LANG->line('delete_member_group'));
  1894. $DSP->body = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=delete_mbr_group'.AMP.'group_id='.$group_id))
  1895. .$DSP->input_hidden('group_id', $group_id);
  1896. $DSP->body .= ($members_exist === TRUE) ? $DSP->input_hidden('reassign', 'y') : $DSP->input_hidden('reassign', 'n');
  1897. $DSP->body .= $DSP->heading($DSP->qspan('alert', $LANG->line('delete_member_group')))
  1898. .$DSP->div('box')
  1899. .$DSP->qdiv('itemWrapper', '<b>'.$LANG->line('delete_member_group_confirm').'</b>')
  1900. .$DSP->qdiv('itemWrapper', '<i>'.$query->row['group_title'].'</i>')
  1901. .$DSP->qdiv('alert', BR.$LANG->line('action_can_not_be_undone').BR.BR);
  1902. if ($members_exist === TRUE)
  1903. {
  1904. $DSP->body .= $DSP->qdiv('defaultBold', str_replace('%x', $result->row['count'], $LANG->line('member_assignment_warning')));
  1905. $DSP->body .= $DSP->div('itemWrapper');
  1906. $DSP->body .= $DSP->input_select_header('new_group_id');
  1907. $query = $DB->query("SELECT group_title, group_id FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id != '{$group_id}' order by group_title");
  1908. foreach ($query->result as $row)
  1909. {
  1910. $group_name = $row['group_title'];
  1911. if (in_array($group_name, $this->english))
  1912. {
  1913. $group_name = $LANG->line(strtolower(str_replace(" ", "_", $group_name)));
  1914. }
  1915. $DSP->body .= $DSP->input_select_option($row['group_id'], $group_name, '');
  1916. }
  1917. $DSP->body .= $DSP->input_select_footer();
  1918. $DSP->body .= $DSP->div_c();
  1919. }
  1920. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('delete')))
  1921. .$DSP->div_c()
  1922. .$DSP->form_close();
  1923. }
  1924. /* END */
  1925. /** -----------------------------------
  1926. /** Delete Member Group
  1927. /** -----------------------------------*/
  1928. function delete_member_group()
  1929. {
  1930. global $DSP, $IN, $DB, $LANG, $SESS, $PREFS;
  1931. /** ----------------------------------------------------
  1932. /** Only super admins can delete member groups
  1933. /** ----------------------------------------------------*/
  1934. if ($SESS->userdata['group_id'] != 1)
  1935. {
  1936. return $DSP->no_access_message($LANG->line('only_superadmins_can_admin_groups'));
  1937. }
  1938. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  1939. {
  1940. return false;
  1941. }
  1942. if (in_array($group_id, $this->no_delete))
  1943. {
  1944. return $DSP->no_access_message();
  1945. }
  1946. $group_id = $DB->escape_str($group_id);
  1947. if ($IN->GBL('reassign') == 'y' AND $IN->GBL('new_group_id') != FALSE)
  1948. {
  1949. $new_group = $DB->escape_str($IN->GBL('new_group_id'));
  1950. $DB->query("UPDATE exp_members SET group_id = '{$new_group}' WHERE group_id = '{$group_id}'");
  1951. }
  1952. $DB->query("DELETE FROM exp_member_groups WHERE group_id = '{$group_id}'");
  1953. return $this->member_group_manager($DSP->qdiv('success', $LANG->line('member_group_deleted')));
  1954. }
  1955. /* END */
  1956. /** -----------------------------------
  1957. /** Create a member profile form
  1958. /** -----------------------------------*/
  1959. function new_member_profile_form()
  1960. {
  1961. global $IN, $DSP, $DB, $LANG, $SESS, $PREFS;
  1962. if ( ! $DSP->allowed_group('can_admin_members'))
  1963. {
  1964. return $DSP->no_access_message();
  1965. }
  1966. $DSP->body_props = " onload=\"document.forms[0].username.focus();\"";
  1967. $title = $LANG->line('register_member');
  1968. // Build the output
  1969. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=register_member'));
  1970. $r .= $DSP->qdiv('tableHeading', $title);
  1971. $r .= $DSP->div('box');
  1972. $r .= $DSP->itemgroup(
  1973. $DSP->required().NBS.$LANG->line('username', 'username'),
  1974. $DSP->input_text('username', '', '35', '32', 'input', '300px')
  1975. );
  1976. $r .= $DSP->itemgroup(
  1977. $DSP->required().NBS.$LANG->line('password', 'password'),
  1978. $DSP->input_pass('password', '', '35', '32', 'input', '300px')
  1979. );
  1980. $r .= $DSP->itemgroup(
  1981. $DSP->required().NBS.$LANG->line('password_confirm', 'password_confirm'),
  1982. $DSP->input_pass('password_confirm', '', '35', '32', 'input', '300px')
  1983. );
  1984. $r .= $DSP->itemgroup(
  1985. $DSP->required().NBS.$LANG->line('screen_name', 'screen_name'),
  1986. $DSP->input_text('screen_name', '', '40', '50', 'input', '300px')
  1987. );
  1988. $r .= $DSP->td_c().
  1989. $DSP->td('', '45%', '', '', 'top');
  1990. $r .= $DSP->itemgroup(
  1991. $DSP->required().NBS.$LANG->line('email', 'email'),
  1992. $DSP->input_text('email', '', '35', '100', 'input', '300px')
  1993. );
  1994. // Member groups assignment
  1995. if ($DSP->allowed_group('can_admin_mbr_groups'))
  1996. {
  1997. if ($SESS->userdata['group_id'] != 1)
  1998. {
  1999. $sql = "SELECT group_id, group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_locked = 'n' order by group_title";
  2000. }
  2001. else
  2002. {
  2003. $sql = "SELECT group_id, group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' order by group_title";
  2004. }
  2005. $query = $DB->query($sql);
  2006. if ($query->num_rows > 0)
  2007. {
  2008. $r .= $DSP->qdiv(
  2009. 'itemWrapperTop',
  2010. $DSP->qdiv('defaultBold', $LANG->line('member_group_assignment'))
  2011. );
  2012. $r .= $DSP->input_select_header('group_id');
  2013. foreach ($query->result as $row)
  2014. {
  2015. $selected = ($row['group_id'] == 5) ? 1 : '';
  2016. if ($row['group_id'] == 1 AND $SESS->userdata['group_id'] != 1)
  2017. {
  2018. continue;
  2019. }
  2020. $group_title = $row['group_title'];
  2021. if (in_array($group_title, $this->english))
  2022. {
  2023. $group_title = $LANG->line(strtolower(str_replace(" ", "_", $group_title)));
  2024. }
  2025. $r .= $DSP->input_select_option($row['group_id'], $group_title, $selected);
  2026. }
  2027. $r .= $DSP->input_select_footer();
  2028. }
  2029. }
  2030. $r .= $DSP->div_c();
  2031. // Submit button
  2032. $r .= $DSP->itemgroup( '',
  2033. $DSP->required(1).$DSP->br(2).$DSP->input_submit($LANG->line('submit'))
  2034. );
  2035. $r .= $DSP->form_close();
  2036. $DSP->title = $title;
  2037. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2038. $DSP->crumb_item($title);
  2039. $DSP->body = $r;
  2040. }
  2041. /* END */
  2042. /** ----------------------------------
  2043. /** Create a member profile
  2044. /** ----------------------------------*/
  2045. function create_member_profile()
  2046. {
  2047. global $IN, $DSP, $DB, $SESS, $PREFS, $FNS, $REGX, $LOC, $LOG, $LANG, $STAT, $EXT;
  2048. if ( ! $DSP->allowed_group('can_admin_members'))
  2049. {
  2050. return $DSP->no_access_message();
  2051. }
  2052. $data = array();
  2053. if ($IN->GBL('group_id', 'POST'))
  2054. {
  2055. if ( ! $DSP->allowed_group('can_admin_mbr_groups'))
  2056. {
  2057. return $DSP->no_access_message();
  2058. }
  2059. $data['group_id'] = $_POST['group_id'];
  2060. }
  2061. /* -------------------------------------------
  2062. /* 'cp_members_member_create_start' hook.
  2063. /* - Take over member creation when done through the CP
  2064. /* - Added 1.4.2
  2065. */
  2066. $edata = $EXT->call_extension('cp_members_member_create_start');
  2067. if ($EXT->end_script === TRUE) return;
  2068. /*
  2069. // -------------------------------------------*/
  2070. // If the screen name field is empty, we'll assign is
  2071. // from the username field.
  2072. if ($_POST['screen_name'] == '')
  2073. $_POST['screen_name'] = $_POST['username'];
  2074. /** -------------------------------------
  2075. /** Instantiate validation class
  2076. /** -------------------------------------*/
  2077. if ( ! class_exists('Validate'))
  2078. {
  2079. require PATH_CORE.'core.validate'.EXT;
  2080. }
  2081. $VAL = new Validate(
  2082. array(
  2083. 'member_id' => '',
  2084. 'val_type' => 'new', // new or update
  2085. 'fetch_lang' => TRUE,
  2086. 'require_cpw' => FALSE,
  2087. 'enable_log' => TRUE,
  2088. 'username' => $_POST['username'],
  2089. 'cur_username' => '',
  2090. 'screen_name' => stripslashes($_POST['screen_name']),
  2091. 'cur_screen_name' => '',
  2092. 'password' => $_POST['password'],
  2093. 'password_confirm' => $_POST['password_confirm'],
  2094. 'cur_password' => '',
  2095. 'email' => $_POST['email'],
  2096. 'cur_email' => ''
  2097. )
  2098. );
  2099. $VAL->validate_username();
  2100. $VAL->validate_screen_name();
  2101. $VAL->validate_password();
  2102. $VAL->validate_email();
  2103. /** -------------------------------------
  2104. /** Display error is there are any
  2105. /** -------------------------------------*/
  2106. if (count($VAL->errors) > 0)
  2107. {
  2108. return $VAL->show_errors();
  2109. }
  2110. // Assign the query data
  2111. $data['username'] = $_POST['username'];
  2112. $data['password'] = $FNS->hash(stripslashes($_POST['password']));
  2113. $data['ip_address'] = $IN->IP;
  2114. $data['unique_id'] = $FNS->random('encrypt');
  2115. $data['join_date'] = $LOC->now;
  2116. $data['email'] = $_POST['email'];
  2117. $data['screen_name'] = $_POST['screen_name'];
  2118. // Was a member group ID submitted?
  2119. $data['group_id'] = ( ! $IN->GBL('group_id', 'POST')) ? 2 : $_POST['group_id'];
  2120. $DB->query($DB->insert_string('exp_members', $data));
  2121. $member_id = $DB->insert_id;
  2122. // Create a record in the custom field table
  2123. $DB->query($DB->insert_string('exp_member_data', array('member_id' => $member_id)));
  2124. // Create a record in the member homepage table
  2125. $DB->query($DB->insert_string('exp_member_homepage', array('member_id' => $member_id)));
  2126. $message = $LANG->line('new_member_added');
  2127. // Write log file
  2128. $LOG->log_action($message.$DSP->nbs(2).stripslashes($data['username']));
  2129. // -------------------------------------------
  2130. // 'cp_members_member_create' hook.
  2131. // - Additional processing when a member is created through the CP
  2132. //
  2133. $edata = $EXT->call_extension('cp_members_member_create', $member_id, $data);
  2134. if ($EXT->end_script === TRUE) return;
  2135. //
  2136. // -------------------------------------------
  2137. // Update global stat
  2138. $STAT->update_member_stats();
  2139. // Build success message
  2140. return $this->view_all_members($DSP->qspan('success', $message).NBS.'<b>'.stripslashes($data['username']).'</b>');
  2141. }
  2142. /* END */
  2143. /** -----------------------------
  2144. /** Member banning forms
  2145. /** -----------------------------*/
  2146. function member_banning_forms()
  2147. {
  2148. global $IN, $LANG, $DSP, $PREFS, $DB;
  2149. if ( ! $DSP->allowed_group('can_ban_users'))
  2150. {
  2151. return $DSP->no_access_message();
  2152. }
  2153. $banned_ips = $PREFS->ini('banned_ips');
  2154. $banned_emails = $PREFS->ini('banned_emails');
  2155. $banned_usernames = $PREFS->ini('banned_usernames');
  2156. $banned_screen_names = $PREFS->ini('banned_screen_names');
  2157. $out = '';
  2158. $ips = '';
  2159. $email = '';
  2160. $users = '';
  2161. $screens = '';
  2162. if ($banned_ips != '')
  2163. {
  2164. foreach (explode('|', $banned_ips) as $val)
  2165. {
  2166. $ips .= $val.NL;
  2167. }
  2168. }
  2169. if ($banned_emails != '')
  2170. {
  2171. foreach (explode('|', $banned_emails) as $val)
  2172. {
  2173. $email .= $val.NL;
  2174. }
  2175. }
  2176. if ($banned_usernames != '')
  2177. {
  2178. foreach (explode('|', $banned_usernames) as $val)
  2179. {
  2180. $users .= $val.NL;
  2181. }
  2182. }
  2183. if ($banned_screen_names != '')
  2184. {
  2185. foreach (explode('|', $banned_screen_names) as $val)
  2186. {
  2187. $screens .= $val.NL;
  2188. }
  2189. }
  2190. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=save_ban_data')).
  2191. $DSP->qdiv('tableHeading', $LANG->line('user_banning'));
  2192. if ($IN->GBL('U'))
  2193. {
  2194. $r .= $DSP->qdiv('box', $DSP->qdiv('success', $LANG->line('ban_preferences_updated')));
  2195. }
  2196. $r .= $DSP->table('', '', '', '100%', '').
  2197. $DSP->tr().
  2198. $DSP->td('', '48%', '', '', 'top');
  2199. $r .= $DSP->div('box').
  2200. $DSP->heading($LANG->line('ip_address_banning', 'banned_ips'), 5).
  2201. $DSP->qdiv('itemWrapper', $DSP->qspan('highlight', $LANG->line('ip_banning_instructions'))).
  2202. $DSP->qdiv('itemWrapper', $LANG->line('ip_banning_instructions_cont')).
  2203. $DSP->input_textarea('banned_ips', stripslashes($ips), '22', 'textarea', '100%').BR.BR;
  2204. $r .= $DSP->heading(BR.$LANG->line('ban_options'), 5);
  2205. $selected = ($PREFS->ini('ban_action') == 'restrict') ? 1 : '';
  2206. $r .= $DSP->div('itemWrapper').
  2207. $DSP->input_radio('ban_action', 'restrict', $selected).NBS. $LANG->line('restrict_to_viewing').BR.
  2208. $DSP->div_c();
  2209. $selected = ($PREFS->ini('ban_action') == 'message') ? 1 : '';
  2210. $r .= $DSP->div('itemWrapper').
  2211. $DSP->input_radio('ban_action', 'message', $selected).NBS.$LANG->line('show_this_message', 'ban_message').BR.
  2212. $DSP->input_text('ban_message', $PREFS->ini('ban_message'), '50', '100', 'input', '100%').
  2213. $DSP->div_c();
  2214. $selected = ($PREFS->ini('ban_action') == 'bounce') ? 1 : '';
  2215. $destination = ($PREFS->ini('ban_destination') == '') ? 'http://' : $PREFS->ini('ban_destination');
  2216. $r .= $DSP->div('itemWrapper').
  2217. $DSP->input_radio('ban_action', 'bounce', $selected).NBS.$LANG->line('send_to_site', 'ban_destination').BR.
  2218. $DSP->input_text('ban_destination', $destination, '50', '70', 'input', '100%').
  2219. $DSP->div_c();
  2220. $r .= $DSP->div().BR.
  2221. $DSP->input_submit($LANG->line('update')).BR.BR.BR.
  2222. $DSP->div_c().
  2223. $DSP->div_c();
  2224. $r .= $DSP->td_c().
  2225. $DSP->td('', '4%', '', '', 'top').NBS.
  2226. $DSP->td_c().
  2227. $DSP->td('', '48%', '', '', 'top');
  2228. $r .= $DSP->div('box').
  2229. $DSP->heading($LANG->line('email_address_banning', 'banned_emails'), 5).
  2230. $DSP->qdiv('itemWrapper', $DSP->qspan('highlight', $LANG->line('email_banning_instructions'))).
  2231. $DSP->qdiv('itemWrapper', $LANG->line('email_banning_instructions_cont')).
  2232. $DSP->input_textarea('banned_emails', stripslashes($email), '9', 'textarea', '100%').
  2233. $DSP->div_c();
  2234. $r .= $DSP->qdiv('defaultSmall', NBS);
  2235. $r .= $DSP->div('box').
  2236. $DSP->heading($LANG->line('username_banning', 'banned_usernames'), 5).
  2237. $DSP->qdiv('itemWrapper', $DSP->qspan('highlight', $LANG->line('username_banning_instructions'))).
  2238. $DSP->input_textarea('banned_usernames', stripslashes($users), '9', 'textarea', '100%').
  2239. $DSP->div_c();
  2240. $r .= $DSP->qdiv('defaultSmall', NBS);
  2241. $r .= $DSP->div('box').
  2242. $DSP->heading($LANG->line('screen_name_banning', 'banned_screen_names'), 5).
  2243. $DSP->qdiv('itemWrapper', $DSP->qspan('highlight', $LANG->line('screen_name_banning_instructions'))).
  2244. $DSP->input_textarea('banned_screen_names', stripslashes($screens), '9', 'textarea', '100%').
  2245. $DSP->div_c();
  2246. $r .= $DSP->td_c().
  2247. $DSP->tr_c().
  2248. $DSP->table_c();
  2249. $r .= $DSP->form_close();
  2250. $DSP->title = $LANG->line('user_banning');
  2251. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2252. $DSP->crumb_item($LANG->line('user_banning'));
  2253. $DSP->body = $r;
  2254. }
  2255. /* END */
  2256. /** -----------------------------
  2257. /** Update banning data
  2258. /** -----------------------------*/
  2259. function update_banning_data()
  2260. {
  2261. global $IN, $DSP, $DB, $PREFS, $REGX, $FNS;
  2262. if ( ! $DSP->allowed_group('can_ban_users'))
  2263. {
  2264. return $DSP->no_access_message();
  2265. }
  2266. foreach ($_POST as $key => $val)
  2267. {
  2268. $_POST[$key] = stripslashes($val);
  2269. }
  2270. $banned_ips = str_replace(NL, '|', $_POST['banned_ips']);
  2271. $banned_emails = str_replace(NL, '|', $_POST['banned_emails']);
  2272. $banned_usernames = str_replace(NL, '|', $_POST['banned_usernames']);
  2273. $banned_screen_names = str_replace(NL, '|', $_POST['banned_screen_names']);
  2274. $destination = ($_POST['ban_destination'] == 'http://') ? '' : $_POST['ban_destination'];
  2275. $data = array(
  2276. 'banned_ips' => $banned_ips,
  2277. 'banned_emails' => $banned_emails,
  2278. 'banned_emails' => $banned_emails,
  2279. 'banned_usernames' => $banned_usernames,
  2280. 'banned_screen_names' => $banned_screen_names,
  2281. 'ban_action' => $_POST['ban_action'],
  2282. 'ban_message' => $_POST['ban_message'],
  2283. 'ban_destination' => $destination
  2284. );
  2285. /** ----------------------------------------
  2286. /** Preferences Stored in Database For Site
  2287. /** ----------------------------------------*/
  2288. $query = $DB->query("SELECT site_id, site_system_preferences FROM exp_sites");
  2289. foreach($query->result AS $row)
  2290. {
  2291. $prefs = array_merge($REGX->array_stripslashes(unserialize($row['site_system_preferences'])), $data);
  2292. $query = $DB->query($DB->update_string('exp_sites',
  2293. array('site_system_preferences' => addslashes(serialize($prefs))),
  2294. "site_id = '".$DB->escape_str($row['site_id'])."'"));
  2295. }
  2296. $override = ($IN->GBL('class_override', 'GET') != '') ? AMP.'class_override='.$IN->GBL('class_override', 'GET') : '';
  2297. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=member_banning'.AMP.'U=1'.$override);
  2298. exit;
  2299. }
  2300. /* END */
  2301. /** -----------------------------------------------------------
  2302. /** Custom profile fields
  2303. /** -----------------------------------------------------------*/
  2304. // This function show a list of current member fields and the
  2305. // form that allows you to create a new field.
  2306. //-----------------------------------------------------------
  2307. function custom_profile_fields($group_id = '')
  2308. {
  2309. global $DSP, $IN, $DB, $LANG;
  2310. if ( ! $DSP->allowed_group('can_admin_members'))
  2311. {
  2312. return $DSP->no_access_message();
  2313. }
  2314. // Fetch language file
  2315. // There are some lines in the publish administration language file
  2316. // that we need.
  2317. $LANG->fetch_language_file('publish_ad');
  2318. $DSP->title = $LANG->line('custom_member_fields');
  2319. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2320. $DSP->crumb_item($LANG->line('custom_member_fields'));
  2321. $DSP->right_crumb($LANG->line('create_new_profile_field'),BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_field');
  2322. // Build the output
  2323. $r = $DSP->qdiv('tableHeading', $LANG->line('custom_member_fields'));
  2324. if ($IN->GBL('U'))
  2325. {
  2326. $r .= $DSP->qdiv('success', $LANG->line('field_updated'));
  2327. }
  2328. $query = $DB->query("SELECT m_field_id, m_field_order, m_field_label FROM exp_member_fields ORDER BY m_field_order");
  2329. if ($query->num_rows == 0)
  2330. {
  2331. $DSP->body = $DSP->div('box');
  2332. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->heading($LANG->line('no_custom_profile_fields'), 5));
  2333. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_field', $LANG->line('create_new_profile_field')));
  2334. $DSP->body .= $DSP->div_c();
  2335. return;
  2336. }
  2337. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  2338. $DSP->tr().
  2339. $DSP->td('tableHeadingAlt', '', '3').
  2340. $LANG->line('current_fields').
  2341. $DSP->td_c().
  2342. $DSP->tr_c();
  2343. $i = 0;
  2344. foreach ($query->result as $row)
  2345. {
  2346. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  2347. $r .= $DSP->tr();
  2348. $r .= $DSP->table_qcell($style, $row['m_field_order'].$DSP->nbs(2).$DSP->qspan('defaultBold', $row['m_field_label']), '40%');
  2349. $r .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_field'.AMP.'m_field_id='.$row['m_field_id'], $LANG->line('edit')), '30%');
  2350. $r .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=del_field_conf'.AMP.'m_field_id='.$row['m_field_id'], $LANG->line('delete')), '30%');
  2351. $r .= $DSP->tr_c();
  2352. }
  2353. $r .= $DSP->table_c();
  2354. $r .= $DSP->qdiv('paddedWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_field_order', $LANG->line('edit_field_order')));
  2355. $DSP->body = $r;
  2356. }
  2357. /* END */
  2358. /** -----------------------------------------------------------
  2359. /** Edit field form
  2360. /** -----------------------------------------------------------*/
  2361. // This function lets you edit an existing custom field
  2362. //-----------------------------------------------------------
  2363. function edit_profile_field_form()
  2364. {
  2365. global $DSP, $IN, $DB, $REGX, $LANG;
  2366. if ( ! $DSP->allowed_group('can_admin_members'))
  2367. {
  2368. return $DSP->no_access_message();
  2369. }
  2370. $type = ($m_field_id = $IN->GBL('m_field_id')) ? 'edit' : 'new';
  2371. // Fetch language file
  2372. // There are some lines in the publish administration language file
  2373. // that we need.
  2374. $LANG->fetch_language_file('publish_ad');
  2375. $total_fields = '';
  2376. if ($type == 'new')
  2377. {
  2378. $query = $DB->query("SELECT count(*) AS count FROM exp_member_fields");
  2379. $total_fields = $query->row['count'] + 1;
  2380. }
  2381. $DB->fetch_fields = TRUE;
  2382. $query = $DB->query("SELECT * FROM exp_member_fields WHERE m_field_id = '$m_field_id'");
  2383. if ($query->num_rows == 0)
  2384. {
  2385. foreach ($query->fields as $f)
  2386. {
  2387. $$f = '';
  2388. }
  2389. }
  2390. else
  2391. {
  2392. foreach ($query->row as $key => $val)
  2393. {
  2394. $$key = $val;
  2395. }
  2396. }
  2397. $r = <<<EOT
  2398. <script type="text/javascript">
  2399. <!--
  2400. function showhide_element(id)
  2401. {
  2402. if (id == 'text')
  2403. {
  2404. document.getElementById('text_block').style.display = "block";
  2405. document.getElementById('textarea_block').style.display = "none";
  2406. document.getElementById('select_block').style.display = "none";
  2407. }
  2408. else if (id == 'textarea')
  2409. {
  2410. document.getElementById('textarea_block').style.display = "block";
  2411. document.getElementById('text_block').style.display = "none";
  2412. document.getElementById('select_block').style.display = "none";
  2413. }
  2414. else
  2415. {
  2416. document.getElementById('select_block').style.display = "block";
  2417. document.getElementById('text_block').style.display = "none";
  2418. document.getElementById('textarea_block').style.display = "none";
  2419. }
  2420. }
  2421. -->
  2422. </script>
  2423. EOT;
  2424. $title = ($type == 'edit') ? 'edit_member_field' : 'create_member_field';
  2425. $i = 0;
  2426. // Form declaration
  2427. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=update_profile_fields'.AMP.'U=1'));
  2428. $r .= $DSP->input_hidden('m_field_id', $m_field_id);
  2429. $r .= $DSP->input_hidden('cur_field_name', $m_field_name);
  2430. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  2431. $DSP->tr().
  2432. $DSP->td('tableHeading', '', '2').$LANG->line($title).$DSP->td_c().
  2433. $DSP->tr_c();
  2434. /** ---------------------------------
  2435. /** Field name
  2436. /** ---------------------------------*/
  2437. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2438. $r .= $DSP->tr();
  2439. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('fieldname', 'm_field_name')).$DSP->qdiv('itemWrapper', $LANG->line('fieldname_cont')), '40%');
  2440. $r .= $DSP->table_qcell($style, $DSP->input_text('m_field_name', $m_field_name, '50', '60', 'input', '300px'), '60%');
  2441. $r .= $DSP->tr_c();
  2442. /** ---------------------------------
  2443. /** Field label
  2444. /** ---------------------------------*/
  2445. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2446. $r .= $DSP->tr();
  2447. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('fieldlabel', 'm_field_label')).$DSP->qdiv('itemWrapper', $LANG->line('for_profile_page')), '40%');
  2448. $r .= $DSP->table_qcell($style, $DSP->input_text('m_field_label', $m_field_label, '50', '60', 'input', '300px'), '60%');
  2449. $r .= $DSP->tr_c();
  2450. /** ---------------------------------
  2451. /** Field Description
  2452. /** ---------------------------------*/
  2453. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2454. $r .= $DSP->tr();
  2455. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_description', 'm_field_description')).$DSP->qdiv('itemWrapper', $LANG->line('field_description_info')), '40%');
  2456. $r .= $DSP->table_qcell($style, $DSP->input_textarea('m_field_description', $m_field_description, '4', 'textarea', '100%'), '60%');
  2457. $r .= $DSP->tr_c();
  2458. /** ---------------------------------
  2459. /** Field order
  2460. /** ---------------------------------*/
  2461. if ($type == 'new')
  2462. $m_field_order = $total_fields;
  2463. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2464. $r .= $DSP->tr();
  2465. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_order', 'm_field_order')), '40%');
  2466. $r .= $DSP->table_qcell($style, $DSP->input_text('m_field_order', $m_field_order, '4', '3', 'input', '30px'), '60%');
  2467. $r .= $DSP->tr_c();
  2468. /** ---------------------------------
  2469. /** Field type
  2470. /** ---------------------------------*/
  2471. $sel_1 = ''; $sel_2 = ''; $sel_3 = '';
  2472. $text_js = ($type == 'edit') ? 'none' : 'block';
  2473. $textarea_js = 'none';
  2474. $select_js = 'none';
  2475. $select_opt_js = 'none';
  2476. switch ($m_field_type)
  2477. {
  2478. case 'text' : $sel_1 = 1; $text_js = 'block';
  2479. break;
  2480. case 'textarea' : $sel_2 = 1; $textarea_js = 'block';
  2481. break;
  2482. case 'select' : $sel_3 = 1; $select_js = 'block'; $select_opt_js = 'block';
  2483. break;
  2484. }
  2485. /** ---------------------------------
  2486. /** Create the pull-down menu
  2487. /** ---------------------------------*/
  2488. $typemenu = "<select name='m_field_type' class='select' onchange='showhide_element(this.options[this.selectedIndex].value);' >".NL;
  2489. $typemenu .= $DSP->input_select_option('text', $LANG->line('text_input'), $sel_1)
  2490. .$DSP->input_select_option('textarea', $LANG->line('textarea'), $sel_2)
  2491. .$DSP->input_select_option('select', $LANG->line('select_list'), $sel_3)
  2492. .$DSP->input_select_footer();
  2493. /** ---------------------------------
  2494. /** Field width
  2495. /** ---------------------------------*/
  2496. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2497. if ($m_field_width == '')
  2498. $m_field_width = '100%';
  2499. $r .= $DSP->tr();
  2500. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_width', 'm_field_width')).$DSP->qdiv('itemWrapper', $LANG->line('field_width_cont')), '40%');
  2501. $r .= $DSP->table_qcell($style, $DSP->input_text('m_field_width', $m_field_width, '8', '6', 'input', '60px'), '60%');
  2502. $r .= $DSP->tr_c();
  2503. /** ---------------------------------
  2504. /** Max-length Field
  2505. /** ---------------------------------*/
  2506. if ($m_field_maxl == '') $m_field_maxl = '100';
  2507. $typopts = '<div id="text_block" style="display: '.$text_js.'; padding:0; margin:5px 0 0 0;">';
  2508. $typopts .= $DSP->qdiv('defaultBold', $LANG->line('max_length', 'm_field_maxl')).$DSP->qdiv('itemWrapper', $DSP->input_text('m_field_maxl', $m_field_maxl, '4', '3', 'input', '30px'));
  2509. $typopts .= $DSP->div_c();
  2510. /** ---------------------------------
  2511. /** Textarea Row Field
  2512. /** ---------------------------------*/
  2513. if ($m_field_ta_rows == '') $m_field_ta_rows = '10';
  2514. $typopts .= '<div id="textarea_block" style="display: '.$textarea_js.'; padding:0; margin:5px 0 0 0;">';
  2515. $typopts .= $DSP->qdiv('defaultBold', $LANG->line('text_area_rows', 'm_field_ta_rows')).$DSP->qdiv('itemWrapper', $DSP->input_text('m_field_ta_rows', $m_field_ta_rows, '4', '3', 'input', '30px'));
  2516. $typopts .= $DSP->div_c();
  2517. /** ---------------------------------
  2518. /** Select List Field
  2519. /** ---------------------------------*/
  2520. $typopts .= '<div id="select_block" style="display: '.$select_js.'; padding:0; margin:5px 0 0 0;">';
  2521. $typopts .= $DSP->qdiv('defaultBold', $LANG->line('pull_down_items', 'm_field_list_items')).$DSP->qdiv('default', $LANG->line('field_list_instructions')).$DSP->input_textarea('m_field_list_items', $m_field_list_items, 10, 'textarea', '400px');
  2522. $typopts .= $DSP->div_c();
  2523. /** ---------------------------------
  2524. /** Generate the above items
  2525. /** ---------------------------------*/
  2526. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2527. $r .= $DSP->tr();
  2528. $r .= $DSP->table_qcell($style, $DSP->qdiv('itemWrapper', $DSP->qspan('defaultBold', $LANG->line('field_type'))).$typemenu, '50%', 'top');
  2529. $r .= $DSP->table_qcell($style, $typopts, '50%', 'top');
  2530. $r .= $DSP->tr_c();
  2531. /** ---------------------------------
  2532. /** Field formatting
  2533. /** ---------------------------------*/
  2534. $sel_1 = ''; $sel_2 = ''; $sel_3 = '';
  2535. switch ($m_field_fmt)
  2536. {
  2537. case 'none' : $sel_1 = 1;
  2538. break;
  2539. case 'br' : $sel_2 = 1;
  2540. break;
  2541. case 'xhtml' : $sel_3 = 1;
  2542. break;
  2543. default : $sel_3 = 1;
  2544. break;
  2545. }
  2546. $typemenu = $DSP->input_select_header('m_field_fmt')
  2547. .$DSP->input_select_option('none', $LANG->line('none'), $sel_1)
  2548. .$DSP->input_select_option('br', $LANG->line('auto_br'), $sel_2)
  2549. .$DSP->input_select_option('xhtml', $LANG->line('xhtml'), $sel_3)
  2550. .$DSP->input_select_footer();
  2551. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2552. $r .= $DSP->tr();
  2553. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_format')).$DSP->qdiv('itemWrapper', $LANG->line('text_area_rows_cont')), '40%');
  2554. $r .= $DSP->table_qcell($style, $typemenu, '60%');
  2555. $r .= $DSP->tr_c();
  2556. /** ---------------------------------
  2557. /** Is field required?
  2558. /** ---------------------------------*/
  2559. if ($m_field_required == '') $m_field_required = 'n';
  2560. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2561. $r .= $DSP->tr();
  2562. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_required')), '40%');
  2563. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('m_field_required', 'y', ($m_field_required == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('m_field_required', 'n', ($m_field_required == 'n') ? 1 : ''), '60%');
  2564. $r .= $DSP->tr_c();
  2565. /** ---------------------------------
  2566. /** Is field public?
  2567. /** ---------------------------------*/
  2568. if ($m_field_public == '') $m_field_public = 'y';
  2569. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2570. $r .= $DSP->tr();
  2571. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_public')).$DSP->qdiv('itemWrapper', $LANG->line('is_field_public_cont')), '40%');
  2572. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('m_field_public', 'y', ($m_field_public == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('m_field_public', 'n', ($m_field_public == 'n') ? 1 : ''), '60%');
  2573. $r .= $DSP->tr_c();
  2574. /** ---------------------------------
  2575. /** Is field visible in reg page?
  2576. /** ---------------------------------*/
  2577. if ($m_field_reg == '') $m_field_reg = 'n';
  2578. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2579. $r .= $DSP->tr();
  2580. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_reg')).$DSP->qdiv('itemWrapper', $LANG->line('is_field_public_cont')), '40%');
  2581. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('m_field_reg', 'y', ($m_field_reg == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('m_field_reg', 'n', ($m_field_reg == 'n') ? 1 : ''), '60%');
  2582. $r .= $DSP->tr_c();
  2583. /** ---------------------------------
  2584. /** Is field searchable?
  2585. /** ---------------------------------*/
  2586. /*
  2587. if ($m_field_search == '') $m_field_search = 'n';
  2588. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2589. $r .= $DSP->tr();
  2590. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_searchable')), '40%');
  2591. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('m_field_search', 'y', ($m_field_search == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('m_field_search', 'n', ($m_field_search == 'n') ? 1 : ''), '60%');
  2592. $r .= $DSP->tr_c();
  2593. */
  2594. $r .= $DSP->table_c();
  2595. $r .= $DSP->div('itemWrapper');
  2596. $r .= $DSP->required(1).BR.BR;
  2597. if ($type == 'edit')
  2598. $r .= $DSP->input_submit($LANG->line('update'));
  2599. else
  2600. $r .= $DSP->input_submit($LANG->line('submit'));
  2601. $r .= $DSP->div_c();
  2602. $r .= $DSP->form_close();
  2603. $DSP->title = $LANG->line('edit_member_field');
  2604. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2605. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=profile_fields', $LANG->line('custom_member_fields'))).
  2606. $DSP->crumb_item($LANG->line('edit_member_field'));
  2607. $DSP->body = $r;
  2608. }
  2609. /* END */
  2610. /** -----------------------------------------------------------
  2611. /** Create/update custom fields
  2612. /** -----------------------------------------------------------*/
  2613. // This function alters the "exp_member_data" table, adding
  2614. // the new custom fields.
  2615. //-----------------------------------------------------------
  2616. function update_profile_fields()
  2617. {
  2618. global $DSP, $IN, $DB, $REGX, $LANG;
  2619. if ( ! $DSP->allowed_group('can_admin_members'))
  2620. {
  2621. return $DSP->no_access_message();
  2622. }
  2623. $LANG->fetch_language_file('publish_ad');
  2624. // If the $field_id variable is present we are editing an
  2625. // existing field, otherwise we are creating a new one
  2626. $edit = (isset($_POST['m_field_id']) AND $_POST['m_field_id'] != '') ? TRUE : FALSE;
  2627. // Check for required fields
  2628. $error = array();
  2629. if ($_POST['m_field_name'] == '')
  2630. {
  2631. $error[] = $LANG->line('no_field_name');
  2632. }
  2633. if ($_POST['m_field_label'] == '')
  2634. {
  2635. $error[] = $LANG->line('no_field_label');
  2636. }
  2637. // Is the field one of the reserved words?
  2638. if (in_array($_POST['m_field_name'], $DSP->invalid_custom_field_names()))
  2639. {
  2640. $error[] = $LANG->line('reserved_word');
  2641. }
  2642. // Does field name have invalid characters?
  2643. if ( ! preg_match("#^[a-z0-9\_\-]+$#i", $_POST['m_field_name']))
  2644. {
  2645. $error[] = $LANG->line('invalid_characters');
  2646. }
  2647. // Is the field name taken?
  2648. $query = $DB->query("SELECT count(*) as count FROM exp_member_fields WHERE m_field_name = '".$DB->escape_str($_POST['m_field_name'])."'");
  2649. if (($edit == FALSE || ($edit == TRUE && $_POST['m_field_name'] != $_POST['cur_field_name']))
  2650. && $query->row['count'] > 0)
  2651. {
  2652. $error[] = $LANG->line('duplicate_field_name');
  2653. }
  2654. unset($_POST['cur_field_name']);
  2655. // Are there errors to display?
  2656. if (count($error) > 0)
  2657. {
  2658. $str = '';
  2659. foreach ($error as $msg)
  2660. {
  2661. $str .= $msg.BR;
  2662. }
  2663. return $DSP->error_message($str);
  2664. }
  2665. if ($_POST['m_field_list_items'] != '')
  2666. {
  2667. $_POST['m_field_list_items'] = $REGX->convert_quotes($_POST['m_field_list_items']);
  2668. }
  2669. // Construct the query based on whether we are updating or inserting
  2670. if ($edit === TRUE)
  2671. {
  2672. $n = $_POST['m_field_maxl'];
  2673. if ($_POST['m_field_type'] == 'text')
  2674. {
  2675. if ( ! is_numeric($n) || $n == '' || $n == 0)
  2676. {
  2677. $n = '100';
  2678. }
  2679. $f_type = 'varchar('.$n.') NOT NULL';
  2680. }
  2681. else
  2682. {
  2683. $f_type = 'text NOT NULL';
  2684. }
  2685. $DB->query("ALTER table exp_member_data CHANGE m_field_id_".$_POST['m_field_id']." m_field_id_".$_POST['m_field_id']." $f_type");
  2686. $id = $_POST['m_field_id'];
  2687. unset($_POST['m_field_id']);
  2688. $DB->query($DB->update_string('exp_member_fields', $_POST, 'm_field_id='.$id));
  2689. }
  2690. else
  2691. {
  2692. if ($_POST['m_field_order'] == 0 || $_POST['m_field_order'] == '')
  2693. {
  2694. $query = $DB->query("SELECT count(*) AS count FROM exp_member_fields");
  2695. $total = $query->row['count'] + 1;
  2696. $_POST['m_field_order'] = $total;
  2697. }
  2698. unset($_POST['m_field_id']);
  2699. $DB->query($DB->insert_string('exp_member_fields', $_POST));
  2700. $DB->query("ALTER table exp_member_data add column m_field_id_{$DB->insert_id} text NOT NULL");
  2701. $sql = "SELECT exp_members.member_id
  2702. FROM exp_members
  2703. LEFT JOIN exp_member_data ON exp_members.member_id = exp_member_data.member_id
  2704. WHERE exp_member_data.member_id IS NULL
  2705. ORDER BY exp_members.member_id";
  2706. $query = $DB->query($sql);
  2707. if ($query->num_rows > 0)
  2708. {
  2709. foreach ($query->result as $row)
  2710. {
  2711. $DB->query("INSERT INTO exp_member_data (member_id) values ('{$row['member_id']}')");
  2712. }
  2713. }
  2714. }
  2715. return $this->custom_profile_fields();
  2716. }
  2717. /* END */
  2718. /** -----------------------------------------------------------
  2719. /** Delete field confirm
  2720. /** -----------------------------------------------------------*/
  2721. // Warning message if you try to delete a custom profile field
  2722. //-----------------------------------------------------------
  2723. function delete_profile_field_conf()
  2724. {
  2725. global $DSP, $IN, $DB, $LANG;
  2726. if ( ! $DSP->allowed_group('can_admin_members'))
  2727. {
  2728. return $DSP->no_access_message();
  2729. }
  2730. if ( ! $m_field_id = $IN->GBL('m_field_id'))
  2731. {
  2732. return false;
  2733. }
  2734. $LANG->fetch_language_file('publish_ad');
  2735. $query = $DB->query("SELECT m_field_label FROM exp_member_fields WHERE m_field_id = '$m_field_id'");
  2736. $DSP->title = $LANG->line('delete_field');
  2737. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2738. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=profile_fields', $LANG->line('custom_member_fields'))).
  2739. $DSP->crumb_item($LANG->line('edit_member_field'));
  2740. $DSP->body = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=delete_field'.AMP.'m_field_id='.$m_field_id))
  2741. .$DSP->input_hidden('m_field_id', $m_field_id)
  2742. .$DSP->qdiv('alertHeading', $LANG->line('delete_field'))
  2743. .$DSP->div('box')
  2744. .$DSP->qdiv('itemWrapper', '<b>'.$LANG->line('delete_field_confirmation').'</b>')
  2745. .$DSP->qdiv('itemWrapper', '<i>'.$query->row['m_field_label'].'</i>')
  2746. .$DSP->qdiv('alert', BR.$LANG->line('action_can_not_be_undone'))
  2747. .$DSP->qdiv('itemWrapper', BR.$DSP->input_submit($LANG->line('delete')))
  2748. .$DSP->div_c()
  2749. .$DSP->form_close();
  2750. }
  2751. /* END */
  2752. /** -----------------------------------------------------------
  2753. /** Delete member profile field
  2754. /** -----------------------------------------------------------*/
  2755. function delete_profile_field()
  2756. {
  2757. global $DSP, $IN, $DB, $LOG, $LANG;
  2758. if ( ! $DSP->allowed_group('can_admin_members'))
  2759. {
  2760. return $DSP->no_access_message();
  2761. }
  2762. if ( ! $m_field_id = $IN->GBL('m_field_id'))
  2763. {
  2764. return false;
  2765. }
  2766. $query = $DB->query("SELECT m_field_label FROM exp_member_fields WHERE m_field_id = '$m_field_id'");
  2767. $m_field_label = $query->row['m_field_label'];
  2768. $DB->query("ALTER TABLE exp_member_data DROP COLUMN m_field_id_".$m_field_id);
  2769. $DB->query("DELETE FROM exp_member_fields WHERE m_field_id = '$m_field_id'");
  2770. $LOG->log_action($LANG->line('profile_field_deleted').$DSP->nbs(2).$m_field_label);
  2771. return $this->custom_profile_fields();
  2772. }
  2773. /* END */
  2774. /** -----------------------------------------------------------
  2775. /** Edit field order
  2776. /** -----------------------------------------------------------*/
  2777. function edit_field_order_form()
  2778. {
  2779. global $DSP, $IN, $DB, $LANG;
  2780. if ( ! $DSP->allowed_group('can_admin_members'))
  2781. {
  2782. return $DSP->no_access_message();
  2783. }
  2784. $LANG->fetch_language_file('publish_ad');
  2785. $query = $DB->query("SELECT m_field_label, m_field_name, m_field_order FROM exp_member_fields ORDER BY m_field_order");
  2786. if ($query->num_rows == 0)
  2787. {
  2788. return false;
  2789. }
  2790. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=update_field_order'));
  2791. $r .= $DSP->table('tableBorder', '0', '10', '100%');
  2792. $r .= $DSP->td('tableHeading', '', '3').
  2793. $LANG->line('edit_field_order').
  2794. $DSP->td_c().
  2795. $DSP->tr_c();
  2796. foreach ($query->result as $row)
  2797. {
  2798. $r .= $DSP->tr();
  2799. $r .= $DSP->table_qcell('tableCellOne', $row['m_field_label']);
  2800. $r .= $DSP->table_qcell('tableCellOne', $DSP->input_text($row['m_field_name'], $row['m_field_order'], '4', '3', 'input', '30px'));
  2801. $r .= $DSP->tr_c();
  2802. }
  2803. $r .= $DSP->table_c();
  2804. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  2805. $r .= $DSP->form_close();
  2806. $DSP->title = $LANG->line('edit_field_order');
  2807. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2808. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=profile_fields', $LANG->line('custom_member_fields'))).
  2809. $DSP->crumb_item($LANG->line('edit_field_order'));
  2810. $DSP->body = $r;
  2811. }
  2812. /* END */
  2813. /** -----------------------------------------------------------
  2814. /** Update field order
  2815. /** -----------------------------------------------------------*/
  2816. // This function receives the field order submission
  2817. //-----------------------------------------------------------
  2818. function update_field_order()
  2819. {
  2820. global $DSP, $IN, $DB, $LANG;
  2821. if ( ! $DSP->allowed_group('can_admin_members'))
  2822. {
  2823. return $DSP->no_access_message();
  2824. }
  2825. foreach ($_POST as $key => $val)
  2826. {
  2827. $DB->query("UPDATE exp_member_fields SET m_field_order = '$val' WHERE m_field_name = '".$DB->escape_str($key)."'");
  2828. }
  2829. return $this->custom_profile_fields();
  2830. }
  2831. /* END */
  2832. /** -----------------------------
  2833. /** Member search form
  2834. /** -----------------------------*/
  2835. function member_search_form($message = '')
  2836. {
  2837. global $LANG, $DSP, $DB, $PREFS;
  2838. $DSP->body = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=do_member_search'));
  2839. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('member_search'));
  2840. if ($message != '')
  2841. $DSP->body .= $DSP->qdiv('box', $message);
  2842. $DSP->body .= $DSP->div('box');
  2843. $DSP->body .= $DSP->qdiv('itemWrapper', $LANG->line('member_search_instructions'));
  2844. $DSP->body .= $DSP->itemgroup(
  2845. $LANG->line('username', 'username'),
  2846. $DSP->input_text('username', '', '35', '100', 'input', '300px')
  2847. );
  2848. $DSP->body .= $DSP->itemgroup(
  2849. $LANG->line('email', 'email'),
  2850. $DSP->input_text('email', '', '35', '100', 'input', '300px')
  2851. );
  2852. $DSP->body .= $DSP->itemgroup(
  2853. $LANG->line('screen_name', 'screen_name'),
  2854. $DSP->input_text('screen_name', '', '35', '100', 'input', '300px')
  2855. );
  2856. $DSP->body .= $DSP->itemgroup(
  2857. $LANG->line('url', 'url'),
  2858. $DSP->input_text('url', '', '35', '100', 'input', '300px')
  2859. );
  2860. $DSP->body .= $DSP->itemgroup(
  2861. $LANG->line('ip_address', 'ip_address'),
  2862. $DSP->input_text('ip_address', '', '35', '100', 'input', '300px')
  2863. );
  2864. $DSP->body .= $DSP->itemgroup(
  2865. $DSP->qdiv('defaultBold', $LANG->line('member_group'))
  2866. );
  2867. // Member group select list
  2868. $query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_title");
  2869. $DSP->body .= $DSP->input_select_header('group_id');
  2870. $DSP->body .= $DSP->input_select_option('any', $LANG->line('any'));
  2871. foreach ($query->result as $row)
  2872. {
  2873. $DSP->body.= $DSP->input_select_option($row['group_id'], $row['group_title']);
  2874. }
  2875. $DSP->body .= $DSP->input_select_footer();
  2876. $DSP->body .= $DSP->div_c();
  2877. $DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  2878. $DSP->body .= $DSP->form_close();
  2879. $DSP->title = $LANG->line('member_search');
  2880. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  2881. $DSP->crumb_item($LANG->line('member_search'));
  2882. }
  2883. /* END */
  2884. /** -----------------------------
  2885. /** Member search
  2886. /** -----------------------------*/
  2887. function do_member_search()
  2888. {
  2889. global $IN, $LANG, $DSP, $FNS, $LOC, $DB, $PREFS;
  2890. $pageurl = BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=do_member_search';
  2891. $custom = FALSE;
  2892. /** -----------------------------
  2893. /** Homepage source?
  2894. /** -----------------------------*/
  2895. // Since we allow a simplified member search field to be displayed
  2896. // on the Control Panel homepage, we need to set the proper POST variable
  2897. if (isset($_POST['criteria']))
  2898. {
  2899. if ($_POST['keywords'] == '')
  2900. {
  2901. $FNS->redirect(BASE);
  2902. exit;
  2903. }
  2904. if (substr($_POST['criteria'], 0, 11) == 'm_field_id_' && is_numeric(substr($_POST['criteria'], 11)))
  2905. {
  2906. $custom = TRUE;
  2907. }
  2908. $_POST[$_POST['criteria']] = $_POST['keywords'];
  2909. unset($_POST['keywords']);
  2910. unset($_POST['criteria']);
  2911. }
  2912. // Done...
  2913. /** --------------------------------
  2914. /** Parse the GET or POST request
  2915. /** --------------------------------*/
  2916. if ($Q = $IN->GBL('Q', 'GET'))
  2917. {
  2918. $Q = stripslashes(base64_decode(urldecode($Q)));
  2919. }
  2920. else
  2921. {
  2922. foreach (array('username', 'screen_name', 'email', 'url', 'ip_address') as $pval)
  2923. {
  2924. if ( ! isset($_POST[$pval]))
  2925. {
  2926. $_POST[$pval] = '';
  2927. }
  2928. }
  2929. if ( $_POST['username'] == '' &&
  2930. $_POST['screen_name'] == '' &&
  2931. $_POST['email'] == '' &&
  2932. $_POST['url'] == '' &&
  2933. $_POST['ip_address'] == '' &&
  2934. $custom === FALSE
  2935. )
  2936. {
  2937. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=member_search');
  2938. exit;
  2939. }
  2940. $search_query = array();
  2941. foreach ($_POST as $key => $val)
  2942. {
  2943. if ($key == 'group_id')
  2944. {
  2945. if ($val != 'any')
  2946. {
  2947. $search_query[] = " g.group_id ='".$DB->escape_str($_POST['group_id'])."'";
  2948. }
  2949. }
  2950. elseif ($key != 'exact_match')
  2951. {
  2952. if ($val != '')
  2953. {
  2954. if (isset($_POST['exact_match']))
  2955. {
  2956. $search_query[] = $key." = '".$DB->escape_str($val)."'";
  2957. }
  2958. else
  2959. {
  2960. $search_query[] = $key." LIKE '%".$DB->escape_like_str($val)."%'";
  2961. }
  2962. }
  2963. }
  2964. }
  2965. if (count($search_query) < 1)
  2966. {
  2967. return $this->member_search_form();
  2968. }
  2969. $Q = implode(" AND ", $search_query);
  2970. }
  2971. $pageurl .= AMP.'Q='.urlencode(base64_encode(stripslashes($Q)));
  2972. $sql = "SELECT DISTINCT
  2973. m.username,
  2974. m.member_id,
  2975. m.screen_name,
  2976. m.email,
  2977. m.join_date,
  2978. m.ip_address,
  2979. g.group_title
  2980. FROM exp_members AS m, exp_member_groups AS g";
  2981. if ($custom === TRUE)
  2982. {
  2983. $sql .= ", exp_member_data AS md";
  2984. }
  2985. $sql .= " WHERE m.group_id = g.group_id AND g.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND ".$Q;
  2986. if ($custom === TRUE)
  2987. {
  2988. $sql .= " AND md.member_id = m.member_id";
  2989. }
  2990. $query = $DB->query($sql);
  2991. // No result? Show the "no results" message
  2992. $total_count = $query->num_rows;
  2993. if ($total_count == 0)
  2994. {
  2995. return $this->member_search_form($DSP->qdiv('itemWrapper', $DSP->qdiv('alert', $LANG->line('no_search_results'))));
  2996. }
  2997. // Get the current row number and add the LIMIT clause to the SQL query
  2998. if ( ! $rownum = $IN->GBL('rownum', 'GP'))
  2999. {
  3000. $rownum = 0;
  3001. }
  3002. $sql .= " LIMIT ".$rownum.", ".$this->perpage;
  3003. // Run the query
  3004. $query = $DB->query($sql);
  3005. // Build the table heading
  3006. $r = $DSP->qdiv('tableHeading', $LANG->line('member_search_results'));
  3007. // "select all" checkbox
  3008. $r .= $DSP->toggle();
  3009. $DSP->right_crumb($LANG->line('new_member_search'), BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=member_search');
  3010. $DSP->body_props .= ' onload="magic_check()" ';
  3011. $r .= $DSP->magic_checkboxes();
  3012. // Declare the "delete" form
  3013. $r .= $DSP->form_open(
  3014. array(
  3015. 'action' => 'C=admin'.AMP.'M=members'.AMP.'P=mbr_del_conf',
  3016. 'name' => 'target',
  3017. 'id' => 'target'
  3018. )
  3019. );
  3020. $r .= $DSP->table('tableBorder', '0', '', '100%').
  3021. $DSP->tr().
  3022. $DSP->table_qcell('tableHeadingAlt', $LANG->line('username')).
  3023. $DSP->table_qcell('tableHeadingAlt', $LANG->line('screen_name')).
  3024. $DSP->table_qcell('tableHeadingAlt', $LANG->line('email')).
  3025. $DSP->table_qcell('tableHeadingAlt', $LANG->line('ip_address')).
  3026. $DSP->table_qcell('tableHeadingAlt', $LANG->line('join_date')).
  3027. $DSP->table_qcell('tableHeadingAlt', $LANG->line('member_group')).
  3028. $DSP->table_qcell('tableHeadingAlt', $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"")).
  3029. $DSP->tr_c();
  3030. // Loop through the query result and write each table row
  3031. $i = 0;
  3032. foreach($query->result as $row)
  3033. {
  3034. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3035. $r .= $DSP->tr();
  3036. // Username
  3037. $r .= $DSP->table_qcell($style,
  3038. $DSP->anchor(
  3039. BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'],
  3040. '<b>'.$row['username'].'</b>'
  3041. )
  3042. );
  3043. // Screen name
  3044. $screen = ($row['screen_name'] == '') ? "--" : $row['screen_name'];
  3045. $r .= $DSP->table_qcell($style, $screen);
  3046. // Email
  3047. $r .= $DSP->table_qcell($style,
  3048. $DSP->mailto($row['email'], $row['email'])
  3049. );
  3050. // IP Address
  3051. $r .= $DSP->td($style);
  3052. $r .= $row['ip_address'];
  3053. $r .= $DSP->td_c();
  3054. // Join date
  3055. $r .= $DSP->td($style).
  3056. $LOC->convert_timestamp('%Y', $row['join_date']).'-'.
  3057. $LOC->convert_timestamp('%m', $row['join_date']).'-'.
  3058. $LOC->convert_timestamp('%d', $row['join_date']).
  3059. $DSP->td_c();
  3060. // Member group
  3061. $r .= $DSP->td($style);
  3062. $r .= $row['group_title'];
  3063. $r .= $DSP->td_c();
  3064. // Delete checkbox
  3065. $r .= $DSP->table_qcell($style, $DSP->input_checkbox('toggle[]', $row['member_id'], '', " id='delete_box_".$row['member_id']."'"));
  3066. $r .= $DSP->tr_c();
  3067. } // End foreach
  3068. $r .= $DSP->table_c();
  3069. $r .= $DSP->table('', '0', '', '98%');
  3070. $r .= $DSP->tr().
  3071. $DSP->td();
  3072. // Pass the relevant data to the paginate class so it can display the "next page" links
  3073. $r .= $DSP->div('crumblinks').
  3074. $DSP->pager(
  3075. $pageurl,
  3076. $total_count,
  3077. $this->perpage,
  3078. $rownum,
  3079. 'rownum'
  3080. ).
  3081. $DSP->div_c().
  3082. $DSP->td_c().
  3083. $DSP->td('defaultRight');
  3084. // Delete button
  3085. $r .= $DSP->input_submit($LANG->line('delete')).
  3086. $DSP->td_c().
  3087. $DSP->tr_c();
  3088. // Table end
  3089. $r .= $DSP->table_c().
  3090. $DSP->form_close();
  3091. $DSP->title = $LANG->line('member_search');
  3092. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  3093. $DSP->crumb_item($LANG->line('member_search'));
  3094. $DSP->body = $r;
  3095. }
  3096. /* END */
  3097. /** -----------------------------
  3098. /** IP Search Form
  3099. /** -----------------------------*/
  3100. function ip_search_form($message = '')
  3101. {
  3102. global $LANG, $DSP, $DB, $IN;
  3103. if ( ! $DSP->allowed_group('can_admin_members'))
  3104. {
  3105. return $DSP->no_access_message();
  3106. }
  3107. $ip = ($IN->GBL('ip_address') != FALSE) ? str_replace('_', '.',$IN->GBL('ip_address')) : '';
  3108. $DSP->body = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=do_ip_search'));
  3109. $DSP->body .= $DSP->qdiv('tableHeading', $LANG->line('ip_search'));
  3110. if ($message != '')
  3111. $DSP->body .= $DSP->qdiv('box', $message);
  3112. $DSP->body .= $DSP->div('box');
  3113. if ($IN->GBL('error') == 2)
  3114. {
  3115. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('ip_search_no_results')));
  3116. }
  3117. elseif ($IN->GBL('error') == 1)
  3118. {
  3119. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('ip_search_too_short')));
  3120. }
  3121. $DSP->body .= $DSP->qdiv('itemWrapper', $LANG->line('ip_search_instructions'));
  3122. $DSP->body .= $DSP->itemgroup(
  3123. $LANG->line('ip_address', 'ip_address'),
  3124. $DSP->input_text('ip_address', $ip, '35', '100', 'input', '300px')
  3125. );
  3126. $DSP->body .= $DSP->div_c();
  3127. $DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  3128. $DSP->body .= $DSP->form_close();
  3129. $DSP->title = $LANG->line('member_search');
  3130. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  3131. $DSP->crumb_item($LANG->line('member_search'));
  3132. }
  3133. /* END */
  3134. /** -----------------------------
  3135. /** IP Search
  3136. /** -----------------------------*/
  3137. function do_ip_search($message = '')
  3138. {
  3139. global $IN, $FNS, $LANG, $DSP, $DB, $LOC, $PREFS;
  3140. if ( ! $DSP->allowed_group('can_admin_members'))
  3141. {
  3142. return $DSP->no_access_message();
  3143. }
  3144. $ip = str_replace('_', '.', $IN->GBL('ip_address'));
  3145. $url_ip = str_replace('.', '_', $ip);
  3146. if ($ip == '')
  3147. {
  3148. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=ip_search');
  3149. exit;
  3150. }
  3151. if (strlen($ip) < 3)
  3152. {
  3153. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=ip_search'.AMP.'error=1'.AMP.'ip_address='.$url_ip);
  3154. exit;
  3155. }
  3156. /** -----------------------------
  3157. /** Set some defaults for pagination
  3158. /** -----------------------------*/
  3159. $w_page = ($IN->GBL('w_page') == FALSE) ? 0 : $IN->GBL('w_page');
  3160. $m_page = ($IN->GBL('m_page') == FALSE) ? 0 : $IN->GBL('m_page');
  3161. $c_page = ($IN->GBL('c_page') == FALSE) ? 0 : $IN->GBL('c_page');
  3162. $g_page = ($IN->GBL('g_page') == FALSE) ? 0 : $IN->GBL('g_page');
  3163. $t_page = ($IN->GBL('t_page') == FALSE) ? 0 : $IN->GBL('t_page');
  3164. $p_page = ($IN->GBL('p_page') == FALSE) ? 0 : $IN->GBL('p_page');
  3165. $page_url = BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=do_ip_search'.AMP.'ip_address='.$url_ip;
  3166. $r = '';
  3167. /** -----------------------------
  3168. /** Find Member Accounts with IP
  3169. /** -----------------------------*/
  3170. $sql_a = "SELECT COUNT(*) AS count ";
  3171. $sql_b = "SELECT member_id, username, screen_name, ip_address, email, join_date ";
  3172. $sql = "FROM exp_members
  3173. WHERE ip_address LIKE '%".$DB->escape_like_str($ip)."%'
  3174. ORDER BY screen_name desc ";
  3175. // Run the query the first time to get total for pagination
  3176. $query = $DB->query($sql_a.$sql);
  3177. $total = $query->row['count'];
  3178. if ($total > 0)
  3179. {
  3180. if ($total > 10)
  3181. {
  3182. $sql .= " LIMIT ".$m_page.", 10";
  3183. }
  3184. // Run the full query
  3185. $query = $DB->query($sql_b.$sql);
  3186. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  3187. $r .= $DSP->table_row(array(array('text' => $LANG->line('member_accounts'),'class' => 'tableHeading', 'colspan' => '4' )));
  3188. $r .= $DSP->table_row(array(
  3189. array('text' => $LANG->line('username'), 'class' => 'tableHeadingAlt', 'width' => '50%'),
  3190. array('text' => $LANG->line('screen_name'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3191. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3192. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3193. )
  3194. );
  3195. $i = 0;
  3196. foreach($query->result as $row)
  3197. {
  3198. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3199. $r .= $DSP->table_row(array(
  3200. array('text' => $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'], '<b>'.$row['username'].'</b>'), 'class' => $class),
  3201. array('text' => ($row['screen_name'] == '') ? "--" : $row['screen_name'], 'class' => $class),
  3202. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3203. array('text' => $row['ip_address'], 'class' => $class)
  3204. )
  3205. );
  3206. } // End foreach
  3207. $r .= $DSP->table_close();
  3208. if ($total > 10)
  3209. {
  3210. $r .= $DSP->div('crumblinks').
  3211. $DSP->pager(
  3212. $page_url.AMP.'w_page='.$w_page.AMP.'c_page='.$c_page.AMP.'g_page='.$g_page.AMP.'t_page='.$t_page.AMP.'p_page='.$p_page,
  3213. $total,
  3214. 10,
  3215. $m_page,
  3216. 'm_page'
  3217. ).
  3218. $DSP->div_c();
  3219. }
  3220. }
  3221. /** -----------------------------
  3222. /** Find Weblog Entries with IP
  3223. /** -----------------------------*/
  3224. $sql_a = "SELECT COUNT(*) AS count ";
  3225. $sql_b = "SELECT s.site_label, t.entry_id, t.weblog_id, t.title, t.ip_address, m.member_id, m.username, m.screen_name, m.email ";
  3226. $sql = "FROM exp_weblog_titles t, exp_members m, exp_sites s
  3227. WHERE t.ip_address LIKE '%".$DB->escape_like_str($ip)."%'
  3228. AND t.site_id = s.site_id
  3229. AND t.author_id = m.member_id
  3230. ORDER BY entry_id desc ";
  3231. // Run the query the first time to get total for pagination
  3232. $query = $DB->query($sql_a.$sql);
  3233. $total = $query->row['count'];
  3234. if ($total > 0)
  3235. {
  3236. if ($total > 10)
  3237. {
  3238. $sql .= " LIMIT ".$w_page.", 10";
  3239. }
  3240. // Run the full query
  3241. $query = $DB->query($sql_b.$sql);
  3242. $r .= $DSP->qdiv('defaultSmall', BR);
  3243. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  3244. $r .= $DSP->table_row(array(array('text' => $LANG->line('weblog_entries'),'class' => 'tableHeading', 'colspan' => ($PREFS->ini('multiple_sites_enabled') !== 'y') ? '4' : '5' )));
  3245. if ($PREFS->ini('multiple_sites_enabled') !== 'y')
  3246. {
  3247. $r .= $DSP->table_row(array(
  3248. array('text' => $LANG->line('title'), 'class' => 'tableHeadingAlt', 'width' => '50%'),
  3249. array('text' => $LANG->line('screen_name'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3250. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3251. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3252. )
  3253. );
  3254. }
  3255. else
  3256. {
  3257. $r .= $DSP->table_row(array(
  3258. array('text' => $LANG->line('title'), 'class' => 'tableHeadingAlt', 'width' => '40%'),
  3259. array('text' => $LANG->line('site'), 'class' => 'tableHeadingAlt', 'width' => '15%'),
  3260. array('text' => $LANG->line('screen_name'), 'class' => 'tableHeadingAlt', 'width' => '15%'),
  3261. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3262. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3263. )
  3264. );
  3265. }
  3266. $i = 0;
  3267. foreach($query->result as $row)
  3268. {
  3269. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3270. if ($PREFS->ini('multiple_sites_enabled') !== 'y')
  3271. {
  3272. $r .= $DSP->table_row(array(
  3273. array('text' => $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_entry'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'], '<b>'.$row['title'].'</b>'), 'class' => $class),
  3274. array('text' => $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'], '<b>'.$row['screen_name'].'</b>'), 'class' => $class),
  3275. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3276. array('text' => $row['ip_address'], 'class' => $class)
  3277. )
  3278. );
  3279. }
  3280. else
  3281. {
  3282. $r .= $DSP->table_row(array(
  3283. array('text' => $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=view_entry'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'], '<b>'.$row['title'].'</b>'), 'class' => $class),
  3284. array('text' => $row['site_label'], 'class' => $class),
  3285. array('text' => $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'], '<b>'.$row['screen_name'].'</b>'), 'class' => $class),
  3286. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3287. array('text' => $row['ip_address'], 'class' => $class)
  3288. )
  3289. );
  3290. }
  3291. } // End foreach
  3292. $r .= $DSP->table_close();
  3293. if ($total > 10)
  3294. {
  3295. $r .= $DSP->div('crumblinks').
  3296. $DSP->pager(
  3297. $page_url.AMP.'m_page='.$m_page.AMP.'c_page='.$c_page.AMP.'g_page='.$g_page.AMP.'t_page='.$t_page.AMP.'p_page='.$p_page,
  3298. $total,
  3299. 10,
  3300. $w_page,
  3301. 'w_page'
  3302. ).
  3303. $DSP->div_c();
  3304. }
  3305. }
  3306. /** -----------------------------
  3307. /** Find Comments with IP
  3308. /** -----------------------------*/
  3309. // But only if the comment module is installed
  3310. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Comment'");
  3311. if ($query->row['count'] == 1)
  3312. {
  3313. $sql_a = "SELECT COUNT(*) AS count ";
  3314. $sql_b = "SELECT comment_id, entry_id, weblog_id, author_id, comment, name, email, ip_address ";
  3315. $sql = "FROM exp_comments
  3316. WHERE ip_address LIKE '%".$DB->escape_like_str($ip)."%'
  3317. ORDER BY comment_id desc ";
  3318. // Run the query the first time to get total for pagination
  3319. $query = $DB->query($sql_a.$sql);
  3320. $total = $query->row['count'];
  3321. if ($total > 0)
  3322. {
  3323. if ($total > 10)
  3324. {
  3325. $sql .= " LIMIT ".$c_page.", 10";
  3326. }
  3327. // Run the full query
  3328. $query = $DB->query($sql_b.$sql);
  3329. $r .= $DSP->qdiv('defaultSmall', BR);
  3330. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  3331. $r .= $DSP->table_row(array(array('text' => $LANG->line('comments'),'class' => 'tableHeading', 'colspan' => '4' )));
  3332. $r .= $DSP->table_row(array(
  3333. array('text' => $LANG->line('comment'), 'class' => 'tableHeadingAlt', 'width' => '50%'),
  3334. array('text' => $LANG->line('author'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3335. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3336. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3337. )
  3338. );
  3339. $i = 0;
  3340. foreach($query->result as $row)
  3341. {
  3342. if ($row['author_id'] != 0)
  3343. {
  3344. $author = $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['author_id'], '<b>'.$row['name'].'</b>');
  3345. }
  3346. else
  3347. {
  3348. $author = '<b>'.$row['name'].'</b>';
  3349. }
  3350. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3351. $r .= $DSP->table_row(array(
  3352. array('text' => $DSP->anchor(BASE.AMP.'C=edit'.AMP.'M=edit_comment'.AMP.'weblog_id='.$row['weblog_id'].AMP.'entry_id='.$row['entry_id'].AMP.'comment_id='.$row['comment_id'].AMP.'current_page=0', '<b>'.substr(strip_tags($row['comment']), 0, 45).'...</b>'), 'class' => $class),
  3353. array('text' => $author, 'class' => $class),
  3354. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3355. array('text' => $row['ip_address'], 'class' => $class)
  3356. )
  3357. );
  3358. } // End foreach
  3359. $r .= $DSP->table_close();
  3360. if ($total > 10)
  3361. {
  3362. $r .= $DSP->div('crumblinks').
  3363. $DSP->pager(
  3364. $page_url.AMP.'m_page='.$m_page.AMP.'w_page='.$w_page.AMP.'g_page='.$g_page.AMP.'t_page='.$t_page.AMP.'p_page='.$p_page,
  3365. $total,
  3366. 10,
  3367. $c_page,
  3368. 'c_page'
  3369. ).
  3370. $DSP->div_c();
  3371. }
  3372. }
  3373. }
  3374. /** -----------------------------
  3375. /** Find Gallery Comments with IP
  3376. /** -----------------------------*/
  3377. // But only if the gallery module is installed
  3378. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Gallery'");
  3379. if ($query->row['count'] == 1)
  3380. {
  3381. $sql_a = "SELECT COUNT(*) AS count ";
  3382. $sql_b = "SELECT e.cat_id, c.gallery_id, c.comment_id, c.entry_id, c.author_id, c.comment, c.name, c.email, c.ip_address ";
  3383. $sql = "FROM exp_gallery_comments c, exp_gallery_entries e
  3384. WHERE ip_address LIKE '%".$DB->escape_like_str($ip)."%'
  3385. AND c.entry_id = e.entry_id
  3386. ORDER BY c.comment_id desc ";
  3387. // Run the query the first time to get total for pagination
  3388. $query = $DB->query($sql_a.$sql);
  3389. $total = $query->row['count'];
  3390. if ($total > 0)
  3391. {
  3392. if ($total > 10)
  3393. {
  3394. $sql .= " LIMIT ".$g_page.", 10";
  3395. }
  3396. // Run the full query
  3397. $query = $DB->query($sql_b.$sql);
  3398. $r .= $DSP->qdiv('defaultSmall', BR);
  3399. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  3400. $r .= $DSP->table_row(array(array('text' => $LANG->line('gallery_comments'),'class' => 'tableHeading', 'colspan' => '4' )));
  3401. $r .= $DSP->table_row(array(
  3402. array('text' => $LANG->line('comment'), 'class' => 'tableHeadingAlt', 'width' => '50%'),
  3403. array('text' => $LANG->line('author'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3404. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3405. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3406. )
  3407. );
  3408. $i = 0;
  3409. foreach($query->result as $row)
  3410. {
  3411. if ($row['author_id'] != 0)
  3412. {
  3413. $author = $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['author_id'], '<b>'.$row['name'].'</b>');
  3414. }
  3415. else
  3416. {
  3417. $author = '<b>'.$row['name'].'</b>';
  3418. }
  3419. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3420. $r .= $DSP->table_row(array(
  3421. array('text' => $DSP->anchor(BASE.AMP.'C=modules'.AMP.'M=gallery'.AMP.'P=edit_comment'.AMP.'gallery_id='.$row['gallery_id'].AMP.'entry_id='.$row['entry_id'].AMP.'comment_id='.$row['comment_id'].AMP.'row='.AMP.'cat_id='.$row['cat_id'], '<b>'.substr($row['comment'], 0, 45).'...</b>'), 'class' => $class),
  3422. array('text' => $author, 'class' => $class),
  3423. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3424. array('text' => $row['ip_address'], 'class' => $class)
  3425. )
  3426. );
  3427. } // End foreach
  3428. $r .= $DSP->table_close();
  3429. if ($total > 10)
  3430. {
  3431. $r .= $DSP->div('crumblinks').
  3432. $DSP->pager(
  3433. $page_url.AMP.'m_page='.$m_page.AMP.'w_page='.$w_page.AMP.'c_page='.$c_page.AMP.'t_page='.$t_page.AMP.'p_page='.$p_page,
  3434. $total,
  3435. 10,
  3436. $g_page,
  3437. 'g_page'
  3438. ).
  3439. $DSP->div_c();
  3440. }
  3441. }
  3442. }
  3443. /** -----------------------------
  3444. /** Find Forum Topics with IP
  3445. /** -----------------------------*/
  3446. // But only if the forum module is installed
  3447. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Forum'");
  3448. if ($query->row['count'] == 1)
  3449. {
  3450. $sql_a = "SELECT COUNT(*) AS count ";
  3451. $sql_b = "SELECT f.topic_id, f.forum_id, f.title, f.ip_address, m.member_id, m.screen_name, m.email, b.board_forum_url ";
  3452. $sql = "FROM exp_forum_topics f, exp_members m, exp_forum_boards b
  3453. WHERE f.ip_address LIKE '%".$DB->escape_like_str($ip)."%'
  3454. AND f.board_id = b.board_id
  3455. AND f.author_id = m.member_id
  3456. ORDER BY f.topic_id desc ";
  3457. // Run the query the first time to get total for pagination
  3458. $query = $DB->query($sql_a.$sql);
  3459. $total = $query->row['count'];
  3460. if ($total > 0)
  3461. {
  3462. if ($total > 10)
  3463. {
  3464. $sql .= " LIMIT ".$t_page.", 10";
  3465. }
  3466. // Run the full query
  3467. $query = $DB->query($sql_b.$sql);
  3468. $r .= $DSP->qdiv('defaultSmall', BR);
  3469. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  3470. $r .= $DSP->table_row(array(array('text' => $LANG->line('forum_topics'),'class' => 'tableHeading', 'colspan' => '4' )));
  3471. $r .= $DSP->table_row(array(
  3472. array('text' => $LANG->line('topic'), 'class' => 'tableHeadingAlt', 'width' => '50%'),
  3473. array('text' => $LANG->line('author'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3474. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3475. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3476. )
  3477. );
  3478. $i = 0;
  3479. foreach($query->result as $row)
  3480. {
  3481. $row['title'] = str_replace(array('<', '>', '{', '}', '\'', '"', '?'), array('&lt;', '&gt;', '&#123;', '&#125;', '&#146;', '&quot;', '&#63;'), $row['title']);
  3482. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3483. $r .= $DSP->table_row(array(
  3484. array('text' => $DSP->anchor($FNS->remove_double_slashes($row['board_forum_url'].'/viewthread/').$row['topic_id'].'/', '<b>'.$row['title'].'</b>'), 'class' => $class),
  3485. array('text' => $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'], '<b>'.$row['screen_name'].'</b>'), 'class' => $class),
  3486. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3487. array('text' => $row['ip_address'], 'class' => $class)
  3488. )
  3489. );
  3490. } // End foreach
  3491. $r .= $DSP->table_close();
  3492. if ($total > 10)
  3493. {
  3494. $r .= $DSP->div('crumblinks').
  3495. $DSP->pager(
  3496. $page_url.AMP.'m_page='.$m_page.AMP.'w_page='.$w_page.AMP.'c_page='.$c_page.AMP.'g_page='.$g_page.AMP.'p_page='.$p_page,
  3497. $total,
  3498. 10,
  3499. $t_page,
  3500. 't_page'
  3501. ).
  3502. $DSP->div_c();
  3503. }
  3504. }
  3505. /** -----------------------------
  3506. /** Find Forum Posts with IP
  3507. /** -----------------------------*/
  3508. $sql_a = "SELECT COUNT(*) AS count ";
  3509. $sql_b = "SELECT p.post_id, p.forum_id, p.body, p.ip_address, m.member_id, m.screen_name, m.email, b.board_forum_url ";
  3510. $sql = "FROM exp_forum_posts p, exp_members m, exp_forum_boards b
  3511. WHERE p.ip_address LIKE '%".$DB->escape_like_str($ip)."%'
  3512. AND p.author_id = m.member_id
  3513. AND p.board_id = b.board_id
  3514. ORDER BY p.topic_id desc ";
  3515. // Run the query the first time to get total for pagination
  3516. $query = $DB->query($sql_a.$sql);
  3517. $total = $query->row['count'];
  3518. if ($total > 0)
  3519. {
  3520. if ($total > 10)
  3521. {
  3522. $sql .= " LIMIT ".$p_page.", 10";
  3523. }
  3524. // Run the full query
  3525. $query = $DB->query($sql_b.$sql);
  3526. $r .= $DSP->qdiv('defaultSmall', BR);
  3527. $r .= $DSP->table_open(array('class' => 'tableBorder', 'width' => '100%'));
  3528. $r .= $DSP->table_row(array(array('text' => $LANG->line('forum_posts'),'class' => 'tableHeading', 'colspan' => '4' )));
  3529. $r .= $DSP->table_row(array(
  3530. array('text' => $LANG->line('topic'), 'class' => 'tableHeadingAlt', 'width' => '50%'),
  3531. array('text' => $LANG->line('author'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3532. array('text' => $LANG->line('email'), 'class' => 'tableHeadingAlt', 'width' => '20%'),
  3533. array('text' => $LANG->line('ip_address'), 'class' => 'tableHeadingAlt', 'width' => '10%')
  3534. )
  3535. );
  3536. $i = 0;
  3537. foreach($query->result as $row)
  3538. {
  3539. $class = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  3540. $r .= $DSP->table_row(array(
  3541. array('text' => $DSP->anchor($FNS->remove_double_slashes($row['board_forum_url'].'/viewreply/').$row['post_id'].'/', '<b>'.substr($row['body'], 0, 45).'</b>'), 'class' => $class),
  3542. array('text' => $DSP->anchor(BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'], '<b>'.$row['screen_name'].'</b>'), 'class' => $class),
  3543. array('text' => $DSP->mailto($row['email'], $row['email']), 'class' => $class),
  3544. array('text' => $row['ip_address'], 'class' => $class)
  3545. )
  3546. );
  3547. } // End foreach
  3548. $r .= $DSP->table_close();
  3549. if ($total > 10)
  3550. {
  3551. $r .= $DSP->div('crumblinks').
  3552. $DSP->pager(
  3553. $page_url.AMP.'m_page='.$m_page.AMP.'w_page='.$w_page.AMP.'c_page='.$c_page.AMP.'g_page='.$g_page.AMP.'t_page='.$t_page,
  3554. $total,
  3555. 10,
  3556. $p_page,
  3557. 'p_page'
  3558. ).
  3559. $DSP->div_c();
  3560. }
  3561. }
  3562. }
  3563. /** -----------------------------
  3564. /** Were there results?
  3565. /** -----------------------------*/
  3566. if ($r == '')
  3567. {
  3568. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=ip_search'.AMP.'error=2'.AMP.'ip_address='.$url_ip);
  3569. exit;
  3570. }
  3571. $DSP->body = $r;
  3572. $DSP->title = $LANG->line('ip_search');
  3573. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  3574. $DSP->crumb_item($LANG->line('ip_search'));
  3575. }
  3576. /* END */
  3577. /** ---------------------------------
  3578. /** Member Validation
  3579. /** ---------------------------------*/
  3580. function member_validation()
  3581. {
  3582. global $DSP, $DB, $LANG, $LOC;
  3583. if ( ! $DSP->allowed_group('can_admin_members'))
  3584. {
  3585. return $DSP->no_access_message();
  3586. }
  3587. $title = $LANG->line('member_validation');
  3588. $DSP->title = $title;
  3589. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  3590. $DSP->crumb_item($title);
  3591. $DSP->body = $DSP->qdiv('tableHeading', $title);
  3592. $query = $DB->query("SELECT member_id, username, screen_name, email, join_date FROM exp_members WHERE group_id = '4' ORDER BY join_date");
  3593. if ($query->num_rows == 0)
  3594. {
  3595. $DSP->body .= $DSP->qdiv('box', $DSP->qdiv('highlight', $LANG->line('no_members_to_validate')));
  3596. return;
  3597. }
  3598. $DSP->body .= $DSP->toggle();
  3599. $DSP->body_props .= ' onload="magic_check()" ';
  3600. $DSP->body .= $DSP->magic_checkboxes();
  3601. $DSP->body .= $DSP->form_open(
  3602. array(
  3603. 'action' => 'C=admin'.AMP.'M=members'.AMP.'P=validate_members',
  3604. 'name' => 'target',
  3605. 'id' => 'target'
  3606. )
  3607. );
  3608. $DSP->body .= $DSP->table('tableBorder', '0', '0', '100%').
  3609. $DSP->tr().
  3610. $DSP->table_qcell('tableHeadingAlt',
  3611. array(
  3612. NBS,
  3613. $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\""),
  3614. $LANG->line('username'),
  3615. $LANG->line('screen_name'),
  3616. $LANG->line('email'),
  3617. $LANG->line('join_date')
  3618. )
  3619. ).
  3620. $DSP->tr_c();
  3621. $i = 0;
  3622. $n = 1;
  3623. foreach ($query->result as $row)
  3624. {
  3625. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  3626. $DSP->body .= $DSP->tr();
  3627. $DSP->body .= $DSP->table_qcell($style, $DSP->qspan('', $n++), '1%');
  3628. // Checkbox
  3629. $DSP->body .= $DSP->table_qcell($style, $DSP->input_checkbox('toggle[]', $row['member_id'], '', "id='delete_box_".$row['member_id']."'"), '3%');
  3630. // Username
  3631. $DSP->body .= $DSP->table_qcell($style,
  3632. $DSP->anchor(
  3633. BASE.AMP.'C=myaccount'.AMP.'id='.$row['member_id'],
  3634. '<b>'.$row['username'].'</b>',
  3635. '24%'
  3636. )
  3637. );
  3638. // Screen name
  3639. $screen = ($row['screen_name'] == '') ? "--" : '<b>'.$row['screen_name'].'</b>';
  3640. $DSP->body .= $DSP->table_qcell($style, $screen, '24%');
  3641. // Email
  3642. $DSP->body .= $DSP->table_qcell($style, $DSP->mailto($row['email']), '24%');
  3643. // Join Date
  3644. $DSP->body .= $DSP->table_qcell($style, $LOC->set_human_time($row['join_date']), '24%');
  3645. $DSP->body .= $DSP->tr_c();
  3646. }
  3647. $DSP->body .= $DSP->table_c();
  3648. $DSP->body .= $DSP->div('box');
  3649. $DSP->body .= $DSP->input_select_header('action');
  3650. $DSP->body .= $DSP->input_select_option('activate', $LANG->line('validate_selected'), 1);
  3651. $DSP->body .= $DSP->input_select_option('delete', $LANG->line('delete_selected'), '');
  3652. $DSP->body .= $DSP->input_select_footer();
  3653. $DSP->body.= $DSP->qdiv('itemWrapper', BR.$DSP->input_checkbox('send_notification', 'y', 1).NBS.$LANG->line('send_email_notification').BR);
  3654. $DSP->body .= $DSP->div_c();
  3655. $DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  3656. $DSP->body .= $DSP->form_close();
  3657. }
  3658. /* END */
  3659. /** ---------------------------------
  3660. /** Validate/Delete Selected Members
  3661. /** ---------------------------------*/
  3662. function validate_members()
  3663. {
  3664. global $IN, $DSP, $DB, $LANG, $PREFS, $REGX, $FNS, $EXT, $STAT;
  3665. if ( ! $DSP->allowed_group('can_admin_members'))
  3666. {
  3667. return $DSP->no_access_message();
  3668. }
  3669. if ( ! $DSP->allowed_group('can_delete_members'))
  3670. {
  3671. if ($_POST['action'] == 'delete')
  3672. {
  3673. return $DSP->no_access_message();
  3674. }
  3675. }
  3676. if ( ! $IN->GBL('toggle', 'POST'))
  3677. {
  3678. return $this->member_validation();
  3679. }
  3680. $send_email = (isset($_POST['send_notification'])) ? TRUE : FALSE;
  3681. if ($send_email == TRUE)
  3682. {
  3683. if ($_POST['action'] == 'activate')
  3684. {
  3685. $template = $FNS->fetch_email_template('validated_member_notify');
  3686. }
  3687. else
  3688. {
  3689. $template = $FNS->fetch_email_template('decline_member_validation');
  3690. }
  3691. require PATH_CORE.'core.email'.EXT;
  3692. $email = new EEmail;
  3693. $email->wordwrap = true;
  3694. }
  3695. $group_id = $PREFS->ini('default_member_group');
  3696. foreach ($_POST as $key => $val)
  3697. {
  3698. if (strstr($key, 'toggle') AND ! is_array($val))
  3699. {
  3700. if ($send_email == TRUE)
  3701. {
  3702. $query = $DB->query("SELECT username, screen_name, email FROM exp_members WHERE member_id = '$val'");
  3703. if ($query->num_rows == 1 AND $query->row['email'] != "")
  3704. {
  3705. $swap = array(
  3706. 'name' => ($query->row['screen_name'] != '') ? $query->row['screen_name'] : $query->row['username'],
  3707. 'site_name' => stripslashes($PREFS->ini('site_name')),
  3708. 'site_url' => $PREFS->ini('site_url')
  3709. );
  3710. $email_tit = $FNS->var_swap($template['title'], $swap);
  3711. $email_msg = $FNS->var_swap($template['data'], $swap);
  3712. $email->initialize();
  3713. $email->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));
  3714. $email->to($query->row['email']);
  3715. $email->subject($email_tit);
  3716. $email->message($REGX->entities_to_ascii($email_msg));
  3717. $email->Send();
  3718. }
  3719. }
  3720. if (isset($_POST['action']) && $_POST['action'] == 'activate')
  3721. {
  3722. $DB->query("UPDATE exp_members SET group_id = '$group_id' WHERE member_id = '".$DB->escape_str($val)."'");
  3723. }
  3724. else
  3725. {
  3726. $DB->query("DELETE FROM exp_members WHERE member_id = '$val'");
  3727. $DB->query("DELETE FROM exp_member_data WHERE member_id = '$val'");
  3728. $DB->query("DELETE FROM exp_member_homepage WHERE member_id = '$val'");
  3729. $message_query = $DB->query("SELECT DISTINCT recipient_id FROM exp_message_copies WHERE sender_id = '$val' AND message_read = 'n'");
  3730. $DB->query("DELETE FROM exp_message_copies WHERE sender_id = '$val'");
  3731. $DB->query("DELETE FROM exp_message_data WHERE sender_id = '$val'");
  3732. $DB->query("DELETE FROM exp_message_folders WHERE member_id = '$val'");
  3733. $DB->query("DELETE FROM exp_message_listed WHERE member_id = '$val'");
  3734. if ($message_query->num_rows > 0)
  3735. {
  3736. foreach($message_query->result as $row)
  3737. {
  3738. $count_query = $DB->query("SELECT COUNT(*) AS count FROM exp_message_copies WHERE recipient_id = '".$row['recipient_id']."' AND message_read = 'n'");
  3739. $DB->query($DB->update_string('exp_members', array('private_messages' => $count_query->row['count']), "member_id = '".$row['recipient_id']."'"));
  3740. }
  3741. }
  3742. }
  3743. }
  3744. }
  3745. $STAT->update_member_stats();
  3746. // -------------------------------------------
  3747. // 'cp_members_validate_members' hook.
  3748. // - Additional processing when member(s) are validated in the CP
  3749. // - Added 1.5.2, 2006-12-28
  3750. //
  3751. $edata = $EXT->call_extension('cp_members_validate_members');
  3752. if ($EXT->end_script === TRUE) return;
  3753. //
  3754. // -------------------------------------------
  3755. $title = $LANG->line('member_validation');
  3756. $DSP->title = $title;
  3757. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  3758. $DSP->crumb_item($title);
  3759. $DSP->body = $DSP->qdiv('tableHeading', $title);
  3760. $msg = ($_POST['action'] == 'activate') ? $LANG->line('members_are_validated') : $LANG->line('members_are_deleted');
  3761. $DSP->body .= $DSP->qdiv('box', $msg);
  3762. }
  3763. /* END */
  3764. /** ---------------------------------
  3765. /** View Email Console Logs
  3766. /** ---------------------------------*/
  3767. function email_console_logs($message = '')
  3768. {
  3769. global $IN, $DB, $LANG, $DSP, $LOC;
  3770. if ( ! $DSP->allowed_group('can_admin_members'))
  3771. {
  3772. return $DSP->no_access_message();
  3773. }
  3774. /** -----------------------------
  3775. /** Define base variables
  3776. /** -----------------------------*/
  3777. $i = 0;
  3778. $s1 = 'tableCellOne';
  3779. $s2 = 'tableCellTwo';
  3780. $row_limit = 100;
  3781. $paginate = '';
  3782. $row_count = 0;
  3783. $DSP->title = $LANG->line('email_console_log');
  3784. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  3785. $DSP->crumb_item($LANG->line('email_console_log'));
  3786. $DSP->body = $DSP->qdiv('tableHeading', $LANG->line('email_console_log'));
  3787. if ($message != '')
  3788. {
  3789. $DSP->body .= $DSP->qdiv('box', $DSP->qdiv('success', $message));
  3790. }
  3791. /** -----------------------------
  3792. /** Run Query
  3793. /** -----------------------------*/
  3794. $sql = "SELECT cache_id, member_id, member_name, recipient_name, cache_date, subject
  3795. FROM exp_email_console_cache
  3796. ORDER BY cache_id desc";
  3797. $query = $DB->query($sql);
  3798. if ($query->num_rows == 0)
  3799. {
  3800. if ($message == '')
  3801. $DSP->body .= $DSP->qdiv('box', $DSP->qdiv('highlight', $LANG->line('no_cached_email')));
  3802. return;
  3803. }
  3804. /** -----------------------------
  3805. /** Do we need pagination?
  3806. /** -----------------------------*/
  3807. if ($query->num_rows > $row_limit)
  3808. {
  3809. $row_count = ( ! $IN->GBL('row')) ? 0 : $IN->GBL('row');
  3810. $url = BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=email_console_logs';
  3811. $paginate = $DSP->pager( $url,
  3812. $query->num_rows,
  3813. $row_limit,
  3814. $row_count,
  3815. 'row'
  3816. );
  3817. $sql .= " LIMIT ".$row_count.", ".$row_limit;
  3818. $query = $DB->query($sql);
  3819. }
  3820. $DSP->body .= $DSP->toggle();
  3821. $DSP->body_props .= ' onload="magic_check()" ';
  3822. $DSP->body .= $DSP->magic_checkboxes();
  3823. $DSP->body .= $DSP->form_open(
  3824. array(
  3825. 'action' => 'C=admin'.AMP.'M=members'.AMP.'P=delete_email_console',
  3826. 'name' => 'target',
  3827. 'id' => 'target'
  3828. )
  3829. );
  3830. $DSP->body .= $DSP->table('tableBorder', '0', '0', '100%').
  3831. $DSP->tr().
  3832. $DSP->table_qcell('tableHeadingAlt',
  3833. array(
  3834. NBS,
  3835. $LANG->line('email_title'),
  3836. $LANG->line('from'),
  3837. $LANG->line('to'),
  3838. $LANG->line('date'),
  3839. $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").NBS.NBS
  3840. )
  3841. ).
  3842. $DSP->tr_c();
  3843. /** -----------------------------
  3844. /** Table Rows
  3845. /** -----------------------------*/
  3846. $row_count++;
  3847. foreach ($query->result as $row)
  3848. {
  3849. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  3850. array(
  3851. $row_count,
  3852. $DSP->anchorpop(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=view_email'.AMP.'id='.$row['cache_id'].AMP.'Z=1', '<b>'.$row['subject'].'</b>', '600', '580'),
  3853. $DSP->qspan('defaultBold', $row['member_name']),
  3854. $DSP->qspan('defaultBold', $row['recipient_name']),
  3855. $LOC->set_human_time($row['cache_date']),
  3856. $DSP->input_checkbox('toggle[]', $row['cache_id'], '', " id='delete_box_".$row['cache_id']."'")
  3857. )
  3858. );
  3859. $row_count++;
  3860. }
  3861. $DSP->body .= $DSP->table_c();
  3862. if ($paginate != '')
  3863. {
  3864. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $paginate));
  3865. }
  3866. $DSP->body .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('delete')));
  3867. $DSP->body .= $DSP->form_close();
  3868. }
  3869. /* END */
  3870. /** -----------------------------
  3871. /** View Email
  3872. /** -----------------------------*/
  3873. function view_email()
  3874. {
  3875. global $IN, $DB, $LANG, $DSP, $LOC;
  3876. if ( ! $DSP->allowed_group('can_admin_members'))
  3877. {
  3878. return $DSP->no_access_message();
  3879. }
  3880. $id = $IN->GBL('id');
  3881. /** -----------------------------
  3882. /** Run Query
  3883. /** -----------------------------*/
  3884. $query = $DB->query("SELECT subject, message, recipient, recipient_name, member_name, ip_address FROM exp_email_console_cache WHERE cache_id = '$id' ");
  3885. if ($query->num_rows == 0)
  3886. {
  3887. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('no_cached_email')));
  3888. return;
  3889. }
  3890. /** -----------------------------
  3891. /** Render output
  3892. /** -----------------------------*/
  3893. $DSP->body .= $DSP->heading(BR.$query->row['subject']);
  3894. /** ----------------------------------------
  3895. /** Instantiate Typography class
  3896. /** ----------------------------------------*/
  3897. if ( ! class_exists('Typography'))
  3898. {
  3899. require PATH_CORE.'core.typography'.EXT;
  3900. }
  3901. $TYPE = new Typography;
  3902. $DSP->body .= $TYPE->parse_type( $query->row['message'],
  3903. array(
  3904. 'text_format' => 'xhtml',
  3905. 'html_format' => 'all',
  3906. 'auto_links' => 'y',
  3907. 'allow_img_url' => 'y'
  3908. )
  3909. );
  3910. $DSP->body .= $DSP->qdiv('', BR);
  3911. $DSP->body .= $DSP->table('tableBorderNoBot', '0', '10', '100%');
  3912. $DSP->body .= $DSP->tr();
  3913. $DSP->body .= $DSP->table_qcell('tableCellTwo', $DSP->qspan('defaultBold', $LANG->line('from')));
  3914. $DSP->body .= $DSP->table_qcell('tableCellOne', $DSP->qspan('defaultBold', $query->row['member_name']));
  3915. $DSP->body .= $DSP->table_qcell('tableCellOne', $DSP->qspan('defaultBold', $query->row['ip_address']));
  3916. $DSP->body .= $DSP->tr_c();
  3917. $DSP->body .= $DSP->tr();
  3918. $DSP->body .= $DSP->table_qcell('tableCellTwo', $DSP->qspan('defaultBold', $LANG->line('to')));
  3919. $DSP->body .= $DSP->table_qcell('tableCellOne', $DSP->qspan('defaultBold', $query->row['recipient_name']));
  3920. $DSP->body .= $DSP->table_qcell('tableCellOne', $DSP->qspan('defaultBold', $DSP->mailto($query->row['recipient'])));
  3921. $DSP->body .= $DSP->tr_c();
  3922. $DSP->body .= $DSP->table_c();
  3923. }
  3924. /* END */
  3925. /** -------------------------------------------
  3926. /** Delete Emails
  3927. /** -------------------------------------------*/
  3928. function delete_email_console_messages()
  3929. {
  3930. global $IN, $DSP, $LANG, $DB;
  3931. if ( ! $DSP->allowed_group('can_admin_members'))
  3932. {
  3933. return $DSP->no_access_message();
  3934. }
  3935. if ( ! $IN->GBL('toggle', 'POST'))
  3936. {
  3937. return $this->email_console_logs();
  3938. }
  3939. $ids = array();
  3940. foreach ($_POST as $key => $val)
  3941. {
  3942. if (strstr($key, 'toggle') AND ! is_array($val))
  3943. {
  3944. $ids[] = "cache_id = '".$DB->escape_str($val)."'";
  3945. }
  3946. }
  3947. $IDS = implode(" OR ", $ids);
  3948. $DB->query("DELETE FROM exp_email_console_cache WHERE ".$IDS);
  3949. return $this->email_console_logs($LANG->line('email_deleted'));
  3950. }
  3951. /* END */
  3952. /** -----------------------------
  3953. /** Member Profile Templates
  3954. /** -----------------------------*/
  3955. // Template Overview
  3956. function profile_templates()
  3957. {
  3958. global $DSP, $IN, $PREFS, $LANG;
  3959. if ( ! $DSP->allowed_group('can_admin_mbr_templates'))
  3960. {
  3961. return $DSP->no_access_message();
  3962. }
  3963. $r = $DSP->table_open(array('class' => 'tableBorder', 'width' => '60%'));
  3964. $r .= $DSP->table_row(array(
  3965. array(
  3966. 'text' => $LANG->line('profile_templates'),
  3967. 'class' => 'tableHeading',
  3968. 'colspan' => 2
  3969. )
  3970. )
  3971. );
  3972. $themes = array();
  3973. if ($fp = @opendir(PATH_MBR_THEMES))
  3974. {
  3975. while (false !== ($file = readdir($fp)))
  3976. {
  3977. if (is_dir(PATH_MBR_THEMES.$file) AND $file != '.' AND $file != '..' AND $file != '.svn' AND $file != '.cvs')
  3978. {
  3979. $themes[] = $file;
  3980. }
  3981. }
  3982. closedir($fp);
  3983. }
  3984. if (count($themes) == 0)
  3985. {
  3986. $r .= $DSP->table_row(array(
  3987. array(
  3988. 'text' => $DSP->qdiv('defaultBold', $LANG->line('unable_to_find_templates')),
  3989. 'class' => 'tableCellTwo',
  3990. 'colspan' => 2
  3991. )
  3992. )
  3993. );
  3994. }
  3995. else
  3996. {
  3997. $i = 0;
  3998. foreach ($themes as $set)
  3999. {
  4000. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  4001. $template_name = ucfirst(str_replace("_", " ", $set));
  4002. $folder = '<img src="'.PATH_CP_IMG.'folder.gif" border="0" width="12" height="12" alt="'.$template_name.'" />';
  4003. $r .= $DSP->table_row(array(
  4004. array(
  4005. 'text' => $i.$DSP->nbs(2),
  4006. 'class' => $style,
  4007. 'width' => '2%'
  4008. ),
  4009. array(
  4010. 'text' => $folder.NBS.NBS.$DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=list_templates'.AMP.'name='.$set, $template_name),
  4011. 'class' => $style,
  4012. 'width' => '98%'
  4013. )
  4014. )
  4015. );
  4016. }
  4017. }
  4018. $r .= $DSP->table_close();
  4019. $DSP->title = $LANG->line('profile_templates');
  4020. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  4021. $DSP->crumb_item($LANG->line('profile_templates'));
  4022. $DSP->body = $r;
  4023. }
  4024. /* END */
  4025. /** -----------------------------
  4026. /** List Templates within a set
  4027. /** -----------------------------*/
  4028. function list_templates()
  4029. {
  4030. global $IN, $PREFS, $LANG, $DSP, $FNS;
  4031. if ( ! $DSP->allowed_group('can_admin_mbr_templates'))
  4032. {
  4033. return $DSP->no_access_message();
  4034. }
  4035. $path = PATH_MBR_THEMES.$FNS->filename_security($IN->GBL('name')).'/profile_theme'.EXT;
  4036. if ( ! file_exists($path))
  4037. {
  4038. return $DSP->no_access_message($LANG->line('unable_to_find_templates'));
  4039. }
  4040. if ( ! class_exists('profile_theme'))
  4041. {
  4042. require $path;
  4043. }
  4044. $template_name = ucfirst(str_replace("_", " ", $IN->GBL('name')));
  4045. $class_methods = get_class_methods('profile_theme');
  4046. $r = $DSP->table_open(array('class' => 'tableBorder', 'width' => '60%'));
  4047. $r .= $DSP->table_row(array(
  4048. array(
  4049. 'text' => $template_name,
  4050. 'class' => 'tableHeading'
  4051. )
  4052. )
  4053. );
  4054. $t_array = array();
  4055. foreach ($class_methods as $val)
  4056. {
  4057. $t_array[$val] = ($LANG->line($val) == FALSE) ? $val : $LANG->line($val);
  4058. }
  4059. asort($t_array);
  4060. $i = 0;
  4061. foreach ($t_array as $key => $val)
  4062. {
  4063. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  4064. $folder = '<img src="'.PATH_CP_IMG.'folder.gif" border="0" width="12" height="12" alt="'.$val.'" />';
  4065. $r .= $DSP->table_row(array(
  4066. array(
  4067. 'text' => $folder.NBS.NBS.$DSP->qspan('default', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=edit_template'.AMP.'name='.$IN->GBL('name').AMP.'function='.$key, $val)),
  4068. 'class' => $style
  4069. )
  4070. )
  4071. );
  4072. }
  4073. $r .= $DSP->div_c();
  4074. $r .= $DSP->td_c();
  4075. $r .= $DSP->tr_c();
  4076. $r .= $DSP->table_close();
  4077. $DSP->title = $template_name;
  4078. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  4079. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=profile_templates', $LANG->line('profile_templates'))).
  4080. $DSP->crumb_item($template_name);
  4081. $DSP->body = $r;
  4082. }
  4083. /* END */
  4084. /** -----------------------------
  4085. /** Edit Profile Template
  4086. /** -----------------------------*/
  4087. function edit_template($name = '', $function = '', $template_data = '')
  4088. {
  4089. global $IN, $DSP, $LANG, $SESS, $PREFS, $FNS;
  4090. if ( ! $DSP->allowed_group('can_admin_mbr_templates'))
  4091. {
  4092. return $DSP->no_access_message();
  4093. }
  4094. $update = ($function != '' AND $name != '') ? TRUE : FALSE;
  4095. if ($function == '')
  4096. {
  4097. $function = $IN->GBL('function');
  4098. }
  4099. if ($name == '')
  4100. {
  4101. $name = $IN->GBL('name');
  4102. }
  4103. $path = PATH_MBR_THEMES.$FNS->filename_security($name).'/profile_theme'.EXT;
  4104. if ( ! file_exists($path))
  4105. {
  4106. return $DSP->no_access_message($LANG->line('unable_to_find_template_file'));
  4107. }
  4108. if ( ! class_exists('profile_theme'))
  4109. {
  4110. require $path;
  4111. }
  4112. $MS = new profile_theme;
  4113. $line = ($LANG->line($function) == FALSE) ? $function : $LANG->line($function);
  4114. $r = $DSP->qdiv('tableHeading', $line);
  4115. if ($update)
  4116. {
  4117. $r .= $DSP->qdiv('success', $LANG->line('template_updated'));
  4118. }
  4119. $writable = TRUE;
  4120. if ( ! is_writable($path))
  4121. {
  4122. $writable = FALSE;
  4123. $r .= $DSP->div('box');
  4124. $r .= $DSP->qdiv('itemWrapper', $DSP->qspan('alert', $LANG->line('file_not_writable')));
  4125. $r .= $DSP->qdiv('itemWrapper', $LANG->line('file_writing_instructions'));
  4126. $r .= $DSP->qdiv('itemWrapper', $DSP->qspan('default', $path));
  4127. $r .= $DSP->div_c();
  4128. }
  4129. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=members'.AMP.'P=save_template'))
  4130. .$DSP->input_hidden('name', $name)
  4131. .$DSP->input_hidden('function', $function);
  4132. if ($update == FALSE)
  4133. {
  4134. $template_data = $MS->$function();
  4135. }
  4136. $r .= $DSP->div('itemWrapper')
  4137. .$DSP->input_textarea('template_data', stripslashes($template_data), $SESS->userdata['template_size'], 'textarea', '100%')
  4138. .$DSP->div_c();
  4139. if ($writable == TRUE)
  4140. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')));
  4141. $r .= $DSP->form_close();
  4142. $temp_name = ucfirst(str_replace("_", " ", $name));
  4143. $DSP->title = $LANG->line($function);
  4144. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=members_and_groups', $LANG->line('members_and_groups')).
  4145. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=profile_templates', $LANG->line('profile_templates'))).
  4146. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=list_templates'.AMP.'name='.$name, $temp_name)).
  4147. $DSP->crumb_item($LANG->line($function));
  4148. $DSP->body = $r;
  4149. }
  4150. /* END */
  4151. /** -----------------------------
  4152. /** Save Template
  4153. /** -----------------------------*/
  4154. function save_template()
  4155. {
  4156. global $IN, $DSP, $LANG, $SESS, $FNS, $PREFS;
  4157. if ( ! $DSP->allowed_group('can_admin_mbr_templates'))
  4158. {
  4159. return $DSP->no_access_message();
  4160. }
  4161. $function = $IN->GBL('function');
  4162. $name = $IN->GBL('name');
  4163. $template_data = $IN->GBL('template_data');
  4164. $path = PATH_MBR_THEMES.$FNS->filename_security($name).'/profile_theme'.EXT;
  4165. if ( ! file_exists($path))
  4166. {
  4167. return $DSP->no_access_message($LANG->line('unable_to_find_templates'));
  4168. }
  4169. if ( ! class_exists('profile_theme'))
  4170. {
  4171. require $path;
  4172. }
  4173. $MS = new profile_theme;
  4174. $class_methods = get_class_methods('profile_theme');
  4175. $methods = array();
  4176. foreach ($class_methods as $val)
  4177. {
  4178. if ($val == $function)
  4179. {
  4180. $methods[$val] = stripslashes($template_data);
  4181. }
  4182. else
  4183. {
  4184. $methods[$val] = stripslashes($MS->$val());
  4185. }
  4186. }
  4187. $str = "<?php\n\n";
  4188. $str .= '/*'."\n";
  4189. $str .= '====================================================='."\n";
  4190. $str .= ' ExpressionEngine - by EllisLab'."\n";
  4191. $str .= '-----------------------------------------------------'."\n";
  4192. $str .= ' http://expressionengine.com/'."\n";
  4193. $str .= '-----------------------------------------------------'."\n";
  4194. $str .= ' Copyright (c) 2003 - 2010 EllisLab, Inc.'."\n";
  4195. $str .= '====================================================='."\n";
  4196. $str .= ' THIS IS COPYRIGHTED SOFTWARE'."\n";
  4197. $str .= ' PLEASE READ THE LICENSE AGREEMENT'."\n";
  4198. $str .= ' http://expressionengine.com/docs/license.html'."\n";
  4199. $str .= '====================================================='."\n";
  4200. $str .= ' File: ';
  4201. $str .= $name.EXT."\n";
  4202. $str .= '-----------------------------------------------------'."\n";
  4203. $str .= ' Purpose: Member Profile Skin Elements'."\n";
  4204. $str .= '====================================================='."\n";
  4205. $str .= '*/'."\n\n";
  4206. $str .= "if ( ! defined('EXT')){\n\texit('Invalid file request');\n}\n\n";
  4207. $str .= "class profile_theme {\n\n";
  4208. foreach ($methods as $key => $val)
  4209. {
  4210. $str .= '//-------------------------------------'."\n";
  4211. $str .= '// '.$LANG->line($key)."\n";
  4212. $str .= '//-------------------------------------'."\n\n";
  4213. $str .= 'function '.$key.'()'."\n{\nreturn <<< EOF\n";
  4214. $str .= str_replace("\$", "\\$", $val);
  4215. $str .= "\nEOF;\n}\n// END\n\n\n\n\n";
  4216. }
  4217. $str .= "}\n";
  4218. $str .= '// END CLASS'."\n";
  4219. $str .= '?'.'>';
  4220. if ( ! $fp = @fopen($path, 'wb'))
  4221. {
  4222. return $DSP->no_access_message($LANG->line('error_opening_template'));
  4223. }
  4224. flock($fp, LOCK_EX);
  4225. fwrite($fp, $str);
  4226. flock($fp, LOCK_UN);
  4227. fclose($fp);
  4228. // Clear cache files
  4229. $FNS->clear_caching('all');
  4230. $this->edit_template($name, $function, $template_data);
  4231. }
  4232. /* END */
  4233. }/* END */
  4234. ?>