PageRenderTime 89ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/system/expressionengine/controllers/cp/admin_content.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 5283 lines | 3493 code | 1083 blank | 707 comment | 503 complexity | 201607107bf2c54da47ee90b7cc3fdb1 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine CP Home Page Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Control Panel
  19. * @category Control Panel
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Admin_content extends CI_Controller {
  24. var $reserved = array(
  25. 'random', 'date', 'title', 'url_title', 'edit_date',
  26. 'comment_total', 'username', 'screen_name',
  27. 'most_recent_comment', 'expiration_date');
  28. // Category arrays
  29. var $categories = array();
  30. var $cat_update = array();
  31. var $temp;
  32. /**
  33. * Constructor
  34. */
  35. function __construct()
  36. {
  37. parent::__construct();
  38. $this->lang->loadfile('admin');
  39. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content', lang('admin_content'));
  40. // Note- no access check here to allow the publish page access to categories
  41. }
  42. // --------------------------------------------------------------------
  43. /**
  44. * Index function
  45. *
  46. * @access public
  47. * @return void
  48. */
  49. function index()
  50. {
  51. if ( ! $this->cp->allowed_group('can_access_admin', 'can_access_content_prefs'))
  52. {
  53. show_error(lang('unauthorized_access'));
  54. }
  55. $this->cp->set_variable('cp_page_title', lang('admin'));
  56. $this->javascript->compile();
  57. $this->cp->set_variable('cp_page_title', lang('admin_content'));
  58. $this->load->vars(array('controller'=>'admin'));
  59. $this->load->view('_shared/overview');
  60. }
  61. // --------------------------------------------------------------------
  62. /**
  63. * Channel Overview
  64. *
  65. * Displays the Channel Management page
  66. *
  67. * @access public
  68. * @return void
  69. */
  70. function channel_management()
  71. {
  72. $this->_restrict_prefs_access();
  73. $this->cp->set_right_nav(array('create_new_channel' => BASE.AMP.'C=admin_content'.AMP.'M=channel_add'));
  74. $this->load->library('table');
  75. $this->lang->loadfile('admin_content');
  76. $this->load->model('channel_model');
  77. $this->cp->set_variable('cp_page_title', lang('channels'));
  78. $this->jquery->tablesorter('.mainTable', '{
  79. headers: {2: {sorter: false}, 3: {sorter: false}, 4: {sorter: false}},
  80. widgets: ["zebra"]
  81. }');
  82. $this->javascript->compile();
  83. $vars['channel_data'] = $this->channel_model->get_channels();
  84. $this->load->view('admin/channel_management', $vars);
  85. }
  86. // --------------------------------------------------------------------
  87. /**
  88. * Add Channel
  89. *
  90. * Displays the Channel Preferences form
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function channel_add()
  96. {
  97. $this->_restrict_prefs_access();
  98. $this->_channel_validation_rules();
  99. if ($this->form_validation->run() !== FALSE)
  100. {
  101. return $this->channel_update();
  102. }
  103. $this->lang->loadfile('admin_content');
  104. $this->load->helper('snippets');
  105. $this->load->model('channel_model');
  106. $this->load->model('category_model');
  107. $this->cp->add_js_script('plugin', 'ee_url_title');
  108. $this->javascript->output('
  109. $("#edit_group_prefs").hide();
  110. $("#channel_title").bind("keyup keydown", function() {
  111. $(this).ee_url_title("#channel_name");
  112. });
  113. ');
  114. $this->javascript->click("#edit_group_prefs_y", '$("#edit_group_prefs").show();', FALSE);
  115. $this->javascript->click("#edit_group_prefs_n", '$("#edit_group_prefs").hide();', FALSE);
  116. $this->cp->set_variable('cp_page_title', lang('create_new_channel'));
  117. $channels = $this->channel_model->get_channels($this->config->item('site_id'), array('channel_id', 'channel_title'));
  118. $vars['duplicate_channel_prefs_options'][''] = lang('do_not_duplicate');
  119. if ($channels != FALSE && $channels->num_rows() > 0)
  120. {
  121. foreach($channels->result() as $channel)
  122. {
  123. $vars['duplicate_channel_prefs_options'][$channel->channel_id] = $channel->channel_title;
  124. }
  125. }
  126. $vars['cat_group_options'][''] = lang('none');
  127. $groups = $this->category_model->get_categories('', $this->config->item('site_id'));
  128. if ($groups->num_rows() > 0)
  129. {
  130. foreach ($groups->result() as $group)
  131. {
  132. $vars['cat_group_options'][$group->group_id] = $group->group_name;
  133. }
  134. }
  135. $vars['status_group_options'][''] = lang('none');
  136. $this->db->select('group_id, group_name');
  137. $this->db->where('site_id', $this->config->item('site_id'));
  138. $this->db->order_by('group_name');
  139. $groups = $this->db->get('status_groups');
  140. if ($groups->num_rows() > 0)
  141. {
  142. foreach ($groups->result() as $group)
  143. {
  144. $vars['status_group_options'][$group->group_id] = $group->group_name;
  145. }
  146. }
  147. $vars['field_group_options'][''] = lang('none');
  148. $this->db->select('group_id, group_name');
  149. $this->db->where('site_id', $this->config->item('site_id'));
  150. $this->db->order_by('group_name');
  151. $groups = $this->db->get('field_groups');
  152. if ($groups->num_rows() > 0)
  153. {
  154. foreach ($groups->result() as $group)
  155. {
  156. $vars['field_group_options'][$group->group_id] = $group->group_name;
  157. }
  158. }
  159. // New themes may contain more than one group, thus naming collisions will happen
  160. // unless this is revamped.
  161. $vars['themes'] = array();
  162. $this->db->select('group_id, group_name, s.site_label');
  163. $this->db->from('template_groups tg, sites s');
  164. $this->db->where('tg.site_id = s.site_id', NULL, FALSE);
  165. if ($this->config->item('multiple_sites_enabled') !== 'y')
  166. {
  167. $this->db->where('tg.site_id', '1');
  168. }
  169. $this->db->order_by('tg.group_name');
  170. $query = $this->db->get();
  171. $vars['old_group_id'] = array();
  172. foreach ($query->result_array() as $row)
  173. {
  174. $vars['old_group_id'][$row['group_id']] = ($this->config->item('multiple_sites_enabled') == 'y') ? $row['site_label'].NBS.'-'.NBS.$row['group_name'] : $row['group_name'];
  175. }
  176. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  177. $this->javascript->compile();
  178. $this->load->view('admin/channel_add', $vars);
  179. }
  180. // --------------------------------------------------------------------
  181. /**
  182. * Edit Channel
  183. *
  184. * Displays the Channel Preferences form
  185. *
  186. * @access public
  187. * @return void
  188. */
  189. function channel_edit()
  190. {
  191. $this->_restrict_prefs_access();
  192. // Get modules that are installed
  193. $this->cp->get_installed_modules();
  194. $this->lang->loadfile('admin_content');
  195. $this->load->library('table');
  196. $this->load->helper('snippets');
  197. $this->load->model('channel_model');
  198. $this->load->model('template_model');
  199. $this->load->model('status_model');
  200. $this->load->model('field_model');
  201. $this->load->model('admin_model');
  202. $channel_id = $this->input->get_post('channel_id');
  203. // If we don't have the $channel_id variable, bail out.
  204. if ($channel_id == '' OR ! is_numeric($channel_id))
  205. {
  206. show_error(lang('not_authorized'));
  207. }
  208. $this->_channel_validation_rules();
  209. $this->form_validation->set_old_value('channel_id', $channel_id);
  210. if ($this->form_validation->run() !== FALSE)
  211. {
  212. $this->form_validation->set_old_value('channel_id', $channel_id);
  213. return $this->channel_update();
  214. }
  215. $query = $this->channel_model->get_channel_info($channel_id);
  216. foreach ($query->row_array() as $key => $val)
  217. {
  218. $vars[$key] = $val;
  219. }
  220. $vars['form_hidden']['channel_id'] = $channel_id;
  221. // live_look_template
  222. $query = $this->template_model->get_templates();
  223. $vars['live_look_template_options'][0] = lang('no_live_look_template');
  224. if ($query->num_rows() > 0)
  225. {
  226. foreach ($query->result() as $template)
  227. {
  228. $vars['live_look_template_options'][$template->template_id] = $template->group_name.'/'.$template->template_name;
  229. }
  230. }
  231. // Default status menu
  232. $query = $this->status_model->get_statuses($vars['status_group']);
  233. $vars['deft_status_options']['open'] = lang('open');
  234. $vars['deft_status_options']['closed'] = lang('closed');
  235. if ($query->num_rows() > 0)
  236. {
  237. foreach ($query->result() as $row)
  238. {
  239. $status_name = ($row->status == 'open' OR $row->status == 'closed') ? lang($row->status) : $row->status;
  240. $vars['deft_status_options'][$row->status] = $status_name;
  241. }
  242. }
  243. $vars['deft_category_options'][''] = lang('none');
  244. $cats = $vars['cat_group'] ? explode('|', $vars['cat_group']) : array();
  245. // Needz moar felineness!
  246. if (count($cats))
  247. {
  248. $this->db->select('CONCAT('.$this->db->dbprefix('category_groups').'.group_name, ": ", '.$this->db->dbprefix('categories').'.cat_name) as display_name', FALSE);
  249. $this->db->select('categories.cat_id, categories.cat_name, category_groups.group_name');
  250. $this->db->from('categories, '.$this->db->dbprefix('category_groups'));
  251. $this->db->where($this->db->dbprefix('category_groups').'.group_id = '.$this->db->dbprefix('categories').'.group_id', NULL, FALSE);
  252. $this->db->where_in('categories.group_id', $cats);
  253. $this->db->order_by('display_name');
  254. $query = $this->db->get();
  255. if ($query->num_rows() > 0)
  256. {
  257. foreach ($query->result() as $row)
  258. {
  259. $vars['deft_category_options'][$row->cat_id] = $row->display_name;
  260. }
  261. }
  262. }
  263. // Default field for search excerpt
  264. $this->db->select('field_id, field_label');
  265. $this->db->where('group_id', $vars['field_group']);
  266. $query = $this->db->get('channel_fields');
  267. $vars['search_excerpt_options'] = array();
  268. if ($query->num_rows() > 0)
  269. {
  270. foreach ($query->result() as $row)
  271. {
  272. $vars['search_excerpt_options'][$row->field_id] = $row->field_label;
  273. }
  274. }
  275. // HTML formatting
  276. $vars['channel_html_formatting_options'] = array(
  277. 'none' => lang('convert_to_entities'),
  278. 'safe' => lang('allow_safe_html'),
  279. 'all' => lang('allow_all_html')
  280. );
  281. if (isset($this->cp->installed_modules['comment']))
  282. {
  283. // Default comment text formatting
  284. $vars['comment_text_formatting_options'] = array(
  285. 'none' => lang('none'),
  286. 'xhtml' => lang('xhtml'),
  287. 'br' => lang('auto_br')
  288. );
  289. // Comment HTML formatting
  290. $vars['comment_html_formatting_options'] = array(
  291. 'none' => lang('convert_to_entities'),
  292. 'safe' => lang('allow_safe_html'),
  293. 'all' => lang('allow_all_html_not_recommended')
  294. );
  295. }
  296. $vars['languages'] = $this->admin_model->get_xml_encodings();
  297. $this->javascript->compile();
  298. $this->cp->set_variable('cp_page_title', lang('channel_prefs').': '.$vars['channel_title']);
  299. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  300. $this->load->view('admin/channel_edit', $vars);
  301. }
  302. // --------------------------------------------------------------------
  303. /**
  304. * Channel preference submission validation
  305. *
  306. * Sets the channel validation rules
  307. *
  308. * @access public
  309. * @return void
  310. */
  311. function _channel_validation_rules()
  312. {
  313. $this->load->library('form_validation');
  314. $this->form_validation->set_rules('channel_title', 'lang:channel_title', 'required');
  315. $this->form_validation->set_rules('channel_name', 'lang:channel_name', 'required|callback__valid_channel_name');
  316. $this->form_validation->set_rules('url_title_prefix', 'lang:url_title_prefix', 'strtolower|strip_tags|callback__valid_prefix');
  317. $this->form_validation->set_rules('comment_expiration', 'lang:comment_expiration', 'numeric');
  318. $this->form_validation->set_error_delimiters('<p class="notice">', '</p>');
  319. }
  320. function _valid_prefix($str)
  321. {
  322. if ($str == '')
  323. {
  324. return TRUE;
  325. }
  326. $this->form_validation->set_message('_valid_prefix', lang('invalid_url_title_prefix'));
  327. return preg_match('/^[\w\-]+$/', $str) ? TRUE : FALSE;
  328. }
  329. function _valid_channel_name($str)
  330. {
  331. // Check short name characters
  332. if (preg_match('/[^a-z0-9\-\_]/i', $str))
  333. {
  334. $this->form_validation->set_message('_valid_channel_name', lang('invalid_short_name'));
  335. return FALSE;
  336. }
  337. // Check for duplicates
  338. $this->db->where('site_id', $this->config->item('site_id'));
  339. $this->db->where('channel_name', $str);
  340. if ($this->form_validation->old_value('channel_id'))
  341. {
  342. $this->db->where('channel_id != ', $this->form_validation->old_value('channel_id'));
  343. }
  344. if ($this->db->count_all_results('channels') > 0)
  345. {
  346. $this->form_validation->set_message('_valid_channel_name', lang('taken_channel_name'));
  347. return FALSE;
  348. }
  349. return TRUE;
  350. }
  351. // --------------------------------------------------------------------
  352. /**
  353. * Channel preference submission handler
  354. *
  355. * This function receives the submitted channel preferences
  356. * and stores them in the database.
  357. *
  358. * @access public
  359. * @return void
  360. */
  361. function channel_update()
  362. {
  363. $this->_restrict_prefs_access();
  364. $this->lang->loadfile('admin_content');
  365. unset($_POST['channel_prefs_submit']); // submit button
  366. // If the $channel_id variable is present we are editing an
  367. // existing channel, otherwise we are creating a new one
  368. $edit = (isset($_POST['channel_id'])) ? TRUE : FALSE;
  369. // Load the layout Library & update the layouts
  370. $this->load->library('layout');
  371. $add_rss = (isset($_POST['add_rss'])) ? TRUE : FALSE;
  372. unset($_POST['add_rss']);
  373. $return = ($this->input->get_post('return')) ? TRUE : FALSE;
  374. unset($_POST['return']);
  375. $edit_group_prefs = TRUE;
  376. if ($this->input->get_post('edit_group_prefs') !== 'y')
  377. {
  378. unset($_POST['cat_group']);
  379. unset($_POST['status_group']);
  380. unset($_POST['field_group']);
  381. $edit_group_prefs = FALSE;
  382. }
  383. unset($_POST['edit_group_prefs']);
  384. $dupe_id = $this->input->get_post('duplicate_channel_prefs');
  385. unset($_POST['duplicate_channel_prefs']);
  386. // Check for required fields
  387. $error = array();
  388. if (isset($_POST['comment_expiration']) && $_POST['comment_expiration'] == '')
  389. {
  390. $_POST['comment_expiration'] = 0;
  391. }
  392. // Template Error Trapping
  393. if ($edit == FALSE)
  394. {
  395. $create_templates = ($this->input->get_post('create_templates') == FALSE OR $this->input->get_post('create_templates') == 'no') ? 'no' : $this->input->get_post('create_templates');
  396. $old_group_id = $this->input->get_post('old_group_id');
  397. $group_name = $this->input->post('group_name');
  398. $template_theme = $this->security->sanitize_filename($this->input->get_post('template_theme'));
  399. unset($_POST['create_templates']);
  400. unset($_POST['old_group_id']);
  401. unset($_POST['group_name']);
  402. unset($_POST['template_theme']);
  403. if ($create_templates != 'no')
  404. {
  405. $this->lang->loadfile('design');
  406. if ( ! $this->cp->allowed_group('can_admin_templates'))
  407. {
  408. show_error(lang('unauthorized_access'));
  409. }
  410. if ( ! $group_name)
  411. {
  412. show_error(lang('group_required'));
  413. }
  414. if ( ! preg_match("#^[a-zA-Z0-9_\-/]+$#i", $group_name))
  415. {
  416. show_error(lang('illegal_characters'));
  417. }
  418. $reserved[] = 'act';
  419. if ($this->config->item("forum_is_installed") == 'y' AND $this->config->item("forum_trigger") != '')
  420. {
  421. $reserved[] = $this->config->item("forum_trigger");
  422. }
  423. if (in_array($group_name, $reserved))
  424. {
  425. show_error(lang('reserved_name'));
  426. }
  427. $this->db->where('site_id', $this->config->item('site_id'));
  428. $this->db->where('group_name', $group_name);
  429. $count = $this->db->count_all_results('template_groups');
  430. if ($count > 0)
  431. {
  432. show_error(lang('template_group_taken'));
  433. }
  434. }
  435. }
  436. if ($this->input->post('apply_comment_enabled_to_existing'))
  437. {
  438. if ($this->input->post('comment_system_enabled') == 'y')
  439. {
  440. $this->channel_model->update_comments_allowed($_POST['channel_id'], 'y');
  441. }
  442. elseif ($this->input->post('comment_system_enabled') == 'n')
  443. {
  444. $this->channel_model->update_comments_allowed($_POST['channel_id'], 'n');
  445. }
  446. }
  447. unset($_POST['apply_comment_enabled_to_existing']);
  448. if (isset($_POST['apply_expiration_to_existing']))
  449. {
  450. if ($this->input->post('comment_expiration') == 0)
  451. {
  452. $this->channel_model->update_comment_expiration($_POST['channel_id'], $_POST['comment_expiration'], TRUE);
  453. }
  454. else
  455. {
  456. $this->channel_model->update_comment_expiration($_POST['channel_id'], $_POST['comment_expiration'] * 86400);
  457. }
  458. }
  459. unset($_POST['apply_expiration_to_existing']);
  460. if (isset($_POST['cat_group']) && is_array($_POST['cat_group']))
  461. {
  462. foreach($_POST['cat_group'] as $key => $value)
  463. {
  464. unset($_POST['cat_group_'.$key]);
  465. }
  466. $_POST['cat_group'] = implode('|', $_POST['cat_group']);
  467. }
  468. // Create Channel
  469. // Construct the query based on whether we are updating or inserting
  470. if ($edit == FALSE)
  471. {
  472. unset($_POST['channel_id']);
  473. unset($_POST['clear_versioning_data']);
  474. $_POST['channel_url'] = $this->functions->fetch_site_index();
  475. $_POST['channel_lang'] = $this->config->item('xml_lang');
  476. // Assign field group if there is only one
  477. if ($dupe_id != '' && ( ! isset($_POST['field_group']) OR (isset($_POST['field_group']) && ! is_numeric($_POST['field_group']))))
  478. {
  479. $this->db->select('group_id');
  480. $this->db->where('site_id', $this->config->item('site_id'));
  481. $query = $this->db->get('field_groups');
  482. if ($query->num_rows() == 1)
  483. {
  484. $_POST['field_group'] = $query->row('group_id') ;
  485. }
  486. }
  487. // Insert data
  488. $_POST['site_id'] = $this->config->item('site_id');
  489. $_POST['status_group'] = ($this->input->post('status_group') !== FALSE &&
  490. $this->input->post('status_group') != '')
  491. ? $this->input->post('status_group') : NULL;
  492. $_POST['field_group'] = ($this->input->post('field_group') !== FALSE &&
  493. $this->input->post('field_group') != '')
  494. ? $this->input->post('field_group') : NULL;
  495. // duplicating preferences?
  496. if ($dupe_id !== FALSE AND is_numeric($dupe_id))
  497. {
  498. $this->db->where('channel_id', $dupe_id);
  499. $wquery = $this->db->get('channels');
  500. if ($wquery->num_rows() == 1)
  501. {
  502. $exceptions = array('channel_id', 'site_id', 'channel_name', 'channel_title', 'total_entries',
  503. 'total_comments', 'last_entry_date', 'last_comment_date');
  504. foreach($wquery->row_array() as $key => $val)
  505. {
  506. // don't duplicate fields that are unique to each channel
  507. if ( ! in_array($key, $exceptions))
  508. {
  509. switch ($key)
  510. {
  511. // category, field, and status fields should only be duped
  512. // if both channels are assigned to the same group of each
  513. case 'cat_group':
  514. // allow to implicitly set category group to "None"
  515. if ( ! isset($_POST[$key]))
  516. {
  517. $_POST[$key] = $val;
  518. }
  519. break;
  520. case 'status_group':
  521. case 'field_group':
  522. if ( ! isset($_POST[$key]))
  523. {
  524. $_POST[$key] = $val;
  525. }
  526. elseif ($_POST[$key] == '')
  527. {
  528. $_POST[$key] = NULL;
  529. }
  530. break;
  531. case 'deft_status':
  532. case 'deft_status':
  533. if ( ! isset($_POST['status_group']) OR $_POST['status_group'] == $wquery->row('status_group') )
  534. {
  535. $_POST[$key] = $val;
  536. }
  537. break;
  538. case 'search_excerpt':
  539. if ( ! isset($_POST['field_group']) OR $_POST['field_group'] == $wquery->row('field_group') )
  540. {
  541. $_POST[$key] = $val;
  542. }
  543. break;
  544. case 'deft_category':
  545. if ( ! isset($_POST['cat_group']) OR count(array_diff(explode('|', $_POST['cat_group']), explode('|', $wquery->row('cat_group') ))) == 0)
  546. {
  547. $_POST[$key] = $val;
  548. }
  549. break;
  550. case 'blog_url':
  551. case 'comment_url':
  552. case 'search_results_url':
  553. case 'ping_return_url':
  554. case 'rss_url':
  555. if ($create_templates != 'no')
  556. {
  557. if ( ! isset($old_group_name))
  558. {
  559. $this->db->select('group_name');
  560. $this->db->where('group_id', $old_group_id);
  561. $gquery = $this->db->get('template_groups');
  562. $old_group_name = $gquery->row('group_name');
  563. }
  564. $_POST[$key] = str_replace("/{$old_group_name}/", "/{$group_name}/", $val);
  565. }
  566. else
  567. {
  568. $_POST[$key] = $val;
  569. }
  570. break;
  571. default :
  572. $_POST[$key] = $val;
  573. break;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. $_POST['default_entry_title'] = ( ! isset( $_POST['default_entry_title'])) ? '' : $_POST['default_entry_title'];
  580. $_POST['url_title_prefix'] = ( ! isset( $_POST['url_title_prefix'])) ? '' : $_POST['url_title_prefix'];
  581. $this->db->insert('channels', $_POST);
  582. $insert_id = $this->db->insert_id();
  583. $channel_id = $insert_id;
  584. // If they made the channel? Give access to that channel to the member group?
  585. if ($dupe_id !== FALSE AND is_numeric($dupe_id) && $edit_group_prefs == FALSE)
  586. {
  587. // Duplicate layouts
  588. $this->layout->duplicate_layout($dupe_id, $channel_id);
  589. }
  590. // If member group has ability to create the channel, they should be
  591. // able to access it as well
  592. if ($this->session->userdata('group_id') != 1)
  593. {
  594. $data = array(
  595. 'group_id' => $this->session->userdata('group_id'),
  596. 'channel_id' => $channel_id
  597. );
  598. $this->db->insert('channel_member_groups', $data);
  599. }
  600. $success_msg = lang('channel_created');
  601. $this->logger->log_action($success_msg.NBS.NBS.$_POST['channel_title']);
  602. }
  603. else
  604. {
  605. if (isset($_POST['clear_versioning_data']))
  606. {
  607. $this->db->delete('entry_versioning', array('channel_id' => $_POST['channel_id']));
  608. unset($_POST['clear_versioning_data']);
  609. }
  610. // Only one possible is revisions- enabled or disabled.
  611. // We treat as installed/not and delete the whole tab.
  612. $this->layout->sync_layout($_POST, $_POST['channel_id']);
  613. $sql = $this->db->update_string('exp_channels', $_POST, 'channel_id='.$this->db->escape_str($_POST['channel_id']));
  614. $this->db->query($sql);
  615. $channel_id = $this->db->escape_str($_POST['channel_id']);
  616. $success_msg = lang('channel_updated');
  617. }
  618. /** -----------------------------------------
  619. /** Create Templates
  620. /** -----------------------------------------*/
  621. if ($edit == FALSE)
  622. {
  623. if ($create_templates != 'no')
  624. {
  625. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_template_groups");
  626. $group_order = $query->row('count') +1;
  627. $this->db->insert('template_groups', array(
  628. 'group_name' => $group_name,
  629. 'group_order' => $group_order,
  630. 'is_site_default' => 'n',
  631. 'site_id' => $this->config->item('site_id')
  632. ));
  633. $group_id = $this->db->insert_id();
  634. if ($create_templates == 'duplicate')
  635. {
  636. $this->db->select('group_name');
  637. $this->db->where('group_id', $old_group_id);
  638. $query = $this->db->get('template_groups');
  639. $old_group_name = $query->row('group_name') ;
  640. $this->db->select('template_name, template_data, template_type,
  641. template_notes, cache, refresh, no_auth_bounce,
  642. allow_php, php_parse_location');
  643. $this->db->where('group_id', $old_group_id);
  644. $query = $this->db->get('templates');
  645. if ($query->num_rows() == 0)
  646. {
  647. $this->db->insert('templates', array(
  648. 'group_id' => $group_id,
  649. 'template_name' => 'index',
  650. 'edit_date' => $this->localize->now,
  651. 'site_id' => $this->config->item('site_id')
  652. ));
  653. }
  654. else
  655. {
  656. $old_channel_name = '';
  657. foreach ($query->result_array() as $row)
  658. {
  659. if ($old_channel_name == '')
  660. {
  661. if (preg_match_all("/channel=[\"'](.+?)[\"']/", $row['template_data'], $matches))
  662. {
  663. for ($i = 0; $i < count($matches['1']); $i++)
  664. {
  665. if (substr($matches['1'][$i], 0, 1) != '{')
  666. {
  667. $old_channel_name = $matches['1'][$i];
  668. break;
  669. }
  670. }
  671. }
  672. }
  673. $temp = str_replace('channel="'.$old_channel_name.'"', 'channel="'.$_POST['channel_name'].'"', $row['template_data']);
  674. $temp = str_replace("channel='".$old_channel_name."'", 'channel="'.$_POST['channel_name'].'"', $temp);
  675. $temp = preg_replace("/{stylesheet=.+?\/(.+?)}/", "{stylesheet=".$group_name."/\\1}", $temp);
  676. $temp = preg_replace("#preload_replace:master_channel_name=\".+?\"#", 'preload_replace:master_channel_name="'.$_POST['channel_name'].'"', $temp);
  677. $temp = preg_replace("#preload_replace:master_channel_name=\'.+?\'#", "preload_replace:master_channel_name='".$_POST['channel_name']."'", $temp);
  678. $temp = preg_replace('#preload_replace:my_template_group=(\042|\047)([^\\1]*?)\\1#', "preload_replace:my_template_group=\\1{$group_name}\\1", $temp);
  679. $temp = preg_replace("#".$old_group_name."/(.+?)#", $group_name."/\\1", $temp);
  680. $data = array(
  681. 'group_id' => $group_id,
  682. 'template_name' => $row['template_name'],
  683. 'template_notes' => $row['template_notes'],
  684. 'cache' => $row['cache'],
  685. 'refresh' => $row['refresh'],
  686. 'no_auth_bounce' => $row['no_auth_bounce'],
  687. 'php_parse_location' => $row['php_parse_location'],
  688. 'allow_php' => ($this->session->userdata['group_id'] == 1) ? $row['allow_php'] : 'n',
  689. 'template_type' => $row['template_type'],
  690. 'template_data' => $temp,
  691. 'edit_date' => $this->localize->now,
  692. 'last_author_id' => 0,
  693. 'site_id' => $this->config->item('site_id')
  694. );
  695. $this->db->insert('templates', $data);
  696. }
  697. }
  698. }
  699. else
  700. {
  701. $type = 'core';
  702. if ($fp = @opendir(PATH_MOD))
  703. {
  704. while (FALSE !== ($file = readdir($fp)))
  705. {
  706. if (strpos($file, '.') === FALSE)
  707. {
  708. if ($file == 'mailinglist')
  709. {
  710. $type = 'full';
  711. break;
  712. }
  713. }
  714. }
  715. closedir($fp);
  716. }
  717. require PATH_THEMES.'site_themes/'.$template_theme.'/'.$template_theme.'.php';
  718. foreach ($template_matrix as $tmpl)
  719. {
  720. $Q[] = array($tmpl['0'](), "INSERT INTO exp_templates(group_id, template_name, template_type, template_data, edit_date, site_id)
  721. VALUES ('$group_id', '".$this->db->escape_str($tmpl['0'])."', '".$this->db->escape_str($tmpl['1'])."', '{template}', '".$this->localize->now."', '".$this->db->escape_str($this->config->item('site_id'))."')");
  722. }
  723. if ($add_rss == TRUE)
  724. {
  725. require PATH_THEMES.'site_themes/rss/rss.php';
  726. $Q[] = array(rss_2(), "INSERT INTO exp_templates(group_id, template_name, template_type, template_data, edit_date, site_id)
  727. VALUES ('$group_id', 'rss_2.0', 'feed', '{template}', '".$this->db->escape_str($this->localize->now)."', '".$this->db->escape_str($this->config->item('site_id'))."')");
  728. $Q[] = array(atom(), "INSERT INTO exp_templates(group_id, template_name, template_type, template_data, edit_date, site_id)
  729. VALUES ('$group_id', 'atom', 'feed', '{template}', '".$this->db->escape_str($this->localize->now)."', '".$this->db->escape_str($this->config->item('site_id'))."')");
  730. }
  731. foreach ($Q as $val)
  732. {
  733. $temp = $val['0'];
  734. $temp = str_replace('channel="channel1"', 'channel="'.$_POST['channel_name'].'"', $temp);
  735. $temp = str_replace("channel='channel1'", 'channel="'.$_POST['channel_name'].'"', $temp);
  736. $temp = str_replace('my_channel="channel1"', 'my_channel="'.$_POST['channel_name'].'"', $temp);
  737. $temp = str_replace("my_channel='channel1'", 'my_channel="'.$_POST['channel_name'].'"', $temp);
  738. $temp = str_replace('channel="default_site"', 'channel="'.$_POST['channel_name'].'"', $temp);
  739. $temp = str_replace("channel='default_site'", 'channel="'.$_POST['channel_name'].'"', $temp);
  740. $temp = str_replace('my_channel="default_site"', 'my_channel="'.$_POST['channel_name'].'"', $temp);
  741. $temp = str_replace("my_channel='default_site'", 'my_channel="'.$_POST['channel_name'].'"', $temp);
  742. $temp = str_replace('my_template_group="site"', 'my_template_group="'.$group_name.'"', $temp);
  743. $temp = str_replace("my_template_group='site'", 'my_template_group="'.$group_name.'"', $temp);
  744. $temp = str_replace("{stylesheet=channel/channel_css}", "{stylesheet=".$group_name."/site_css}", $temp);
  745. $temp = str_replace("{stylesheet=site/site_css}", "{stylesheet=".$group_name."/site_css}", $temp);
  746. $temp = str_replace('preload_replace:master_channel_name="channel1"', 'preload_replace:master_channel_name="'.$_POST['channel_name'].'"', $temp);
  747. $temp = preg_replace("#channel/(.+?)#", $group_name."/\\1", $temp);
  748. $temp = addslashes($temp);
  749. $sql = str_replace('{template}', $temp, $val['1']);
  750. $this->db->query($sql);
  751. }
  752. }
  753. }
  754. }
  755. $cp_message = $success_msg.NBS.NBS.$_POST['channel_title'];
  756. $this->session->set_flashdata('message_success', $cp_message);
  757. if ($edit == FALSE OR $return === TRUE)
  758. {
  759. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  760. }
  761. else
  762. {
  763. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_edit&channel_id='.$channel_id);
  764. }
  765. }
  766. // --------------------------------------------------------------------
  767. /**
  768. * Channel Update Group Assignments
  769. *
  770. * This function processes changes to the channel's
  771. * assigned groups
  772. *
  773. * @access public
  774. * @return void
  775. */
  776. function channel_update_group_assignments()
  777. {
  778. $this->_restrict_prefs_access();
  779. $update_fields = FALSE;
  780. $channel_id = $this->input->post('channel_id');
  781. $data['field_group'] = ($this->input->post('field_group') != FALSE && $this->input->post('field_group') != '') ? $this->input->post('field_group') : NULL;
  782. $data['status_group'] = ($this->input->post('status_group') != FALSE && $this->input->post('status_group') != '') ? $this->input->post('status_group') : NULL;
  783. $this->lang->loadfile('admin_content');
  784. if (isset($_POST['cat_group']) && is_array($_POST['cat_group']))
  785. {
  786. $data['cat_group'] = ltrim(implode('|', $_POST['cat_group']), '|');
  787. }
  788. if ( ! isset($data['cat_group']) OR $data['cat_group'] == '')
  789. {
  790. $data['cat_group'] = '';
  791. }
  792. // Find the old custom fields so we can remove them
  793. // Have the field assignments changed
  794. $this->db->select('cat_group, status_group, field_group');
  795. $this->db->where('channel_id', $channel_id);
  796. $query = $this->db->get('channels');
  797. if ($query->num_rows() == 1)
  798. {
  799. $old_cat = $query->row('cat_group');
  800. $old_status = $query->row('status_group');
  801. $old_field = $query->row('field_group');
  802. }
  803. if ($old_field != $data['field_group'] && ! is_null($old_field))
  804. {
  805. $update_fields = TRUE;
  806. $this->db->select('field_id');
  807. $this->db->where('group_id', $old_field);
  808. $query = $this->db->get('channel_fields');
  809. if ($query->num_rows() > 0)
  810. {
  811. foreach($query->result() as $row)
  812. {
  813. $tabs[] = $row->field_id;
  814. }
  815. $this->load->library('layout');
  816. $this->layout->delete_layout_fields($tabs, $channel_id);
  817. unset($tabs);
  818. }
  819. }
  820. $this->db->where('channel_id', $channel_id);
  821. $this->db->update('channels', $data);
  822. // Updated saved layouts if field group changed
  823. if ($update_fields == TRUE && ! is_null($data['field_group']))
  824. {
  825. $this->db->select('field_id');
  826. $this->db->where('group_id', $data['field_group']);
  827. $query = $this->db->get('channel_fields');
  828. if ($query->num_rows() > 0)
  829. {
  830. foreach($query->result() as $row)
  831. {
  832. $tabs['publish'][$row->field_id] = array(
  833. 'visible' => 'true',
  834. 'collapse' => 'false',
  835. 'htmlbuttons' => 'true',
  836. 'width' => '100%'
  837. );
  838. }
  839. $this->load->library('layout');
  840. $this->layout->add_layout_fields($tabs, $channel_id);
  841. }
  842. }
  843. $success_msg = lang('channel_updated');
  844. $cp_message = $success_msg.NBS.NBS.$_POST['channel_title'];
  845. $this->session->set_flashdata('message_success', $cp_message);
  846. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  847. }
  848. // --------------------------------------------------------------------
  849. /**
  850. * Edit Channel
  851. *
  852. * This function displays the form used to edit the various
  853. * preferences and group assignments for a given channel
  854. *
  855. * @access public
  856. * @return void
  857. */
  858. function channel_edit_group_assignments()
  859. {
  860. $this->_restrict_prefs_access();
  861. // If we don't have the $channel_id variable, bail out.
  862. $channel_id = $this->input->get_post('channel_id');
  863. if ($channel_id == '' OR ! is_numeric($channel_id))
  864. {
  865. show_error(lang('not_authorized'));
  866. }
  867. $this->lang->loadfile('admin_content');
  868. $this->load->model(array(
  869. 'channel_model', 'category_model', 'status_model', 'field_model'
  870. ));
  871. $query = $this->channel_model->get_channel_info($channel_id);
  872. foreach ($query->row_array() as $key => $val)
  873. {
  874. if ($key == 'cat_group')
  875. {
  876. $val = explode('|', $val);
  877. }
  878. $vars[$key] = $val;
  879. }
  880. $vars['form_hidden'] = array(
  881. 'channel_id' => $channel_id,
  882. 'channel_name' => $vars['channel_name'],
  883. 'channel_title' => $vars['channel_title'],
  884. 'return' => 1
  885. );
  886. // Category Select List
  887. $query = $this->category_model->get_category_groups('', FALSE, 2);
  888. $vars['cat_group_options'][''] = lang('none');
  889. if ($query->num_rows() > 0)
  890. {
  891. foreach ($query->result() as $row)
  892. {
  893. $vars['cat_group_options'][$row->group_id] = $row->group_name;
  894. }
  895. }
  896. // Status group select list
  897. $this->db->select('group_id, group_name');
  898. $this->db->where('site_id', $this->config->item('site_id'));
  899. $this->db->order_by('group_name');
  900. $query = $this->db->get('status_groups');
  901. $vars['status_group_options'][''] = lang('none');
  902. if ($query->num_rows() > 0)
  903. {
  904. foreach ($query->result() as $row)
  905. {
  906. $vars['status_group_options'][$row->group_id] = $row->group_name;
  907. }
  908. }
  909. // Field group select list
  910. $this->db->select('group_id, group_name');
  911. $this->db->where('site_id', $this->config->item('site_id'));
  912. $this->db->order_by('group_name');
  913. $query = $this->db->get('field_groups');
  914. $vars['field_group_options'][''] = lang('none');
  915. if ($query->num_rows() > 0)
  916. {
  917. foreach ($query->result() as $row)
  918. {
  919. $vars['field_group_options'][$row->group_id] = $row->group_name;
  920. }
  921. }
  922. $this->javascript->compile();
  923. $this->cp->set_variable('cp_page_title', lang('edit_group_assignments'));
  924. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  925. $this->load->view('admin/channel_edit_group_assignments', $vars);
  926. }
  927. // --------------------------------------------------------------------
  928. /**
  929. * Delete channel confirm
  930. *
  931. * @access public
  932. * @return void
  933. */
  934. function channel_delete_confirm()
  935. {
  936. $this->_restrict_prefs_access();
  937. $channel_id = $this->input->get_post('channel_id');
  938. if ($channel_id == '' OR ! is_numeric($channel_id))
  939. {
  940. show_error(lang('not_authorized'));
  941. }
  942. $this->lang->loadfile('admin_content');
  943. $this->load->model('channel_model');
  944. $this->cp->set_variable('cp_page_title', lang('delete_channel'));
  945. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=channel_management', lang('channels'));
  946. $vars['form_action'] = 'C=admin_content'.AMP.'M=channel_delete';
  947. $vars['form_extra'] = '';
  948. $vars['form_hidden']['channel_id'] = $channel_id;
  949. $vars['message'] = lang('delete_channel_confirmation');
  950. // Grab category_groups locations with this id
  951. $items = $this->channel_model->get_channel_info($channel_id);
  952. $vars['items'] = array();
  953. foreach($items->result() as $item)
  954. {
  955. $vars['items'][] = $item->channel_title;
  956. }
  957. $this->javascript->compile();
  958. $this->load->view('admin/preference_delete_confirm', $vars);
  959. }
  960. // --------------------------------------------------------------------
  961. /**
  962. * Delete channel
  963. *
  964. * This function deletes a given channel
  965. *
  966. * @access public
  967. * @return void
  968. */
  969. function channel_delete()
  970. {
  971. $this->_restrict_prefs_access();
  972. $channel_id = $this->input->get_post('channel_id');
  973. if ($channel_id == '' OR ! is_numeric($channel_id))
  974. {
  975. show_error(lang('not_authorized'));
  976. }
  977. $this->lang->loadfile('admin_content');
  978. $this->load->model('channel_model');
  979. $query = $this->channel_model->get_channel_info($channel_id);
  980. if ($query->num_rows() == 0)
  981. {
  982. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  983. }
  984. $channel_title = $query->row('channel_title') ;
  985. $this->logger->log_action(lang('channel_deleted').NBS.NBS.$channel_title);
  986. $this->db->select('entry_id, author_id');
  987. $this->db->where('channel_id', $channel_id);
  988. $query = $this->db->get('channel_titles');
  989. $entries = array();
  990. $authors = array();
  991. if ($query->num_rows() > 0)
  992. {
  993. foreach ($query->result() as $row)
  994. {
  995. $entries[] = $row->entry_id;
  996. $authors[] = $row->author_id;
  997. }
  998. }
  999. $authors = array_unique($authors);
  1000. $this->channel_model->delete_channel($channel_id, $entries, $authors);
  1001. // Clear saved layouts
  1002. $this->load->library('layout');
  1003. $this->layout->delete_channel_layouts($channel_id);
  1004. $this->session->set_flashdata('message_success', lang('channel_deleted').NBS.$channel_title);
  1005. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=channel_management');
  1006. }
  1007. // --------------------------------------------------------------------
  1008. /**
  1009. * Category Management
  1010. *
  1011. * Creates the Category Management main page
  1012. *
  1013. * @access public
  1014. * @return void
  1015. */
  1016. function category_management()
  1017. {
  1018. if (AJAX_REQUEST)
  1019. {
  1020. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1021. {
  1022. show_error(lang('unauthorized_access'));
  1023. }
  1024. }
  1025. else
  1026. {
  1027. $this->_restrict_prefs_access();
  1028. }
  1029. $this->load->library('table');
  1030. $this->load->model('category_model');
  1031. $this->lang->loadfile('admin_content');
  1032. $this->cp->set_variable('cp_page_title', lang('categories'));
  1033. $this->jquery->tablesorter('.mainTable', '{
  1034. headers: {2: {sorter: false}, 3: {sorter: false}, 4: {sorter: false}, 5: {sorter: false}},
  1035. widgets: ["zebra"]
  1036. }');
  1037. $this->javascript->compile();
  1038. // Fetch count of custom fields per group
  1039. $cfcount = array();
  1040. $this->db->select('COUNT(*) AS count, group_id');
  1041. $this->db->group_by('group_id');
  1042. $cfq = $this->db->get('category_fields');
  1043. if ($cfq->num_rows() > 0)
  1044. {
  1045. foreach ($cfq->result() as $row)
  1046. {
  1047. $cfcount[$row->group_id] = $row->count;
  1048. }
  1049. }
  1050. $cat_count = 1;
  1051. $vars['categories'] = array();
  1052. $categories = $this->category_model->get_categories('', FALSE);
  1053. foreach($categories->result() as $row)
  1054. {
  1055. $this->db->where('group_id', $row->group_id);
  1056. $category_count = $this->db->count_all_results('categories');
  1057. $vars['categories'][$cat_count]['group_id'] = $row->group_id;
  1058. $vars['categories'][$cat_count]['group_name'] = $row->group_name;
  1059. $vars['categories'][$cat_count]['category_count'] = $category_count;
  1060. $vars['categories'][$cat_count]['custom_field_count'] = ((isset($cfcount[$row->group_id])) ? $cfcount[$row->group_id] : '0');
  1061. $cat_count++;
  1062. }
  1063. $this->cp->set_right_nav(array('create_new_category_group' => BASE.AMP.'C=admin_content'.AMP.'M=edit_category_group'));
  1064. $this->load->view('admin/category_management', $vars);
  1065. }
  1066. // --------------------------------------------------------------------
  1067. /**
  1068. * Edit Category Group
  1069. *
  1070. * This function shows the form used to define a new category
  1071. * group or edit an existing one
  1072. *
  1073. * @access public
  1074. * @return mixed
  1075. */
  1076. function edit_category_group()
  1077. {
  1078. $this->_restrict_prefs_access();
  1079. $this->load->model('admin_model');
  1080. $this->load->model('category_model');
  1081. $this->lang->loadfile('admin_content');
  1082. $this->load->library('table');
  1083. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1084. // Set default values
  1085. $vars['cp_page_title'] = lang('create_new_category_group');
  1086. $vars['submit_lang_key'] = 'submit';
  1087. $vars['form_hidden'] = array(); // nothing needs to be passed into a new cat group
  1088. $vars['group_name'] = '';
  1089. $vars['field_html_formatting'] = 'all';
  1090. $vars['can_edit'] = array();
  1091. $vars['can_delete'] = array();
  1092. $vars['can_edit_selected'] = array();
  1093. $vars['can_delete_selected'] = array();
  1094. $vars['formatting_options'] = array(
  1095. 'none' => lang('convert_to_entities'),
  1096. 'safe' => lang('allow_safe_html'),
  1097. 'all' => lang('allow_all_html')
  1098. );
  1099. $can_edit_selected = array();
  1100. $can_delete_selected = array();
  1101. $vars['can_edit_categories'] = '';
  1102. $vars['can_delete_categories'] = '';
  1103. $group_id = $this->input->get_post('group_id');
  1104. // If we have the group_id variable, it's an edit request, so fetch the category data
  1105. if ($group_id != '')
  1106. {
  1107. if ( ! is_numeric($group_id))
  1108. {
  1109. show_error();
  1110. }
  1111. // some defaults to overwrite if we're editing
  1112. $vars['cp_page_title'] = lang('edit_category_group');
  1113. $vars['submit_lang_key'] = 'update';
  1114. $vars['form_hidden']['group_id'] = $group_id;
  1115. $this->db->where('group_id', $group_id);
  1116. $this->db->where('site_id', $this->config->item('site_id'));
  1117. $this->db->from('category_groups');
  1118. $this->db->order_by('group_name');
  1119. $query = $this->db->get();
  1120. // there's only 1 possible category
  1121. foreach ($query->row_array() as $key => $val)
  1122. {
  1123. $vars[$key] = $val;
  1124. }
  1125. // convert our | separated list of privileges into an array
  1126. $can_edit_selected = explode('|', rtrim($vars['can_edit_categories'], '|'));
  1127. $can_delete_selected = explode('|', rtrim($vars['can_delete_categories'], '|'));
  1128. }
  1129. // Grab member groups with potential privs
  1130. $this->db->select('group_id, group_title, can_edit_categories, can_delete_categories');
  1131. $this->db->where_not_in('group_id', array(1,2,3,4));
  1132. $this->db->where('site_id', $this->config->item('site_id'));
  1133. $query = $this->db->get('member_groups');
  1134. $vars['can_edit_checks'] = array();
  1135. $vars['can_delete_checks'] = array();
  1136. // Can Edit/Delete Categories selected
  1137. foreach ($query->result_array() as $row)
  1138. {
  1139. if ($row['can_edit_categories'] == 'y')
  1140. {
  1141. $vars['can_edit_checks'][$row['group_id']]['id'] = $row['group_id'];
  1142. $vars['can_edit_checks'][$row['group_id']]['value'] = $row['group_title'];
  1143. $vars['can_edit_checks'][$row['group_id']]['checked'] = (in_array($row['group_id'], $can_edit_selected)) ? TRUE : FALSE;
  1144. $vars['can_edit'][$row['group_id']] = $row['group_title'];
  1145. }
  1146. if ($row['can_delete_categories'] == 'y')
  1147. {
  1148. $vars['can_delete_checks'][$row['group_id']]['id'] = $row['group_id'];
  1149. $vars['can_delete_checks'][$row['group_id']]['value'] = $row['group_title'];
  1150. $vars['can_delete_checks'][$row['group_id']]['checked'] = (in_array($row['group_id'], $can_delete_selected)) ? TRUE : FALSE;
  1151. $vars['can_delete'][$row['group_id']] = $row['group_title'];
  1152. }
  1153. }
  1154. // Get the selected 'excluded' group
  1155. $vars['exclude_selected'] = (isset($vars['exclude_group'])) ? $vars['exclude_group'] : FALSE;
  1156. $this->javascript->compile();
  1157. $this->load->view('admin/edit_category_group', $vars);
  1158. }
  1159. // --------------------------------------------------------------------
  1160. /**
  1161. * Update Category Group
  1162. *
  1163. * This function receives the submission from the group
  1164. * form and stores it in the database
  1165. *
  1166. * @access public
  1167. * @return void
  1168. */
  1169. function update_category_group()
  1170. {
  1171. $this->_restrict_prefs_access();
  1172. // If the $group_id variable is present we are editing an
  1173. // existing group, otherwise we are creating a new one
  1174. $edit = ($this->input->post('group_id') != '') ? TRUE : FALSE;
  1175. if ($this->input->post('group_name') == '')
  1176. {
  1177. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1178. }
  1179. // this should never happen, but protect ourselves!
  1180. if ( ! isset($_POST['field_html_formatting']) OR ! in_array($_POST['field_html_formatting'], array('all', 'none', 'safe')))
  1181. {
  1182. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1183. }
  1184. $this->lang->loadfile('admin_content');
  1185. // check for bad characters in group name
  1186. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $_POST['group_name']))
  1187. {
  1188. show_error(lang('illegal_characters'));
  1189. }
  1190. $this->load->model('category_model');
  1191. // Is the group name taken?
  1192. if ($this->category_model->is_duplicate_category_group($this->input->post('group_name'), $this->input->post('group_id')))
  1193. {
  1194. show_error(lang('taken_category_group_name'));
  1195. }
  1196. // make data array of variables from our POST data
  1197. $data = array();
  1198. foreach ($_POST as $key => $val)
  1199. {
  1200. // we can ignore some unwanted keys before INSERTing / UPDATEing
  1201. if (strpos($key, 'can_edit_categories_') !== FALSE OR strpos($key, 'can_delete_categories_') !== FALSE OR strpos($key, 'submit') !== FALSE)
  1202. {
  1203. continue;
  1204. }
  1205. $data[$key] = $val;
  1206. }
  1207. // Set our pipe delimited privileges for edit / delete
  1208. if (isset($data['can_edit_categories']) and is_array($data['can_edit_categories']))
  1209. {
  1210. $data['can_edit_categories'] = implode('|', $data['can_edit_categories']);
  1211. }
  1212. else
  1213. {
  1214. $data['can_edit_categories'] = '';
  1215. }
  1216. if (isset($data['can_delete_categories']) and is_array($data['can_delete_categories']))
  1217. {
  1218. $data['can_delete_categories'] = implode('|', $data['can_delete_categories']);
  1219. }
  1220. else
  1221. {
  1222. $data['can_delete_categories'] = '';
  1223. }
  1224. // Construct the query based on whether we are updating or inserting
  1225. if ($edit == FALSE)
  1226. {
  1227. $this->category_model->insert_category_group($data);
  1228. $cp_message = lang('category_group_created').' '.$data['group_name'];
  1229. $this->logger->log_action(lang('category_group_created').NBS.NBS.$data['group_name']);
  1230. $this->db->select('channel_id');
  1231. $this->db->where('site_id', $this->config->item('site_id'));
  1232. $query = $this->db->get('channels');
  1233. if ($query->num_rows() > 0)
  1234. {
  1235. $cp_message .= '<br />'.lang('assign_group_to_channel');
  1236. if ($query->num_rows() == 1)
  1237. {
  1238. $link = 'C=admin_content'.AMP.'M=channel_edit_group_assignments'.AMP.'channel_id='.$query->row('channel_id') ;
  1239. }
  1240. else
  1241. {
  1242. $link = 'C=admin_content'.AMP.'M=channel_management';
  1243. }
  1244. $cp_message .= '<br /><a href="'.BASE.AMP.$link.'">'. lang('click_to_assign_group').'</a>';
  1245. }
  1246. }
  1247. else
  1248. {
  1249. $this->category_model->update_category_group($data['group_id'], $data);
  1250. $cp_message = lang('category_group_updated').NBS.$data['group_name'];
  1251. }
  1252. $this->session->set_flashdata('message_success', $cp_message);
  1253. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1254. }
  1255. // --------------------------------------------------------------------
  1256. /**
  1257. * Delete category group confirm
  1258. *
  1259. * Warning message if you try to delete a category group
  1260. *
  1261. * @access public
  1262. * @return mixed
  1263. */
  1264. function category_group_delete_conf()
  1265. {
  1266. $this->_restrict_prefs_access();
  1267. $group_id = $this->input->get_post('group_id');
  1268. if ($group_id == '' OR ! is_numeric($group_id))
  1269. {
  1270. show_error(lang('not_authorized'));
  1271. }
  1272. $this->lang->loadfile('admin_content');
  1273. $this->load->model('category_model');
  1274. $this->cp->set_variable('cp_page_title', lang('delete_group'));
  1275. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1276. $vars['form_action'] = 'C=admin_content'.AMP.'M=category_group_delete';
  1277. $vars['form_extra'] = '';
  1278. $vars['form_hidden']['group_id'] = $group_id;
  1279. $vars['message'] = lang('delete_cat_group_confirmation');
  1280. // Grab category_groups locations with this id
  1281. $items = $this->category_model->get_category_group_name($group_id);
  1282. $vars['items'] = array();
  1283. foreach($items->result() as $item)
  1284. {
  1285. $vars['items'][] = $item->group_name;
  1286. }
  1287. $this->javascript->compile();
  1288. $this->load->view('admin/preference_delete_confirm', $vars);
  1289. }
  1290. // --------------------------------------------------------------------
  1291. /**
  1292. * Delete category group
  1293. *
  1294. * This function deletes the category group and all associated categories
  1295. *
  1296. * @access public
  1297. * @return void
  1298. */
  1299. function category_group_delete()
  1300. {
  1301. $this->_restrict_prefs_access();
  1302. $group_id = $this->input->get_post('group_id');
  1303. if ($group_id == '' OR ! is_numeric($group_id))
  1304. {
  1305. show_error(lang('not_authorized'));
  1306. }
  1307. $this->lang->loadfile('admin_content');
  1308. $this->load->model('category_model');
  1309. $category = $this->category_model->get_category_group_name($group_id);
  1310. if ($category->num_rows() == 0)
  1311. {
  1312. show_error(lang('not_authorized'));
  1313. }
  1314. $name = $category->row('group_name');
  1315. // Delete from exp_category_posts
  1316. $this->category_model->delete_category_group($group_id);
  1317. $this->logger->log_action(lang('category_group_deleted').NBS.NBS.$name);
  1318. $this->functions->clear_caching('all', '', TRUE);
  1319. $this->session->set_flashdata('message_success', lang('category_group_deleted').NBS.NBS.$name);
  1320. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_management');
  1321. }
  1322. // --------------------------------------------------------------------
  1323. /**
  1324. * Category management page
  1325. *
  1326. * This function shows the list of current categories, as
  1327. * well as the form used to submit a new category
  1328. *
  1329. * @access public
  1330. * @return void
  1331. */
  1332. function category_editor($group_id = '', $update = FALSE)
  1333. {
  1334. if (AJAX_REQUEST)
  1335. {
  1336. $vars['EE_view_disable'] = TRUE;
  1337. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1338. {
  1339. show_error(lang('unauthorized_access'));
  1340. }
  1341. }
  1342. else
  1343. {
  1344. $this->_restrict_prefs_access();
  1345. }
  1346. $this->lang->loadfile('admin_content');
  1347. $this->load->model('category_model');
  1348. $this->load->library('table');
  1349. $this->load->library('api');
  1350. $this->api->instantiate('channel_categories');
  1351. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1352. $vars['message'] = ''; // override lower down if needed
  1353. $vars['form_action'] = '';
  1354. $this->jquery->tablesorter('.mainTable', '{
  1355. headers: {1: {sorter: false}, 2: {sorter: false}, 3: {sorter: false}, 4: {sorter: false}},
  1356. widgets: ["zebra"]
  1357. }');
  1358. $this->javascript->compile();
  1359. if ($group_id == '')
  1360. {
  1361. if (($group_id = $this->input->get_post('group_id')) === FALSE OR ! is_numeric($group_id))
  1362. {
  1363. show_error(lang('unauthorized_access'));
  1364. }
  1365. }
  1366. // Check discrete privileges
  1367. if (AJAX_REQUEST)
  1368. {
  1369. $this->db->select('can_edit_categories');
  1370. $this->db->where('group_id', $group_id);
  1371. $query = $this->db->get('category_groups');
  1372. if ($query->num_rows() == 0)
  1373. {
  1374. show_error(lang('unauthorized_access'));
  1375. }
  1376. $can_edit = explode('|', rtrim($query->row('can_edit_categories') , '|'));
  1377. if ($this->session->userdata['group_id'] != 1 AND ! in_array($this->session->userdata['group_id'], $can_edit))
  1378. {
  1379. show_error(lang('unauthorized_access'));
  1380. }
  1381. }
  1382. $zurl = ($this->input->get_post('Z') == 1) ? AMP.'Z=1' : '';
  1383. $zurl .= ($this->input->get_post('cat_group') !== FALSE) ? AMP.'cat_group='.$this->input->get_post('cat_group') : '';
  1384. $zurl .= ($this->input->get_post('integrated') !== FALSE) ? AMP.'integrated='.$this->input->get_post('integrated') : '';
  1385. $query = $this->category_model->get_categories($group_id, FALSE);
  1386. if ($query->num_rows() == 0)
  1387. {
  1388. $this->functions->redirect(BASE.AMP.'C=admin_content&M=category_management');
  1389. }
  1390. $group_name = $query->row('group_name') ;
  1391. $sort_order = $query->row('sort_order') ;
  1392. $this->cp->set_variable('cp_page_title', $group_name);
  1393. if ($update != FALSE)
  1394. {
  1395. $vars['message'] = lang('category_updated');
  1396. }
  1397. // Fetch the category tree
  1398. $this->api_channel_categories->category_tree($group_id, '', $sort_order);
  1399. $vars['categories'] = array();
  1400. if (count($this->api_channel_categories->categories) > 0)
  1401. {
  1402. $vars['categories'] = $this->api_channel_categories->categories;
  1403. // Category order
  1404. if ($this->input->get_post('Z') == FALSE)
  1405. {
  1406. $vars['form_action'] = 'C=admin_content'.AMP.'M=global_category_order'.AMP.'group_id='.$group_id;
  1407. $vars['sort_order'] = $sort_order;
  1408. }
  1409. }
  1410. $vars['can_edit'] = ($this->session->userdata('can_edit_categories') == 'y') ? TRUE : FALSE;
  1411. $vars['can_delete'] = ($this->session->userdata('can_delete_categories') == 'y') ? TRUE : FALSE;
  1412. $vars['group_id'] = $group_id;
  1413. $this->cp->set_right_nav(array(
  1414. 'new_category' => BASE.AMP.'C=admin_content'.AMP.'M=category_edit'.AMP.'group_id='.$group_id
  1415. ));
  1416. $this->load->view('admin/category_editor', $vars);
  1417. }
  1418. // --------------------------------------------------------------------
  1419. /**
  1420. * Edit Category
  1421. *
  1422. * This function displays an existing category in a form so that it can be edited.
  1423. *
  1424. * @access public
  1425. * @return mixed
  1426. */
  1427. function category_edit()
  1428. {
  1429. if (AJAX_REQUEST)
  1430. {
  1431. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1432. {
  1433. show_error(lang('unauthorized_access'));
  1434. }
  1435. }
  1436. else
  1437. {
  1438. $this->_restrict_prefs_access();
  1439. }
  1440. $this->load->model('category_model');
  1441. $this->lang->loadfile('admin_content');
  1442. $this->load->helper('string');
  1443. $this->load->library('form_validation');
  1444. $group_id = $this->input->get_post('group_id');
  1445. if ($group_id != '')
  1446. {
  1447. if ( ! is_numeric($group_id))
  1448. {
  1449. show_error(lang('unauthorized_access'));
  1450. }
  1451. }
  1452. // Check discrete privileges
  1453. if (AJAX_REQUEST)
  1454. {
  1455. $this->db->select('can_edit_categories');
  1456. $this->db->where('group_id', $group_id);
  1457. $query = $this->db->get('category_groups');
  1458. if ($query->num_rows() == 0)
  1459. {
  1460. show_error(lang('unauthorized_access'));
  1461. }
  1462. $can_edit = explode('|', rtrim($query->row('can_edit_categories') , '|'));
  1463. if ($this->session->userdata['group_id'] != 1 AND ! in_array($this->session->userdata['group_id'], $can_edit))
  1464. {
  1465. show_error(lang('unauthorized_access'));
  1466. }
  1467. }
  1468. $vars['cat_id'] = $this->input->get_post('cat_id');
  1469. $default = array('cat_name', 'cat_url_title', 'cat_description', 'cat_image', 'cat_id', 'parent_id');
  1470. if ($vars['cat_id'] != '')
  1471. {
  1472. $this->db->select('cat_id, cat_name, cat_url_title, cat_description, cat_image, group_id, parent_id');
  1473. $query = $this->db->get_where('categories', array('cat_id' => $vars['cat_id']));
  1474. if ($query->num_rows() == 0)
  1475. {
  1476. show_error(lang('unauthorized_access'));
  1477. }
  1478. $row = $query->row_array();
  1479. foreach ($default as $val)
  1480. {
  1481. $vars[$val] = $row[$val];
  1482. }
  1483. $vars['form_hidden']['cat_id'] = $vars['cat_id'];
  1484. $vars['submit_lang_key'] = 'update';
  1485. }
  1486. else
  1487. {
  1488. foreach ($default as $val)
  1489. {
  1490. $vars[$val] = '';
  1491. }
  1492. $vars['submit_lang_key'] = 'submit';
  1493. }
  1494. // Override the parent id if there is post data
  1495. if ($this->input->post('parent_id'))
  1496. {
  1497. $vars['parent_id'] = $this->input->post('parent_id');
  1498. }
  1499. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1500. $this->cp->set_variable('cp_page_title', ($vars['cat_id'] == '') ? lang('new_category') : lang('edit_category'));
  1501. // Create Foreign Character Conversion JS
  1502. include(APPPATH.'config/foreign_chars.php');
  1503. /* -------------------------------------
  1504. /* 'foreign_character_conversion_array' hook.
  1505. /* - Allows you to use your own foreign character conversion array
  1506. /* - Added 1.6.0
  1507. * - Note: in 2.0, you can edit the foreign_chars.php config file as well
  1508. */
  1509. if (isset($this->extensions->extensions['foreign_character_conversion_array']))
  1510. {
  1511. $foreign_characters = $this->extensions->call('foreign_character_conversion_array');
  1512. }
  1513. /*
  1514. /* -------------------------------------*/
  1515. // New entry gets URL title js
  1516. if ($vars['submit_lang_key'] == 'submit')
  1517. {
  1518. // Pipe in necessary globals
  1519. $this->javascript->set_global(array(
  1520. 'publish.word_separator' => $this->config->item('word_separator') != "dash" ? '_' : '-',
  1521. 'publish.foreignChars' => $foreign_characters,
  1522. ));
  1523. // Load in necessary js files
  1524. $this->cp->add_js_script(array(
  1525. 'plugin' => array('ee_url_title')
  1526. ));
  1527. $this->javascript->keyup('#cat_name', '$("#cat_name").ee_url_title($("#cat_url_title"));');
  1528. }
  1529. $this->load->library('file_field');
  1530. // If there is data in the category image field but the file field library
  1531. // can't parse it, it's likely legacy data from when a URL was entered in a
  1532. // text field for the category image. Let's prompt the user to update the
  1533. // field before they save, otherwise the image will be cleared out.
  1534. $vars['cat_image_error'] = '';
  1535. if ( ! empty($vars['cat_image']) &&
  1536. $this->file_field->parse_field($vars['cat_image']) === FALSE)
  1537. {
  1538. $vars['cat_image_error'] = lang('update_category_image');
  1539. }
  1540. // Setup category image
  1541. $this->file_field->browser();
  1542. $vars['cat_image'] = $this->file_field->field(
  1543. 'cat_image',
  1544. $vars['cat_image'],
  1545. 'all',
  1546. 'image'
  1547. );
  1548. $vars['form_hidden']['group_id'] = $group_id;
  1549. $this->load->library('api');
  1550. $this->api->instantiate('channel_categories');
  1551. $this->api_channel_categories->category_tree($group_id, $vars['parent_id']);
  1552. $vars['parent_id_options'] = $this->api_channel_categories->categories;
  1553. // Display custom fields
  1554. $vars['cat_custom_fields'] = array();
  1555. $this->db->where('group_id', $group_id);
  1556. $this->db->order_by('field_order');
  1557. $field_query = $this->db->get('category_fields');
  1558. $this->db->where('cat_id', $vars['cat_id']);
  1559. $data_query = $this->db->get('category_field_data');
  1560. if ($field_query->num_rows() > 0)
  1561. {
  1562. $dq_row = $data_query->row_array();
  1563. $this->load->model('addons_model');
  1564. $plugins = $this->addons_model->get_plugin_formatting();
  1565. $vars['custom_format_options']['none'] = 'None';
  1566. foreach ($plugins as $k=>$v)
  1567. {
  1568. $vars['custom_format_options'][$k] = $v;
  1569. }
  1570. foreach ($field_query->result_array() as $row)
  1571. {
  1572. $vars['cat_custom_fields'][$row['field_id']]['field_content'] = ( ! isset($dq_row['field_id_'.$row['field_id']])) ? '' : $dq_row['field_id_'.$row['field_id']];
  1573. $vars['cat_custom_fields'][$row['field_id']]['field_fmt'] = ( ! isset($dq_row['field_ft_'.$row['field_id']])) ? $row['field_default_fmt'] : $dq_row['field_ft_'.$row['field_id']];
  1574. $vars['cat_custom_fields'][$row['field_id']]['field_id'] = $row['field_id'];
  1575. $vars['cat_custom_fields'][$row['field_id']]['field_label'] = $row['field_label'];
  1576. $vars['cat_custom_fields'][$row['field_id']]['field_required'] = $row['field_required'];
  1577. $vars['cat_custom_fields'][$row['field_id']]['field_name'] = $row['field_name'];
  1578. $vars['cat_custom_fields'][$row['field_id']]['field_input'] = $row['field_label'];
  1579. $vars['cat_custom_fields'][$row['field_id']]['field_type'] = $row['field_type'];
  1580. $vars['cat_custom_fields'][$row['field_id']]['field_text_direction'] = ($row['field_text_direction'] == 'rtl') ? 'rtl' : 'ltr';
  1581. $vars['cat_custom_fields'][$row['field_id']]['field_show_fmt'] = 'n'; // no by default, over-ridden later when appropriate
  1582. $vars['field_fmt'] = $row['field_default_fmt'];
  1583. // Textarea field types
  1584. if ($row['field_type'] == 'textarea')
  1585. {
  1586. $vars['cat_custom_fields'][$row['field_id']]['rows'] = ( ! isset($row['field_ta_rows'])) ? '10' : $row['field_ta_rows'];
  1587. $vars['cat_custom_fields'][$row['field_id']]['field_show_fmt'] = $row['field_show_fmt'];
  1588. if ($row['field_show_fmt'] != 'y')
  1589. {
  1590. $vars['form_hidden']['field_ft_'.$row['field_id']] = $vars['field_fmt'];
  1591. }
  1592. }
  1593. // Text input field types
  1594. elseif ($row['field_type'] == 'text')
  1595. {
  1596. $vars['cat_custom_fields'][$row['field_id']]['field_maxl'] = $row['field_maxl'];
  1597. if ($row['field_show_fmt'] == 'n')
  1598. {
  1599. $vars['form_hidden']['field_ft_'.$row['field_id']] = $vars['field_fmt'];
  1600. }
  1601. }
  1602. // Drop-down lists
  1603. elseif ($row['field_type'] == 'select')
  1604. {
  1605. $text_direction = ($row['field_text_direction'] == 'rtl') ? 'rtl' : 'ltr';
  1606. unset($field_options); // in case another field type was here
  1607. $field_options = array();
  1608. foreach (explode("\n", trim($row['field_list_items'])) as $v)
  1609. {
  1610. $v = trim($v);
  1611. $field_options[$v] = $v;
  1612. }
  1613. $vars['cat_custom_fields'][$row['field_id']]['field_options'] = $field_options;
  1614. }
  1615. }
  1616. }
  1617. $this->javascript->compile();
  1618. $this->load->view('admin/category_edit', $vars);
  1619. }
  1620. // --------------------------------------------------------------------
  1621. /**
  1622. * Delete category group confirm
  1623. *
  1624. * Warning message if you try to delete a category
  1625. *
  1626. * @access public
  1627. * @return mixed
  1628. */
  1629. function category_delete_conf()
  1630. {
  1631. if (AJAX_REQUEST)
  1632. {
  1633. if ( ! $this->cp->allowed_group('can_delete_categories'))
  1634. {
  1635. show_error(lang('unauthorized_access'));
  1636. }
  1637. }
  1638. else
  1639. {
  1640. $this->_restrict_prefs_access();
  1641. }
  1642. $cat_id = $this->input->get_post('cat_id');
  1643. if ($cat_id == '' OR ! is_numeric($cat_id))
  1644. {
  1645. show_error(lang('not_authorized'));
  1646. }
  1647. $zurl = ($this->input->get_post('modal') == 'yes') ? AMP.'modal=yes' : '';
  1648. $zurl .= ($this->input->get_post('cat_group') !== FALSE) ? AMP.'cat_group='.$this->input->get_post('cat_group') : '';
  1649. $zurl .= ($this->input->get_post('integrated') !== FALSE) ? AMP.'integrated='.$this->input->get_post('integrated') : '';
  1650. $this->lang->loadfile('admin_content');
  1651. $this->load->model('category_model');
  1652. $this->cp->set_variable('cp_page_title', lang('delete_category'));
  1653. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  1654. // Grab category_groups locations with this id
  1655. $items = $this->category_model->get_category_name_group($cat_id);
  1656. $vars = array(
  1657. 'form_action' => 'C=admin_content'.AMP.'M=category_delete'.$zurl,
  1658. 'form_extra' => '',
  1659. 'message' => lang('delete_cat_confirmation'),
  1660. 'items' => array(),
  1661. 'form_hidden' => array(
  1662. 'group_id' => $items->row('group_id'),
  1663. 'cat_id' => $cat_id
  1664. )
  1665. );
  1666. foreach($items->result() as $item)
  1667. {
  1668. $vars['items'][] = $item->cat_name;
  1669. }
  1670. $this->javascript->compile();
  1671. $this->load->view('admin/preference_delete_confirm', $vars);
  1672. }
  1673. // --------------------------------------------------------------------
  1674. /**
  1675. * Delete Category
  1676. *
  1677. * This function deletes a single category
  1678. *
  1679. * @access public
  1680. * @return void
  1681. */
  1682. function category_delete()
  1683. {
  1684. if (AJAX_REQUEST)
  1685. {
  1686. if ( ! $this->cp->allowed_group('can_delete_categories'))
  1687. {
  1688. show_error(lang('unauthorized_access'));
  1689. }
  1690. }
  1691. else
  1692. {
  1693. $this->_restrict_prefs_access();
  1694. }
  1695. $cat_id = $this->input->get_post('cat_id');
  1696. if ($cat_id == '' OR ! is_numeric($cat_id))
  1697. {
  1698. show_error(lang('not_authorized'));
  1699. }
  1700. $this->lang->loadfile('admin_content');
  1701. $this->load->model('category_model');
  1702. $group_id = $this->category_model->delete_category($cat_id);
  1703. $this->session->set_flashdata('message_success', lang('category_deleted'));
  1704. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_editor'.AMP.'group_id='.$group_id);
  1705. }
  1706. // --------------------------------------------------------------------
  1707. /** -----------------------------------------------------------
  1708. /** Category submission handler
  1709. /** -----------------------------------------------------------*/
  1710. // This function receives the category information after
  1711. // being submitted from the form (new or edit) and stores
  1712. // the info in the database.
  1713. //-----------------------------------------------------------
  1714. function category_update()
  1715. {
  1716. if (AJAX_REQUEST)
  1717. {
  1718. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1719. {
  1720. show_error(lang('unauthorized_access'));
  1721. }
  1722. }
  1723. else
  1724. {
  1725. $this->_restrict_prefs_access();
  1726. }
  1727. $group_id = $this->input->get_post('group_id');
  1728. if ($group_id == '' OR ! is_numeric($group_id))
  1729. {
  1730. show_error(lang('unauthorized_access'));
  1731. }
  1732. $edit = ($this->input->post('cat_id') == '') ? FALSE : TRUE;
  1733. $this->lang->loadfile('admin_content');
  1734. $this->load->model('category_model');
  1735. $this->load->library('api');
  1736. $this->api->instantiate('channel_categories');
  1737. // Create and validate Category URL Title
  1738. // Kill all the extraneous characters. (We want the URL title to be pure alpha text)
  1739. $word_separator = $this->config->item('word_separator');
  1740. $this->load->library('form_validation');
  1741. if ($this->input->post('cat_url_title') == '')
  1742. {
  1743. $_POST['cat_url_title'] = url_title($this->input->post('cat_name'), $word_separator, TRUE);
  1744. }
  1745. else
  1746. {
  1747. $_POST['cat_url_title'] = url_title($_POST['cat_url_title'], $word_separator);
  1748. }
  1749. $this->form_validation->set_rules('cat_name', 'lang:category_name', 'required');
  1750. $this->form_validation->set_rules('cat_url_title', 'lang:cat_url_title', 'callback__cat_url_title');
  1751. $this->form_validation->set_rules('cat_description', '', '');
  1752. // Get the Category Image
  1753. $this->load->library('file_field');
  1754. $cat_image = $this->file_field->validate(
  1755. $this->input->post('cat_image'),
  1756. 'cat_image'
  1757. );
  1758. $_POST['cat_image'] = $this->file_field->format_data(
  1759. $cat_image['value']
  1760. );
  1761. // Finish data prep for insertion
  1762. if ($this->config->item('auto_convert_high_ascii') == 'y')
  1763. {
  1764. // Load the text helper
  1765. $this->load->helper('text');
  1766. $_POST['cat_name'] = ascii_to_entities($_POST['cat_name']);
  1767. }
  1768. $_POST['cat_name'] = str_replace(array('<', '>'), array('&lt;', '&gt;'), $_POST['cat_name']);
  1769. // Pull out custom field data for later insertion
  1770. $fields = array();
  1771. foreach ($_POST as $key => $val)
  1772. {
  1773. if (strpos($key, 'field') !== FALSE)
  1774. {
  1775. $fields[$key] = $val;
  1776. }
  1777. }
  1778. // Check for missing required custom fields
  1779. $this->db->select('field_id, field_label');
  1780. $this->db->where('group_id', $group_id);
  1781. $this->db->where('field_required', 'y');
  1782. $query = $this->db->get('category_fields');
  1783. $required_cat_fields = array();
  1784. if ($query->num_rows() > 0)
  1785. {
  1786. foreach ($query->result_array() as $row)
  1787. {
  1788. $required_cat_fields[$row['field_id']] = $row['field_label'];
  1789. $this->form_validation->set_rules('field_id_'.$row['field_id'], $row['field_label'], 'required');
  1790. $this->form_validation->set_rules('field_ft_'.$row['field_id'], '', '');
  1791. }
  1792. }
  1793. foreach ($fields as $id => $val)
  1794. {
  1795. if ( ! isset($required_cat_fields[$id]))
  1796. {
  1797. $this->form_validation->set_rules('field_id_'.$id, '', '');
  1798. $this->form_validation->set_rules('field_ft_'.$id, '', '');
  1799. }
  1800. }
  1801. $this->form_validation->set_error_delimiters('<br /><span class="notice">', '<br />');
  1802. if ($this->form_validation->run() === FALSE)
  1803. {
  1804. return $this->category_edit();
  1805. }
  1806. $_POST['site_id'] = $this->config->item('site_id');
  1807. if ($edit == FALSE)
  1808. {
  1809. $category_data = array(
  1810. 'group_id' => $group_id,
  1811. 'cat_name' => $this->input->post('cat_name'),
  1812. 'cat_url_title' => $this->input->post('cat_url_title'),
  1813. 'cat_description' => $this->input->post('cat_description'),
  1814. 'cat_image' => $this->input->post('cat_image'),
  1815. 'parent_id' => $this->input->post('parent_id'),
  1816. 'cat_order' => 1, // Default to the new category appearing first
  1817. 'site_id' => $this->input->post('site_id')
  1818. );
  1819. $this->db->insert('categories', $category_data);
  1820. $cat_id = $this->db->insert_id();
  1821. $update = FALSE;
  1822. // Increment each pre-existing category's sort order to make room for the n00b
  1823. $this->db->set('cat_order', 'cat_order + 1', FALSE);
  1824. $this->db->where('cat_id !=', $cat_id);
  1825. $this->db->where('group_id', $group_id);
  1826. $this->db->where('parent_id', $_POST['parent_id']);
  1827. $this->db->update('categories');
  1828. }
  1829. else
  1830. {
  1831. if ($_POST['cat_id'] == $_POST['parent_id'])
  1832. {
  1833. $_POST['parent_id'] = 0;
  1834. }
  1835. // Check for parent becoming child of its child...oy!
  1836. $this->db->select('parent_id, group_id');
  1837. $this->db->where('cat_id', $this->input->post('cat_id'));
  1838. $query = $this->db->get('categories');
  1839. if ($this->input->get_post('parent_id') !== 0 && $query->num_rows() > 0 && $query->row('parent_id') !== $this->input->get_post('parent_id'))
  1840. {
  1841. $children = array();
  1842. // Fetch parent info
  1843. $this->db->select('cat_name, cat_id, parent_id');
  1844. $this->db->where('group_id', $group_id);
  1845. $this->db->from('categories');
  1846. $this->db->order_by('parent_id, cat_name');
  1847. $query = $this->db->get();
  1848. if ($query->num_rows() == 0)
  1849. {
  1850. $update = FALSE;
  1851. return $this->category_editor($group_id, $update);
  1852. }
  1853. // Assign the query result to a multi-dimensional array
  1854. foreach($query->result_array() as $row)
  1855. {
  1856. $cat_array[$row['cat_id']] = array($row['parent_id'], $row['cat_name']);
  1857. }
  1858. foreach($cat_array as $key => $values)
  1859. {
  1860. if ($values['0'] == $this->input->post('cat_id'))
  1861. {
  1862. $children[] = $key;
  1863. }
  1864. }
  1865. if (count($children) > 0)
  1866. {
  1867. if (($key = array_search($this->input->get_post('parent_id'), $children)) !== FALSE)
  1868. {
  1869. $this->db->update(
  1870. 'categories',
  1871. array('parent_id' => $query->row('parent_id')),
  1872. array('cat_id' => $children[$key])
  1873. );
  1874. }
  1875. else // Find All Descendants
  1876. {
  1877. while(count($children) > 0)
  1878. {
  1879. $now = array_shift($children);
  1880. foreach($cat_array as $key => $values)
  1881. {
  1882. if ($values[0] == $now)
  1883. {
  1884. if ($key == $this->input->get_post('parent_id'))
  1885. {
  1886. $this->db->update(
  1887. 'categories',
  1888. array('parent_id' => $query->row('parent_id')),
  1889. array('cat_id' => $key)
  1890. );
  1891. break 2;
  1892. }
  1893. $children[] = $key;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. $sql = $this->db->update_string(
  1901. 'exp_categories',
  1902. array(
  1903. 'cat_name' => $this->input->post('cat_name'),
  1904. 'cat_url_title' => $this->input->post('cat_url_title'),
  1905. 'cat_description' => $this->input->post('cat_description'),
  1906. 'cat_image' => $this->input->post('cat_image'),
  1907. 'parent_id' => $this->input->post('parent_id')
  1908. ),
  1909. array(
  1910. 'cat_id' => $this->input->post('cat_id'),
  1911. 'group_id' => $this->input->post('group_id')
  1912. )
  1913. );
  1914. $this->db->query($sql);
  1915. $update = TRUE;
  1916. // need this later for custom fields
  1917. $cat_id = $this->input->post('cat_id');
  1918. }
  1919. // Need to re-sort alphabetically now?
  1920. $this->db->select('sort_order');
  1921. $query = $this->db->get_where('category_groups', array('group_id' => $group_id));
  1922. if ($query->num_rows() == 1 && $query->row()->sort_order == 'a')
  1923. {
  1924. $this->_reorder_cats_alphabetically($group_id);
  1925. }
  1926. // Insert / Update Custom Field Data
  1927. if ($edit == FALSE)
  1928. {
  1929. $fields['site_id'] = $this->config->item('site_id');
  1930. $fields['cat_id'] = $cat_id;
  1931. $fields['group_id'] = $group_id;
  1932. $this->db->insert('category_field_data', $fields);
  1933. }
  1934. elseif ( ! empty($fields))
  1935. {
  1936. $this->db->query($this->db->update_string('exp_category_field_data', $fields, array('cat_id' => $cat_id)));
  1937. }
  1938. $this->functions->clear_caching('relationships');
  1939. $this->session->set_flashdata('message_success', lang('preference_updated'));
  1940. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_editor'.AMP."group_id={$group_id}");
  1941. }
  1942. // --------------------------------------------------------------------
  1943. /**
  1944. * Category URL Title
  1945. *
  1946. *
  1947. *
  1948. */
  1949. function _cat_url_title($str)
  1950. {
  1951. $this->load->model('category_model');
  1952. // Is the cat_url_title a pure number? If so we show an error.
  1953. if (is_numeric($str))
  1954. {
  1955. $this->form_validation->set_message('_cat_url_title', lang('cat_url_title_is_numeric'));
  1956. return FALSE;
  1957. }
  1958. // Is the Category URL Title still empty? Can't have that
  1959. if (trim($str) == '')
  1960. {
  1961. $this->form_validation->set_message('_cat_url_title', lang('unable_to_create_cat_url_title'));
  1962. return FALSE;
  1963. }
  1964. // Cat URL Title must be unique within the group
  1965. if ($this->category_model->is_duplicate_category_name($str, $this->input->post('cat_id'), $this->input->post('group_id')))
  1966. {
  1967. $this->form_validation->set_message('_cat_url_title', lang('duplicate_cat_url_title'));
  1968. return FALSE;
  1969. }
  1970. }
  1971. // --------------------------------------------------------------------
  1972. /**
  1973. * Set Global Category Order
  1974. */
  1975. function global_category_order()
  1976. {
  1977. if (AJAX_REQUEST)
  1978. {
  1979. if ( ! $this->cp->allowed_group('can_edit_categories'))
  1980. {
  1981. show_error(lang('unauthorized_access'));
  1982. }
  1983. }
  1984. else
  1985. {
  1986. $this->_restrict_prefs_access();
  1987. }
  1988. if (($group_id = $this->input->get_post('group_id')) === FALSE OR ! is_numeric($group_id))
  1989. {
  1990. return FALSE;
  1991. }
  1992. $order = ($_POST['sort_order'] == 'a') ? 'a' : 'c';
  1993. if ($order == 'a')
  1994. {
  1995. if ( ! isset($_POST['override']))
  1996. {
  1997. return $this->global_category_order_confirm();
  1998. }
  1999. else
  2000. {
  2001. $this->_reorder_cats_alphabetically($group_id);
  2002. }
  2003. }
  2004. $this->db->where('group_id', $group_id);
  2005. $this->db->update('category_groups', array('sort_order' => $order));
  2006. $zurl = ($this->input->get_post('modal') == 'yes') ? AMP.'modal=yes' : '';
  2007. $zurl .= ($this->input->get_post('cat_group') !== FALSE) ? AMP.'cat_group='.$this->input->get_post('cat_group') : '';
  2008. $zurl .= ($this->input->get_post('integrated') !== FALSE) ? AMP.'integrated='.$this->input->get_post('integrated') : '';
  2009. // Clear 'ze cache
  2010. $this->functions->clear_caching('db');
  2011. $this->session->set_flashdata('message_success', lang('preferences_updated'));
  2012. // Return Location
  2013. $return = BASE.AMP.'C=admin_content'.AMP.'M=category_editor'.AMP.'group_id='.$group_id.$zurl;
  2014. $this->functions->redirect($return);
  2015. }
  2016. // --------------------------------------------------------------------
  2017. /**
  2018. * Category order change confirm
  2019. */
  2020. function global_category_order_confirm()
  2021. {
  2022. if (AJAX_REQUEST)
  2023. {
  2024. if ( ! $this->cp->allowed_group('can_edit_categories'))
  2025. {
  2026. show_error(lang('unauthorized_access'));
  2027. }
  2028. }
  2029. else
  2030. {
  2031. $this->_restrict_prefs_access();
  2032. }
  2033. if (($group_id = $this->input->get_post('group_id')) === FALSE OR ! is_numeric($group_id))
  2034. {
  2035. return FALSE;
  2036. }
  2037. $this->lang->loadfile('admin_content');
  2038. $this->cp->set_variable('cp_page_title', lang('global_sort_order'));
  2039. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_editor'.AMP.'group_id='.$group_id, lang('categories'));
  2040. $vars['form_action'] = 'C=admin_content'.AMP.'M=global_category_order'.AMP.'group_id='.$group_id;
  2041. $vars['form_hidden']['sort_order'] = $this->input->post('sort_order');
  2042. $vars['form_hidden']['override'] = 1;
  2043. $this->javascript->compile();
  2044. $this->load->view('admin/category_order_confirm', $vars);
  2045. }
  2046. /** --------------------------------
  2047. /** Re-order Categories Alphabetically
  2048. /** --------------------------------*/
  2049. private function _reorder_cats_alphabetically($group_id)
  2050. {
  2051. if ( ! isset($group_id) OR ! is_numeric($group_id))
  2052. {
  2053. return FALSE;
  2054. }
  2055. $data = $this->process_category_group($group_id);
  2056. if (count($data) == 0)
  2057. {
  2058. return FALSE;
  2059. }
  2060. foreach($data as $cat_id => $cat_data)
  2061. {
  2062. $this->db->query("UPDATE exp_categories SET cat_order = '{$cat_data['1']}' WHERE cat_id = '{$cat_id}'");
  2063. }
  2064. return TRUE;
  2065. }
  2066. /** --------------------------------
  2067. /** Process nested category group
  2068. /** --------------------------------*/
  2069. function process_category_group($group_id)
  2070. {
  2071. if (AJAX_REQUEST)
  2072. {
  2073. if ( ! $this->cp->allowed_group('can_edit_categories'))
  2074. {
  2075. show_error(lang('unauthorized_access'));
  2076. }
  2077. }
  2078. else
  2079. {
  2080. $this->_restrict_prefs_access();
  2081. }
  2082. $this->db->select('cat_name, cat_id, parent_id');
  2083. $this->db->where('group_id', $group_id);
  2084. $this->db->order_by('parent_id, cat_name');
  2085. $categories = $this->db->get('categories');
  2086. if ($categories->num_rows() == 0)
  2087. {
  2088. return FALSE;
  2089. }
  2090. $order = 0;
  2091. $parent = 0;
  2092. foreach($categories->result_array() as $category)
  2093. {
  2094. // Once we're on a new parent, reset the ordering
  2095. if ($category['parent_id'] != $parent)
  2096. {
  2097. $order = 0;
  2098. $parent = $category['parent_id'];
  2099. }
  2100. $order++;
  2101. $this->cat_update[$category['cat_id']] = array(
  2102. $category['parent_id'],
  2103. $order,
  2104. $category['cat_name']
  2105. );
  2106. }
  2107. return $this->cat_update;
  2108. }
  2109. // ------------------------------------------------------------------------
  2110. /**
  2111. * Change Category Order
  2112. */
  2113. function change_category_order()
  2114. {
  2115. if (AJAX_REQUEST)
  2116. {
  2117. if ( ! $this->cp->allowed_group('can_edit_categories'))
  2118. {
  2119. show_error(lang('unauthorized_access'));
  2120. }
  2121. }
  2122. else
  2123. {
  2124. $this->_restrict_prefs_access();
  2125. }
  2126. // Fetch required globals
  2127. foreach (array('cat_id', 'group_id', 'order') as $val)
  2128. {
  2129. if ( ! $this->input->get($val))
  2130. {
  2131. return FALSE;
  2132. }
  2133. if ($val == 'cat_id' OR $val == 'group_id')
  2134. {
  2135. $$val = (int) $this->input->get($val);
  2136. }
  2137. else
  2138. {
  2139. $order = $this->input->get('order');
  2140. }
  2141. }
  2142. // Return Location
  2143. $return = BASE.AMP.'C=admin_content'.AMP.'M=category_editor'.AMP.'group_id='.$group_id;
  2144. // Fetch the parent ID
  2145. $qry = $this->db->select('parent_id')
  2146. ->where('cat_id', $cat_id)
  2147. ->get('categories');
  2148. $parent_id = $qry->row('parent_id');
  2149. // Is the requested category already at the beginning/end of the list?
  2150. $dir = ($order == 'up') ? 'asc' : 'desc';
  2151. $qry = $this->db->select('cat_id')
  2152. ->where('group_id', $group_id)
  2153. ->where('parent_id', $parent_id)
  2154. ->order_by('cat_order', $dir)
  2155. ->limit(1)
  2156. ->get('categories');
  2157. if ($qry->row('cat_id') == $cat_id)
  2158. {
  2159. $this->functions->redirect($return);
  2160. }
  2161. // Fetch all the categories in the parent
  2162. $this->db->select('cat_id, cat_order');
  2163. $this->db->where('group_id', $group_id);
  2164. $this->db->where('parent_id', $parent_id);
  2165. $this->db->order_by('cat_order ASC');
  2166. $query = $this->db->get('categories');
  2167. // If there is only one category, there is nothing to re-order
  2168. if ($query->num_rows() <= 1)
  2169. {
  2170. $this->functions->redirect($return);
  2171. }
  2172. // Assign category ID numbers in an array except the category being shifted.
  2173. // We will also set the position number of the category being shifted, which
  2174. // we'll use in array_shift()
  2175. $flag = '';
  2176. $i = 1;
  2177. $cats = array();
  2178. foreach ($query->result_array() as $row)
  2179. {
  2180. if ($cat_id == $row['cat_id'])
  2181. {
  2182. $flag = ($order == 'down') ? $i+1 : $i-1;
  2183. }
  2184. else
  2185. {
  2186. $cats[] = $row['cat_id'];
  2187. }
  2188. $i++;
  2189. }
  2190. array_splice($cats, ($flag -1), 0, $cat_id);
  2191. // Update the category order for all the categories within the given parent
  2192. $i = 1;
  2193. foreach ($cats as $val)
  2194. {
  2195. $this->db->where('cat_id', $val);
  2196. $this->db->update('categories', array('cat_order' => $i));
  2197. $i++;
  2198. }
  2199. // Switch to custom order
  2200. $this->db->where("group_id", $group_id);
  2201. $this->db->update('category_groups', array('sort_order' => 'c'));
  2202. $this->session->set_flashdata('message_success', lang('preferences_updated'));
  2203. $this->functions->redirect($return);
  2204. }
  2205. // --------------------------------------------------------------------
  2206. /**
  2207. * Category Field Group Form
  2208. *
  2209. * This function displays the field group management form
  2210. * and allows you to delete, modify, or create a
  2211. * category custom field
  2212. */
  2213. function category_custom_field_group_manager($message = '')
  2214. {
  2215. $this->_restrict_prefs_access();
  2216. $vars['message'] = $message; //lang('preferences_updated')
  2217. $vars['group_id'] = $this->input->get_post('group_id');
  2218. if ($vars['group_id'] == '' OR ! is_numeric($vars['group_id']))
  2219. {
  2220. show_error(lang('not_authorized'));
  2221. }
  2222. $this->load->library('table');
  2223. $this->lang->loadfile('admin_content');
  2224. $this->load->model('category_model');
  2225. $this->cp->set_variable('cp_page_title', lang('custom_category_fields'));
  2226. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  2227. // Fetch the name of the category group
  2228. $query = $this->category_model->get_category_group_name($vars['group_id']);
  2229. $vars['group_name'] = $query->row('group_name');
  2230. $this->db->select('field_id, field_name, field_label, field_type, field_order');
  2231. $this->db->from('category_fields');
  2232. $this->db->where('group_id', $vars['group_id']);
  2233. $this->db->order_by('field_order');
  2234. $custom_fields = $this->db->get();
  2235. $vars['custom_fields'] = array();
  2236. if ($custom_fields->num_rows() > 0)
  2237. {
  2238. foreach ($custom_fields->result() as $row)
  2239. {
  2240. $vars['custom_fields'][$row->field_id]['field_id'] = $row->field_id;
  2241. $vars['custom_fields'][$row->field_id]['field_name'] = $row->field_name;
  2242. $vars['custom_fields'][$row->field_id]['field_order'] = $row->field_order;
  2243. $vars['custom_fields'][$row->field_id]['field_label'] = $row->field_label;
  2244. switch ($row->field_type)
  2245. {
  2246. case 'text' : $field_type = lang('text_input');
  2247. break;
  2248. case 'textarea' : $field_type = lang('textarea');
  2249. break;
  2250. case 'select' : $field_type = lang('select_list');
  2251. break;
  2252. }
  2253. $vars['custom_fields'][$row->field_id]['field_type'] = $field_type;
  2254. }
  2255. }
  2256. $this->jquery->tablesorter('.mainTable', '{
  2257. headers: {3: {sorter: false}},
  2258. widgets: ["zebra"]
  2259. }');
  2260. $this->javascript->compile();
  2261. $this->load->view('admin/category_custom_field_group_manager', $vars);
  2262. }
  2263. // --------------------------------------------------------------------
  2264. /**
  2265. * Edit Custom Category Field
  2266. *
  2267. * Used to edit or create a custom category field
  2268. *
  2269. * @access public
  2270. * @return void
  2271. */
  2272. function edit_custom_category_field()
  2273. {
  2274. $this->_restrict_prefs_access();
  2275. $vars['group_id'] = $this->input->get_post('group_id');
  2276. $group_id = $vars['group_id'];
  2277. $vars['field_id'] = $this->input->get_post('field_id');
  2278. $field_id = $vars['field_id'];
  2279. if ($vars['group_id'] == '' OR ! is_numeric($vars['group_id']))
  2280. {
  2281. show_error(lang('not_authorized'));
  2282. }
  2283. $this->load->model('addons_model');
  2284. $this->load->helper('snippets_helper');
  2285. $this->lang->loadfile('admin_content');
  2286. $this->load->library('table');
  2287. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  2288. $this->javascript->change('#field_type', '
  2289. // hide all field format options
  2290. $(".field_format_option").hide();
  2291. // reveal selected option
  2292. $("#"+$(this).val()+"_format").show();
  2293. ');
  2294. if ($vars['field_id'] == '')
  2295. {
  2296. $vars['update_formatting'] = FALSE;
  2297. $this->cp->set_variable('cp_page_title', lang('create_new_cat_field'));
  2298. $vars['submit_lang_key'] = 'submit';
  2299. $this->db->select('group_id');
  2300. $this->db->where('group_id', $vars['group_id']);
  2301. $query = $this->db->get('category_fields');
  2302. $vars['field_order'] = $query->num_rows() + 1;
  2303. $field_id = '';
  2304. if ($query->num_rows() > 0)
  2305. {
  2306. $group_id = $query->row('group_id') ;
  2307. }
  2308. else
  2309. {
  2310. // if there are no existing category fields yet for this group,
  2311. // this allows us to still validate the group_id
  2312. $this->db->select('COUNT(*) AS count');
  2313. $this->db->where('group_id', $group_id);
  2314. $this->db->where('site_id', $this->config->item('site_id'));
  2315. $gquery = $this->db->get('category_groups');
  2316. if ($gquery->row('count') != 1)
  2317. {
  2318. show_error(lang('unauthorized_access'));
  2319. }
  2320. }
  2321. }
  2322. else
  2323. {
  2324. $vars['update_formatting'] = TRUE;
  2325. $this->javascript->output('$(".formatting_notice_info").hide();');
  2326. $this->cp->set_variable('cp_page_title', lang('edit_cat_field'));
  2327. $vars['submit_lang_key'] = 'update';
  2328. $this->javascript->change('#field_default_fmt', '
  2329. // give formatting change notice and checkbox
  2330. $(".formatting_notice_info").show();
  2331. $("#show_formatting_buttons").show();
  2332. ');
  2333. $this->db->select('field_id, group_id');
  2334. $this->db->where('group_id', $group_id);
  2335. $this->db->where('field_id', $field_id);
  2336. $query = $this->db->get('category_fields');
  2337. $vars['field_order'] = '';
  2338. if ($query->num_rows() == 0)
  2339. {
  2340. return FALSE;
  2341. }
  2342. $field_id = $query->row('field_id') ;
  2343. $group_id = $query->row('group_id') ;
  2344. $vars['form_hidden']['field_id'] = $field_id;
  2345. }
  2346. $query = $this->db->query("SELECT f.field_id, f.field_name, f.site_id, f.field_label, f.field_type, f.field_default_fmt, f.field_show_fmt,
  2347. f.field_list_items, f.field_maxl, f.field_ta_rows, f.field_text_direction, f.field_required, f.field_order,
  2348. g.group_name
  2349. FROM exp_category_fields AS f, exp_category_groups AS g
  2350. WHERE f.group_id = g.group_id
  2351. AND g.group_id = '{$group_id}'
  2352. AND f.field_id = '{$field_id}'");
  2353. $data = array();
  2354. if ($query->num_rows() == 0)
  2355. {
  2356. foreach ($query->list_fields() as $f)
  2357. {
  2358. $data[$f] = '';
  2359. $$f = '';
  2360. $vars[$f] = '';
  2361. }
  2362. }
  2363. else
  2364. {
  2365. foreach ($query->row_array() as $key => $val)
  2366. {
  2367. $data[$key] = $val;
  2368. $$key = $val;
  2369. $vars[$key] = $val;
  2370. }
  2371. }
  2372. // Adjust $group_name for new custom fields as we display this later
  2373. if ($group_name == '')
  2374. {
  2375. $query = $this->db->query("SELECT group_name FROM exp_category_groups WHERE group_id = '{$group_id}'");
  2376. if ($query->num_rows() > 0)
  2377. {
  2378. $group_name = $query->row('group_name') ;
  2379. }
  2380. }
  2381. $vars['form_hidden']['group_id'] = $vars['group_id'];
  2382. $vars['field_maxl'] = ($vars['field_maxl'] == '') ? 128 : $vars['field_maxl'];
  2383. $vars['field_ta_rows'] = ($vars['field_ta_rows'] == '') ? 6 : $vars['field_ta_rows'];
  2384. $vars['field_type_options'] = array(
  2385. 'text' => lang('text_input'),
  2386. 'textarea' => lang('textarea'),
  2387. 'select' => lang('select_list')
  2388. );
  2389. // Show field formatting?
  2390. if ($vars['field_show_fmt'] == 'n')
  2391. {
  2392. $vars['field_show_fmt_y'] = FALSE;
  2393. $vars['field_show_fmt_n'] = TRUE;
  2394. }
  2395. else
  2396. {
  2397. $vars['field_show_fmt_y'] = TRUE;
  2398. $vars['field_show_fmt_n'] = FALSE;
  2399. }
  2400. // build list of formatting options
  2401. $vars['field_default_fmt_options']['none'] = lang('none');
  2402. // Fetch formatting plugins
  2403. $plugin_formatting = $this->addons_model->get_plugin_formatting();
  2404. foreach ($plugin_formatting as $k=>$v)
  2405. {
  2406. $vars['field_default_fmt_options'][$k] = $v;
  2407. }
  2408. // Text Direction
  2409. if ($vars['field_text_direction'] == 'rtl')
  2410. {
  2411. $vars['field_text_direction_ltr'] = FALSE;
  2412. $vars['field_text_direction_rtl'] = TRUE;
  2413. }
  2414. else
  2415. {
  2416. $vars['field_text_direction_ltr'] = TRUE;
  2417. $vars['field_text_direction_rtl'] = FALSE;
  2418. }
  2419. // Is field required?
  2420. if ($vars['field_required'] == 'n')
  2421. {
  2422. $vars['field_required_y'] = FALSE;
  2423. $vars['field_required_n'] = TRUE;
  2424. }
  2425. else
  2426. {
  2427. $vars['field_required_y'] = TRUE;
  2428. $vars['field_required_n'] = FALSE;
  2429. }
  2430. // Hide/show field formatting options
  2431. $this->javascript->output('
  2432. // hide all field format options
  2433. $(".field_format_option").hide();
  2434. // reveal text as default
  2435. $("#'.$vars['field_type'].'_format").show();
  2436. // if the formatting changes, we can reveal this option
  2437. $("#formatting_notice").hide();
  2438. ');
  2439. $this->javascript->compile();
  2440. $this->load->view('admin/edit_custom_category_field', $vars);
  2441. }
  2442. // --------------------------------------------------------------------
  2443. /** -----------------------------------------------------------
  2444. /** Update Category Fields
  2445. /** -----------------------------------------------------------*/
  2446. // This function updates or creates category fields
  2447. //-----------------------------------------------------------
  2448. function update_custom_category_fields()
  2449. {
  2450. $this->_restrict_prefs_access();
  2451. // Are we editing or creating?
  2452. $edit = (($field_id = $this->input->get_post('field_id')) !== FALSE AND is_numeric($field_id)) ? TRUE : FALSE;
  2453. $group_id = $this->input->get_post('group_id');
  2454. if ($group_id == '' OR ! is_numeric($group_id))
  2455. {
  2456. show_error(lang('unauthorized_access'));
  2457. }
  2458. $this->lang->loadfile('admin_content');
  2459. unset($_POST['custom_field_edit']); // submit button
  2460. // Check for required fields
  2461. $error = array();
  2462. if ($_POST['field_name'] == '')
  2463. {
  2464. $error[] = lang('no_field_name');
  2465. }
  2466. else
  2467. {
  2468. // Is the field one of the reserved words?
  2469. if (in_array($_POST['field_name'], $this->cp->invalid_custom_field_names()))
  2470. {
  2471. $error[] = lang('reserved_word');
  2472. }
  2473. $field_name = $_POST['field_name'];
  2474. }
  2475. if ($_POST['field_label'] == '')
  2476. {
  2477. $error[] = lang('no_field_label');
  2478. }
  2479. // Does field name contain invalid characters?
  2480. if (preg_match('/[^a-z0-9\_\-]/i', $_POST['field_name']))
  2481. {
  2482. $error[] = lang('invalid_characters');
  2483. }
  2484. // Field name must be unique for across category groups
  2485. if ($edit == FALSE)
  2486. {
  2487. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_category_fields WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."' AND field_name = '".$this->db->escape_str($_POST['field_name'])."'");
  2488. if ($query->row('count') > 0)
  2489. {
  2490. $error[] = lang('duplicate_field_name');
  2491. }
  2492. }
  2493. // Are there errors to display?
  2494. if (count($error) > 0)
  2495. {
  2496. $str = '';
  2497. foreach ($error as $msg)
  2498. {
  2499. $str .= $msg.BR;
  2500. }
  2501. show_error($str);
  2502. }
  2503. if ($_POST['field_list_items'] != '')
  2504. {
  2505. // Load the string helper
  2506. $this->load->helper('string');
  2507. $_POST['field_list_items'] = quotes_to_entities($_POST['field_list_items']);
  2508. }
  2509. if ( ! in_array($_POST['field_type'], array('text', 'textarea', 'select')))
  2510. {
  2511. $_POST['field_text_direction'] = 'ltr';
  2512. }
  2513. // Construct the query based on whether we are updating or inserting
  2514. if ($edit === TRUE)
  2515. {
  2516. // validate field id
  2517. $query = $this->db->query("SELECT field_id FROM exp_category_fields WHERE group_id = '".$this->db->escape_str($group_id)."' AND field_id = '".$this->db->escape_str($field_id)."'");
  2518. if ($query->num_rows() == 0)
  2519. {
  2520. return FALSE;
  2521. }
  2522. // Update the formatting for all existing entries
  2523. if (isset($_POST['update_formatting']))
  2524. {
  2525. $this->db->query("UPDATE exp_category_field_data SET field_ft_{$field_id} = '".$this->db->escape_str($_POST['field_default_fmt'])."'");
  2526. }
  2527. unset($_POST['group_id']);
  2528. unset($_POST['update_formatting']);
  2529. $this->db->query($this->db->update_string('exp_category_fields', $_POST, "field_id='".$field_id."'"));
  2530. $cp_message = lang('cat_field_edited');
  2531. }
  2532. else
  2533. {
  2534. unset($_POST['update_formatting']);
  2535. if ($_POST['field_order'] == 0 OR $_POST['field_order'] == '')
  2536. {
  2537. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_category_fields WHERE group_id = '".$this->db->escape_str($group_id)."'");
  2538. $_POST['field_order'] = $query->num_rows() + 1;
  2539. }
  2540. $_POST['site_id'] = $this->config->item('site_id');
  2541. $this->db->insert('category_fields', $_POST);
  2542. $insert_id = $this->db->insert_id();
  2543. $this->db->query("ALTER TABLE exp_category_field_data ADD COLUMN field_id_{$insert_id} text NULL");
  2544. $this->db->query("ALTER TABLE exp_category_field_data ADD COLUMN field_ft_{$insert_id} varchar(40) NULL default 'none'");
  2545. $this->db->query("UPDATE exp_category_field_data SET field_ft_{$insert_id} = '".$this->db->escape_str($_POST['field_default_fmt'])."'");
  2546. $cp_message = lang('cat_field_created');
  2547. }
  2548. $this->functions->clear_caching('all', '', TRUE);
  2549. $this->session->set_flashdata('message_success', $cp_message.' '.$field_name);
  2550. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_custom_field_group_manager'.AMP.'group_id='.$group_id);
  2551. }
  2552. // --------------------------------------------------------------------
  2553. /**
  2554. * Delete Category Custom Field Confirmation
  2555. *
  2556. * This function displays a confirmation form for deleting
  2557. * a category custom field
  2558. */
  2559. function delete_custom_category_field_confirm()
  2560. {
  2561. $this->_restrict_prefs_access();
  2562. $group_id = $this->input->get_post('group_id');
  2563. if ($group_id == '' OR ! is_numeric($group_id))
  2564. {
  2565. show_error(lang('not_authorized'));
  2566. }
  2567. $field_id = $this->input->get_post('field_id');
  2568. if ($field_id == '' OR ! is_numeric($field_id))
  2569. {
  2570. show_error(lang('not_authorized'));
  2571. }
  2572. $this->lang->loadfile('admin_content');
  2573. $this->load->model('category_model');
  2574. $this->cp->set_variable('cp_page_title', lang('delete_field'));
  2575. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=category_management', lang('categories'));
  2576. $vars['form_action'] = 'C=admin_content'.AMP.'M=delete_custom_category_field';
  2577. $vars['form_extra'] = '';
  2578. $vars['form_hidden']['group_id'] = $group_id;
  2579. $vars['form_hidden']['field_id'] = $field_id;
  2580. $vars['message'] = lang('delete_cat_field_confirmation');
  2581. // Grab category_groups locations with this id
  2582. $items = $this->category_model->get_category_label_name($group_id, $field_id);
  2583. $vars['items'] = array();
  2584. foreach($items->result() as $item)
  2585. {
  2586. $vars['items'][] = $item->field_label;
  2587. }
  2588. $this->javascript->compile();
  2589. $this->load->view('admin/preference_delete_confirm', $vars);
  2590. }
  2591. // --------------------------------------------------------------------
  2592. /**
  2593. * Delete Custom Category Field
  2594. *
  2595. * This function deletes a category field
  2596. */
  2597. function delete_custom_category_field()
  2598. {
  2599. $this->_restrict_prefs_access();
  2600. $group_id = $this->input->get_post('group_id');
  2601. if ($group_id == '' OR ! is_numeric($group_id))
  2602. {
  2603. show_error(lang('not_authorized'));
  2604. }
  2605. $field_id = $this->input->get_post('field_id');
  2606. if ($field_id == '' OR ! is_numeric($field_id))
  2607. {
  2608. show_error(lang('not_authorized'));
  2609. }
  2610. $this->load->model('category_model');
  2611. $this->lang->loadfile('admin_content');
  2612. $query = $this->category_model->get_category_label_name($group_id, $field_id);
  2613. if ($query->num_rows() == 0)
  2614. {
  2615. show_error(lang('unauthorized_access'));
  2616. }
  2617. $this->category_model->delete_category_field($group_id, $field_id);
  2618. $cp_message = lang('cat_field_deleted').NBS.$query->row('field_label');
  2619. $this->logger->log_action($cp_message);
  2620. $this->functions->clear_caching('all', '', TRUE);
  2621. $this->session->set_flashdata('message_success', $cp_message);
  2622. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=category_custom_field_group_manager'.AMP.'group_id='.$group_id);
  2623. }
  2624. // --------------------------------------------------------------------
  2625. /**
  2626. * Field Group Management
  2627. *
  2628. * This function show the "Custom channel fields" overview page, accessed via the "admin" tab
  2629. *
  2630. * @access public
  2631. * @return void
  2632. */
  2633. function field_group_management($message = '')
  2634. {
  2635. $this->_restrict_prefs_access();
  2636. $this->load->library('table');
  2637. $this->load->model('field_model');
  2638. $this->lang->loadfile('admin_content');
  2639. $this->cp->set_variable('cp_page_title', lang('field_management'));
  2640. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content', lang('admin_content'));
  2641. $this->jquery->tablesorter('.mainTable', '{
  2642. headers: {1: {sorter: false}, 2: {sorter: false}},
  2643. widgets: ["zebra"]
  2644. }');
  2645. $this->javascript->compile();
  2646. $vars['message'] = $message;
  2647. $vars['field_groups'] = $this->field_model->get_field_groups(); // Fetch field groups
  2648. $this->cp->set_right_nav(array('create_new_field_group' => BASE.AMP.'C=admin_content'.AMP.'M=field_group_edit'));
  2649. $this->load->view('admin/field_group_management', $vars);
  2650. }
  2651. // --------------------------------------------------------------------
  2652. /**
  2653. * Field Group Edit
  2654. *
  2655. * Creates the Edit Field Group page
  2656. *
  2657. * @access public
  2658. * @return void
  2659. */
  2660. function field_group_edit()
  2661. {
  2662. $this->_restrict_prefs_access();
  2663. $this->load->model('status_model');
  2664. $this->lang->loadfile('admin_content');
  2665. $this->load->model('field_model');
  2666. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management', lang('field_management'));
  2667. // Set default values
  2668. $vars['group_name'] = '';
  2669. $vars['form_hidden'] = array();
  2670. // If we have the group_id variable it's an edit request, so fetch the status data
  2671. $group_id = $this->input->get_post('group_id');
  2672. if ($group_id != '')
  2673. {
  2674. $this->cp->set_variable('cp_page_title', lang('rename_group'));
  2675. $vars['form_hidden']['group_id'] = $group_id;
  2676. $vars['submit_lang_key'] = 'update';
  2677. if ( ! is_numeric($group_id))
  2678. {
  2679. show_error(lang('not_authorized'));
  2680. }
  2681. $query = $this->field_model->get_field_group($group_id);
  2682. foreach ($query->row() as $key => $val)
  2683. {
  2684. $vars[$key] = $val;
  2685. }
  2686. }
  2687. else
  2688. {
  2689. $this->cp->set_variable('cp_page_title', lang('new_field_group'));
  2690. $vars['submit_lang_key'] = 'submit';
  2691. }
  2692. $this->javascript->compile();
  2693. $this->load->view('admin/field_group_edit', $vars);
  2694. }
  2695. // --------------------------------------------------------------------
  2696. /**
  2697. * Field Group Delete Confirm
  2698. *
  2699. * Warning message shown when you try to delete a field group
  2700. *
  2701. * @access public
  2702. * @return mixed
  2703. */
  2704. function field_group_delete_confirm()
  2705. {
  2706. $this->_restrict_prefs_access();
  2707. $group_id = $this->input->get_post('group_id');
  2708. if ($group_id == '' OR ! is_numeric($group_id))
  2709. {
  2710. show_error(lang('not_authorized'));
  2711. }
  2712. $this->lang->loadfile('admin_content');
  2713. $this->load->model('field_model');
  2714. $this->cp->set_variable('cp_page_title', lang('delete_group'));
  2715. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management', lang('field_management'));
  2716. $vars['form_action'] = 'C=admin_content'.AMP.'M=field_group_delete';
  2717. $vars['form_extra'] = '';
  2718. $vars['form_hidden']['group_id'] = $group_id;
  2719. $vars['message'] = lang('delete_field_group_confirmation');
  2720. // Grab category_groups locations with this id
  2721. $items = $this->field_model->get_field_group($group_id);
  2722. $vars['items'] = array();
  2723. foreach($items->result() as $item)
  2724. {
  2725. $vars['items'][] = $item->group_name;
  2726. }
  2727. $this->javascript->compile();
  2728. $this->load->view('admin/preference_delete_confirm', $vars);
  2729. }
  2730. // --------------------------------------------------------------------
  2731. /**
  2732. * Field Group Delete
  2733. *
  2734. * Deletes Field Groups
  2735. *
  2736. * @access public
  2737. * @return void
  2738. */
  2739. function field_group_delete()
  2740. {
  2741. $this->_restrict_prefs_access();
  2742. $group_id = $this->input->get_post('group_id');
  2743. $tabs = array();
  2744. if ($group_id == '' OR ! is_numeric($group_id))
  2745. {
  2746. show_error(lang('not_authorized'));
  2747. }
  2748. $this->load->model('field_model');
  2749. $this->lang->loadfile('admin_content');
  2750. // store the name for the delete message
  2751. $group_name = $this->field_model->get_field_group($group_id);
  2752. // delete routine
  2753. $deleted = $this->field_model->delete_field_groups($group_id);
  2754. // Drop from custom layouts
  2755. $query = $this->field_model->get_assigned_channels($group_id);
  2756. if ($query->num_rows() > 0 && isset($deleted['field_ids']) && count($deleted['field_ids']) > 0)
  2757. {
  2758. foreach ($query->result() as $row)
  2759. {
  2760. $channel_ids[] = $row->channel_id;
  2761. }
  2762. $this->load->library('layout');
  2763. $this->layout->delete_layout_fields($deleted['field_ids'], $channel_ids);
  2764. }
  2765. $this->functions->clear_caching('all', '', TRUE);
  2766. $cp_message = lang('field_group_deleted').NBS.NBS.$group_name->row('group_name');
  2767. $this->logger->log_action($cp_message);
  2768. $this->session->set_flashdata('message_success', $cp_message);
  2769. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management');
  2770. }
  2771. // --------------------------------------------------------------------
  2772. /**
  2773. * Field Group Update
  2774. *
  2775. * This function receives the submitted field group data
  2776. * and puts it in the database
  2777. *
  2778. * @access public
  2779. * @return void
  2780. */
  2781. function field_group_update()
  2782. {
  2783. $this->_restrict_prefs_access();
  2784. $group_id = $this->input->get_post('group_id');
  2785. // If the $group_id variable is present we are editing an
  2786. // existing group, otherwise we are creating a new one
  2787. $edit = (isset($_POST['group_id'])) ? TRUE : FALSE;
  2788. $group_name = $this->input->post('group_name');
  2789. if ($group_name == '')
  2790. {
  2791. return $this->field_group_edit();
  2792. }
  2793. $this->lang->loadfile('admin_content');
  2794. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $group_name))
  2795. {
  2796. show_error(lang('illegal_characters'));
  2797. }
  2798. $this->load->model('field_model');
  2799. // Is the group name taken?
  2800. if ($this->field_model->is_duplicate_field_group_name($group_name, $group_id))
  2801. {
  2802. show_error(lang('taken_field_group_name'));
  2803. }
  2804. // Construct the query based on whether we are updating or inserting
  2805. if ($edit === FALSE)
  2806. {
  2807. $this->field_model->insert_field_group($group_name);
  2808. $cp_message = lang('field_group_created').NBS.$group_name;
  2809. $this->logger->log_action($cp_message);
  2810. $this->db->select('channel_id');
  2811. $this->db->where('site_id', $this->config->item('site_id'));
  2812. $channel_info = $this->db->get('channels');
  2813. $query = $this->db->query("SELECT channel_id from exp_channels WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."'");
  2814. if ($channel_info->num_rows() > 0)
  2815. {
  2816. $cp_message .= '<br />'.lang('assign_group_to_channel').NBS;
  2817. if ($channel_info->num_rows() == 1)
  2818. {
  2819. $link = 'C=admin_content'.AMP.'M=channel_edit_group_assignments'.AMP.'channel_id='.$channel_info->row('channel_id');
  2820. $cp_message .= '<a href="'.BASE.AMP.$link.'">'.lang('click_to_assign_group').'</a>';
  2821. }
  2822. else
  2823. {
  2824. $link = 'C=admin_content';
  2825. }
  2826. }
  2827. }
  2828. else
  2829. {
  2830. $data = array(
  2831. 'group_name' => $group_name,
  2832. 'site_id' => $this->config->item('site_id')
  2833. );
  2834. $this->db->where('group_id', $group_id);
  2835. $this->db->update('field_groups', $data);
  2836. $cp_message = lang('field_group_updated').NBS.$group_name;
  2837. }
  2838. $this->session->set_flashdata('message_success', $cp_message);
  2839. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management');
  2840. }
  2841. // --------------------------------------------------------------------
  2842. /**
  2843. * Add or Edit Field Group
  2844. *
  2845. * This function show a list of current fields in a group
  2846. *
  2847. * @access public
  2848. * @return void
  2849. */
  2850. function field_management($group_id = '', $message = '')
  2851. {
  2852. $this->_restrict_prefs_access();
  2853. $vars['group_id'] = ($group_id != '') ? $group_id : $this->input->get_post('group_id');
  2854. if ($vars['group_id'] == '' OR ! is_numeric($vars['group_id']))
  2855. {
  2856. show_error(lang('not_authorized'));
  2857. }
  2858. $this->cp->set_right_nav(array(
  2859. 'create_new_custom_field' =>
  2860. BASE.AMP.'C=admin_content'.AMP.'M=field_edit'.AMP.'group_id='.$vars['group_id']
  2861. ));
  2862. $vars['message'] = $message; //lang('preferences_updated')
  2863. $this->load->library('table');
  2864. $this->lang->loadfile('admin_content');
  2865. $this->load->model('field_model');
  2866. // Fetch the name of the category group
  2867. $query = $this->field_model->get_field_group($vars['group_id']);
  2868. $vars['group_name'] = $query->row('group_name');
  2869. $this->cp->set_variable('cp_page_title', lang('group').':'.NBS.$vars['group_name']);
  2870. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management', lang('field_management'));
  2871. $custom_fields = $this->field_model->get_fields($vars['group_id'], array('site_id' => $this->config->item('site_id')));
  2872. $vars['custom_fields'] = array();
  2873. if ($custom_fields->num_rows() > 0)
  2874. {
  2875. $this->load->library('api');
  2876. $this->api->instantiate('channel_fields');
  2877. $fts = $this->api_channel_fields->fetch_all_fieldtypes();
  2878. foreach ($custom_fields->result() as $row)
  2879. {
  2880. $vars['custom_fields'][$row->field_id]['field_id'] = $row->field_id;
  2881. $vars['custom_fields'][$row->field_id]['field_name'] = $row->field_name;
  2882. $vars['custom_fields'][$row->field_id]['field_order'] = $row->field_order;
  2883. $vars['custom_fields'][$row->field_id]['field_label'] = $row->field_label;
  2884. $vars['custom_fields'][$row->field_id]['field_type'] = $fts[$row->field_type]['name'];
  2885. }
  2886. }
  2887. $this->jquery->tablesorter('.mainTable', '{
  2888. headers: {4: {sorter: false}},
  2889. widgets: ["zebra"]
  2890. }');
  2891. $this->cp->add_js_script('file', 'cp/custom_fields');
  2892. $this->javascript->compile();
  2893. $this->load->view('admin/field_management', $vars);
  2894. }
  2895. // --------------------------------------------------------------------
  2896. /**
  2897. * Add or Edit Field
  2898. *
  2899. * This function lets you edit an existing custom field
  2900. *
  2901. * @access public
  2902. * @return void
  2903. */
  2904. function field_edit()
  2905. {
  2906. $this->_restrict_prefs_access();
  2907. $this->load->library('table');
  2908. $this->load->library('api');
  2909. $this->load->helper(array('snippets_helper', 'form'));
  2910. $this->api->instantiate('channel_fields');
  2911. $this->lang->loadfile('admin_content');
  2912. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management', lang('field_management'));
  2913. $group_id = $this->input->get_post('group_id');
  2914. $field_id = $this->input->get_post('field_id');
  2915. if ($field_id == '')
  2916. {
  2917. $type = 'new';
  2918. $this->cp->set_variable('cp_page_title', lang('create_new_custom_field'));
  2919. }
  2920. else
  2921. {
  2922. $type = 'edit';
  2923. $this->cp->set_variable('cp_page_title', lang('edit_field'));
  2924. }
  2925. $vars = $this->api_channel_fields->field_edit_vars($group_id, $field_id);
  2926. if ($vars === FALSE)
  2927. {
  2928. show_error(lang('unauthorized_access'));
  2929. }
  2930. if ($type == 'new') {
  2931. $this->cp->add_js_script('plugin', 'ee_url_title');
  2932. $this->javascript->output('
  2933. $("#edit_group_prefs").hide();
  2934. $("#field_label").bind("keyup keydown", function() {
  2935. $(this).ee_url_title("#field_name", true);
  2936. });
  2937. ');
  2938. }
  2939. $this->javascript->output('
  2940. var ft_divs = $("'.$vars['ft_selector'].'"),
  2941. ft_dropdown = $("#field_type");
  2942. ft_dropdown.change(function() {
  2943. ft_divs.hide();
  2944. $("#ft_"+this.value)
  2945. .show()
  2946. .trigger("activate")
  2947. .find("table").trigger("applyWidgets");
  2948. $("#field_pre_populate_'.$vars['field_pre_populate'].'").trigger("click");
  2949. });
  2950. ft_dropdown.trigger("change");
  2951. ');
  2952. $this->jquery->tablesorter('.mainTable', '{
  2953. headers: {0: {sorter: false}, 1: {sorter: false}},
  2954. widgets: ["zebra"]
  2955. }');
  2956. $this->javascript->compile();
  2957. $this->load->view('admin/field_edit', $vars);
  2958. }
  2959. // --------------------------------------------------------------------
  2960. /**
  2961. * Field submission handler
  2962. *
  2963. * This function receives the submitted status data and inserts it in the database.
  2964. *
  2965. * @access public
  2966. * @return mixed
  2967. */
  2968. function field_update()
  2969. {
  2970. $this->_restrict_prefs_access();
  2971. if ( ! isset($_POST['group_id']))
  2972. {
  2973. show_error(lang('unauthorized_access'));
  2974. }
  2975. $this->lang->loadfile('admin_content');
  2976. $this->load->library('api');
  2977. $this->api->instantiate('channel_fields');
  2978. // If the $field_id variable has data we are editing an
  2979. // existing group, otherwise we are creating a new one
  2980. $edit = ( ! isset($_POST['field_id']) OR $_POST['field_id'] == '') ? FALSE : TRUE;
  2981. // We need this as a variable as we'll unset the array index
  2982. $group_id = $this->input->post('group_id');
  2983. //perform the field update
  2984. $this->api_channel_fields->update_field($_POST);
  2985. // Are there errors to display?
  2986. if ($this->api_channel_fields->error_count() > 0)
  2987. {
  2988. $str = '';
  2989. foreach ($this->api_channel_fields->errors as $msg)
  2990. {
  2991. $str .= $msg.BR;
  2992. }
  2993. show_error($str);
  2994. }
  2995. $cp_message = ($edit) ? lang('custom_field_edited') : lang('custom_field_created');
  2996. $strlen = strlen($this->input->post('field_name'));
  2997. if ($strlen > 32)
  2998. {
  2999. $this->session->set_flashdata('message_failure', lang('field_name_too_lrg'));
  3000. }
  3001. else
  3002. {
  3003. $this->session->set_flashdata('message_success', $cp_message);
  3004. }
  3005. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=field_management'.AMP.'group_id='.$group_id);
  3006. }
  3007. // --------------------------------------------------------------------
  3008. /**
  3009. * Get fieldtype specific post data
  3010. *
  3011. * Different from input->post in that it checks for a fieldtype prefixed
  3012. * value as well.
  3013. *
  3014. * @access public
  3015. * @param fieldtype, key
  3016. * @return mixed
  3017. */
  3018. function _get_ft_post_data($field_type, $key)
  3019. {
  3020. return (isset($_POST[$key])) ? $_POST[$key] : $this->input->post($field_type.'_'.$key);
  3021. }
  3022. // --------------------------------------------------------------------
  3023. /**
  3024. * Field Status confirm
  3025. *
  3026. * Creates the Field Deletion Confirmation page
  3027. *
  3028. * @access public
  3029. * @return void
  3030. */
  3031. function field_delete_confirm()
  3032. {
  3033. $this->_restrict_prefs_access();
  3034. $field_id = $this->input->get_post('field_id');
  3035. if ($field_id == '' OR ! is_numeric($field_id))
  3036. {
  3037. show_error(lang('not_authorized'));
  3038. }
  3039. $this->lang->loadfile('admin_content');
  3040. $this->load->model('field_model');
  3041. $this->cp->set_variable('cp_page_title', lang('delete_field'));
  3042. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management', lang('field_management'));
  3043. $vars['form_action'] = 'C=admin_content'.AMP.'M=field_delete';
  3044. $vars['form_extra'] = '';
  3045. $vars['form_hidden']['field_id'] = $field_id;
  3046. $vars['form_hidden']['group_id'] = $this->input->get('group_id');
  3047. $vars['message'] = lang('delete_field_confirmation');
  3048. // Grab status with this id
  3049. $items = $this->field_model->get_field($field_id);
  3050. $vars['items'] = array();
  3051. foreach($items->result() as $item)
  3052. {
  3053. $vars['items'][] = $item->field_label;
  3054. }
  3055. $this->javascript->compile();
  3056. $this->load->view('admin/preference_delete_confirm', $vars);
  3057. }
  3058. // --------------------------------------------------------------------
  3059. /**
  3060. * Delete Field
  3061. *
  3062. * @access public
  3063. * @return void
  3064. */
  3065. function field_delete()
  3066. {
  3067. $this->_restrict_prefs_access();
  3068. $field_id = $this->input->get_post('field_id');
  3069. if ($field_id == '' OR ! is_numeric($field_id))
  3070. {
  3071. show_error(lang('not_authorized'));
  3072. }
  3073. $this->load->model('field_model');
  3074. $this->lang->loadfile('admin_content');
  3075. $deleted = $this->field_model->delete_fields($field_id);
  3076. // Drop from custom layouts
  3077. $query = $this->field_model->get_assigned_channels($deleted['group_id']);
  3078. if ($query->num_rows() > 0)
  3079. {
  3080. foreach ($query->result() as $row)
  3081. {
  3082. $channel_ids[] = $row->channel_id;
  3083. }
  3084. $this->load->library('layout');
  3085. $this->layout->delete_layout_fields($field_id, $channel_ids);
  3086. }
  3087. $cp_message = lang('field_deleted').NBS.$deleted['field_label'];
  3088. $this->logger->log_action($cp_message);
  3089. $this->functions->clear_caching('all', '', TRUE);
  3090. $this->session->set_flashdata('message_success', $cp_message);
  3091. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=field_management'.AMP.'group_id='.$deleted['group_id']);
  3092. }
  3093. // --------------------------------------------------------------------
  3094. /** -----------------------------------------------------------
  3095. /** Edit Formatting Buttons
  3096. /** -----------------------------------------------------------*/
  3097. // This function shows the form that lets you edit the
  3098. // contents of the entry formatting pull-down menu
  3099. //-----------------------------------------------------------
  3100. function edit_formatting_options()
  3101. {
  3102. $this->_restrict_prefs_access();
  3103. if ( ! $id = $this->input->get_post('id'))
  3104. {
  3105. return FALSE;
  3106. }
  3107. $this->db->select('group_id');
  3108. $this->db->from('channel_fields');
  3109. $this->db->where('field_id', $id);
  3110. $query = $this->db->get();
  3111. if ($query->num_rows() !== 1)
  3112. {
  3113. return FALSE;
  3114. }
  3115. $group_id = $query->row('group_id');
  3116. $this->load->library('table');
  3117. $this->load->model('addons_model');
  3118. $this->lang->loadfile('admin_content');
  3119. $this->jquery->tablesorter('.mainTable', '{
  3120. headers: {1: {sorter: false}},
  3121. widgets: ["zebra"]
  3122. }');
  3123. $this->cp->set_variable('cp_page_title', lang('formatting_options'));
  3124. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=field_group_management', lang('field_management'));
  3125. $vars['form_action'] = 'C=admin_content'.AMP.'M=update_formatting_options'.AMP.'field_id='.$id.AMP.'group_id='.$group_id;
  3126. $vars['form_hidden']['field_id'] = $id;
  3127. $vars['form_hidden']['none'] = 'y';
  3128. $plugins = $this->addons_model->get_plugin_formatting();
  3129. $query = $this->db->query("SELECT field_fmt FROM exp_field_formatting WHERE field_id = '$id' AND field_fmt != 'none' ORDER BY field_fmt");
  3130. // Current available
  3131. $plugs = array();
  3132. foreach ($query->result_array() as $row)
  3133. {
  3134. $plugs[] = $row['field_fmt'];
  3135. }
  3136. $options = array();
  3137. foreach ($plugins as $val => $name)
  3138. {
  3139. $select = (in_array($val, $plugs)) ? 'y' : 'n';
  3140. $options[$val] = array('name' => $name, 'selected' => $select);
  3141. }
  3142. $vars['format_options'] = $options;
  3143. $this->javascript->compile();
  3144. $this->load->view('admin/edit_formatting_options', $vars);
  3145. }
  3146. /** ---------------------------------------
  3147. /** Update Formatting Buttons
  3148. /** ---------------------------------------*/
  3149. function update_formatting_options()
  3150. {
  3151. $this->_restrict_prefs_access();
  3152. if ( ! $id = $this->input->post('field_id'))
  3153. {
  3154. return FALSE;
  3155. }
  3156. if ( ! is_numeric($id))
  3157. {
  3158. return FALSE;
  3159. }
  3160. unset($_POST['field_id']);
  3161. $this->db->query("DELETE FROM exp_field_formatting WHERE field_id = '$id'");
  3162. foreach ($_POST as $key => $val)
  3163. {
  3164. if ($val == 'y')
  3165. $this->db->query("INSERT INTO exp_field_formatting (field_id, field_fmt) VALUES ('$id', '$key')");
  3166. }
  3167. return $this->field_edit();
  3168. }
  3169. // --------------------------------------------------------------------
  3170. /**
  3171. * Status Group Management
  3172. *
  3173. * This function show the list of current status groups.
  3174. * It is accessed by clicking "Custom entry statuses" in the "admin" tab
  3175. *
  3176. * @access public
  3177. * @return void
  3178. */
  3179. function status_group_management($message = '')
  3180. {
  3181. $this->_restrict_prefs_access();
  3182. $this->load->library('table');
  3183. $this->load->model('status_model');
  3184. $this->lang->loadfile('admin_content');
  3185. $this->cp->set_variable('cp_page_title', lang('statuses'));
  3186. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content', lang('admin_content'));
  3187. $this->jquery->tablesorter('.mainTable', '{
  3188. headers: {1: {sorter: false}, 2: {sorter: false}},
  3189. widgets: ["zebra"]
  3190. }');
  3191. $vars['message'] = $message;
  3192. // Fetch category groups
  3193. $vars['status_groups'] = $this->status_model->get_status_groups();
  3194. $this->javascript->compile();
  3195. $this->cp->set_right_nav(array('create_new_status_group' => BASE.AMP.'C=admin_content'.AMP.'M=status_group_edit'));
  3196. $this->load->view('admin/status_group_management', $vars);
  3197. }
  3198. // --------------------------------------------------------------------
  3199. /**
  3200. * Status Group Edit
  3201. *
  3202. * @access public
  3203. * @return void
  3204. */
  3205. function status_group_edit()
  3206. {
  3207. $this->_restrict_prefs_access();
  3208. $this->load->model('status_model');
  3209. $this->lang->loadfile('admin_content');
  3210. $this->load->model('status_model');
  3211. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management', lang('statuses'));
  3212. // If we have the group_id variable it's an edit request, so fetch the status data
  3213. $group_id = $this->input->get_post('group_id');
  3214. // Set default values
  3215. $vars = array(
  3216. 'group_id' => '',
  3217. 'group_name' => '',
  3218. 'form_hidden' => array(),
  3219. 'submit_lang_key' => ($group_id != '') ? 'update' : 'submit',
  3220. 'group_name' => ''
  3221. );
  3222. if ($group_id != '')
  3223. {
  3224. $this->cp->set_variable('cp_page_title', lang('rename_group'));
  3225. $vars['form_hidden']['group_id'] = $group_id;
  3226. if ( ! is_numeric($group_id))
  3227. {
  3228. show_error(lang('not_authorized'));
  3229. }
  3230. $query = $this->status_model->get_status_group($group_id);
  3231. foreach ($query->row() as $key => $val)
  3232. {
  3233. $vars[$key] = $val;
  3234. }
  3235. }
  3236. else
  3237. {
  3238. $this->cp->set_variable('cp_page_title', lang('create_new_status_group'));
  3239. }
  3240. $this->javascript->compile();
  3241. $this->load->view('admin/status_group_edit', $vars);
  3242. }
  3243. // --------------------------------------------------------------------
  3244. /**
  3245. * Status Group Delete Confirm
  3246. *
  3247. * Warning message shown when you try to delete a status group
  3248. *
  3249. * @access public
  3250. * @return void
  3251. */
  3252. function status_group_delete_confirm()
  3253. {
  3254. $this->_restrict_prefs_access();
  3255. $group_id = $this->input->get_post('group_id');
  3256. if ($group_id == '' OR ! is_numeric($group_id))
  3257. {
  3258. show_error(lang('not_authorized'));
  3259. }
  3260. $this->lang->loadfile('admin_content');
  3261. $this->load->model('status_model');
  3262. $this->cp->set_variable('cp_page_title', lang('delete_group'));
  3263. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=status_management'.AMP.'group_id='.$group_id, lang('statuses'));
  3264. $vars['form_action'] = 'C=admin_content'.AMP.'M=status_group_delete';
  3265. $vars['form_extra'] = '';
  3266. $vars['form_hidden']['group_id'] = $group_id;
  3267. $vars['message'] = lang('delete_status_group_confirmation');
  3268. // Grab category_groups locations with this id
  3269. $items = $this->status_model->get_status_group($group_id);
  3270. $vars['items'] = array();
  3271. foreach($items->result() as $item)
  3272. {
  3273. $vars['items'][] = $item->group_name;
  3274. }
  3275. $this->javascript->compile();
  3276. $this->load->view('admin/preference_delete_confirm', $vars);
  3277. }
  3278. // --------------------------------------------------------------------
  3279. /**
  3280. * Status Group Delete
  3281. *
  3282. * This function nukes the status group and associated statuses
  3283. *
  3284. * @access public
  3285. * @return void
  3286. */
  3287. function status_group_delete()
  3288. {
  3289. $this->_restrict_prefs_access();
  3290. $group_id = $this->input->get_post('group_id');
  3291. if ($group_id == '' OR ! is_numeric($group_id))
  3292. {
  3293. show_error(lang('not_authorized'));
  3294. }
  3295. $this->load->model('status_model');
  3296. $this->lang->loadfile('admin_content');
  3297. $query = $this->status_model->get_status_group($group_id);
  3298. if ($query->num_rows() == 0)
  3299. {
  3300. show_error(lang('unauthorized_access'));
  3301. }
  3302. $this->status_model->delete_status_group($group_id);
  3303. $cp_message = lang('status_group_deleted').NBS.$query->row('group_name');
  3304. $this->logger->log_action($cp_message);
  3305. $this->functions->clear_caching('all', '', TRUE);
  3306. $this->session->set_flashdata('message_success', $cp_message);
  3307. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management');
  3308. }
  3309. // --------------------------------------------------------------------
  3310. /**
  3311. * Status Group Update
  3312. *
  3313. * his function receives the submitted status group data
  3314. * and puts it in the database
  3315. *
  3316. * @access public
  3317. * @return void
  3318. */
  3319. function status_group_update()
  3320. {
  3321. $this->_restrict_prefs_access();
  3322. $group_id = $this->input->get_post('group_id');
  3323. // If the $group_id variable is present we are editing an
  3324. // existing group, otherwise we are creating a new one
  3325. $edit = (isset($_POST['group_id'])) ? TRUE : FALSE;
  3326. $group_name = $this->input->post('group_name');
  3327. if ($group_name == '')
  3328. {
  3329. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management');
  3330. }
  3331. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $group_name))
  3332. {
  3333. show_error(lang('illegal_characters'));
  3334. }
  3335. $this->load->model('status_model');
  3336. $this->lang->loadfile('admin_content');
  3337. // Is the group name taken?
  3338. if ($this->status_model->is_duplicate_status_group_name($group_name, $group_id))
  3339. {
  3340. show_error(lang('taken_status_group_name'));
  3341. }
  3342. // Construct the query based on whether we are updating or inserting
  3343. if ($edit == FALSE)
  3344. {
  3345. $this->status_model->insert_statuses($group_name);
  3346. $cp_message = lang('status_group_created').NBS.$group_name;
  3347. $this->logger->log_action($cp_message);
  3348. $this->db->select('channel_id');
  3349. $this->db->where('site_id', $this->config->item('site_id'));
  3350. $channel_info = $this->db->get('channels');
  3351. $query = $this->db->query("SELECT channel_id from exp_channels WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."'");
  3352. if ($channel_info->num_rows() > 0)
  3353. {
  3354. $cp_message .= lang('assign_group_to_channel').NBS;
  3355. if ($channel_info->num_rows() == 1)
  3356. {
  3357. $link = 'C=admin_content'.AMP.'M=channel_edit_group_assignments'.AMP.'channel_id='.$channel_info->row('channel_id');
  3358. $cp_message .= '<a href="'.BASE.AMP.$link.'">'.lang('click_to_assign_group').'</a>';
  3359. }
  3360. else
  3361. {
  3362. $link = 'C=admin_content'.AMP.'M=channel_management';
  3363. }
  3364. }
  3365. }
  3366. else
  3367. {
  3368. $this->status_model->update_statuses($group_name, $group_id);
  3369. $cp_message = lang('status_group_updated').NBS.$group_name;
  3370. }
  3371. $this->session->set_flashdata('message_success', $cp_message);
  3372. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management');
  3373. }
  3374. // --------------------------------------------------------------------
  3375. /**
  3376. * Add or Edit Statuses Group Delete
  3377. *
  3378. *
  3379. * @access public
  3380. * @return void
  3381. */
  3382. function status_management($message = '')
  3383. {
  3384. $this->_restrict_prefs_access();
  3385. $group_id = $this->input->get_post('group_id');
  3386. if ($group_id == '' OR ! is_numeric($group_id))
  3387. {
  3388. show_error(lang('not_authorized'));
  3389. }
  3390. $this->load->model('status_model');
  3391. $this->lang->loadfile('admin_content');
  3392. $this->load->library('table');
  3393. $group_name = $this->status_model->get_status_group($group_id);
  3394. $this->cp->set_variable('cp_page_title', lang('group').':'.NBS.$group_name->row('group_name'));
  3395. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management', lang('statuses'));
  3396. $this->jquery->tablesorter('.mainTable', '{
  3397. headers: {1: {sorter: false}},
  3398. widgets: ["zebra"]
  3399. }');
  3400. $vars['message'] = $message;
  3401. // Fetch status groups
  3402. $vars['statuses'] = $this->status_model->get_statuses($group_id);
  3403. $this->javascript->compile();
  3404. $this->cp->set_right_nav(array('create_new_status' => BASE.AMP.'C=admin_content'.AMP.'M=status_edit'.AMP.'group_id='.$group_id));
  3405. $this->load->view('admin/status_management', $vars);
  3406. }
  3407. // --------------------------------------------------------------------
  3408. /**
  3409. * Add or Edit Statuses
  3410. *
  3411. * Edit status form
  3412. *
  3413. * @access public
  3414. * @return void
  3415. */
  3416. function status_edit()
  3417. {
  3418. $this->_restrict_prefs_access();
  3419. $status_id = $this->input->get_post('status_id');
  3420. if ($status_id != '' AND ! is_numeric($status_id))
  3421. {
  3422. show_error(lang('not_authorized'));
  3423. }
  3424. $this->cp->add_js_script(array(
  3425. 'plugin' => array('jscolor')
  3426. ));
  3427. $this->load->library('table');
  3428. $this->lang->loadfile('admin_content');
  3429. $this->load->model('status_model');
  3430. $query = $this->status_model->get_status($status_id);
  3431. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management', lang('statuses'));
  3432. // Set default values
  3433. $vars['group_name'] = '';
  3434. if ($query->num_rows() > 0)
  3435. {
  3436. $vars['status'] = $query->row('status');
  3437. $vars['status_order'] = $query->row('status_order');
  3438. $vars['highlight'] = $query->row('highlight');
  3439. }
  3440. else
  3441. {
  3442. $status_order = $this->status_model->get_next_status_order($this->input->get_post('group_id'));
  3443. $vars['status'] = '';
  3444. $vars['status_order'] = $status_order;
  3445. $vars['highlight'] = '000000';
  3446. }
  3447. $vars['form_hidden']['status_id'] = $status_id;
  3448. $vars['form_hidden']['old_status'] = $vars['status'];
  3449. if ($vars['status'] == 'open' OR $vars['status'] == 'closed')
  3450. {
  3451. $vars['form_hidden']['status'] = $vars['status'];
  3452. }
  3453. if ($status_id == '')
  3454. {
  3455. $vars['submit_lang_key'] = 'submit';
  3456. $vars['form_hidden']['group_id'] = $this->input->get_post('group_id');
  3457. $this->cp->set_variable('cp_page_title', lang('status'));
  3458. }
  3459. else
  3460. {
  3461. $vars['form_hidden']['group_id'] = $query->row('group_id');
  3462. $vars['submit_lang_key'] = 'update';
  3463. $this->cp->set_variable('cp_page_title', ucfirst($vars['status']));
  3464. }
  3465. if ($this->session->userdata['group_id'] == 1)
  3466. {
  3467. $query = $this->db->query("SELECT group_id, group_title
  3468. FROM exp_member_groups
  3469. WHERE group_id NOT IN (1,2,3,4)
  3470. AND site_id = '".$this->db->escape_str($this->config->item('site_id'))."'
  3471. ORDER BY group_title");
  3472. $group = array();
  3473. $vars['member_perms'] = array();
  3474. $result = $this->db->query("SELECT member_group FROM exp_status_no_access WHERE status_id = '$status_id'");
  3475. if ($result->num_rows() != 0)
  3476. {
  3477. foreach($result->result_array() as $row)
  3478. {
  3479. $group[$row['member_group']] = TRUE;
  3480. }
  3481. }
  3482. foreach ($query->result() as $row)
  3483. {
  3484. $vars['member_perms'][$row->group_id]['group_id'] = $row->group_id;
  3485. $vars['member_perms'][$row->group_id]['group_title'] = $row->group_title;
  3486. if ( ! isset($group[$row->group_id]))
  3487. {
  3488. $vars['member_perms'][$row->group_id]['access_y'] = TRUE;
  3489. $vars['member_perms'][$row->group_id]['access_n'] = FALSE;
  3490. }
  3491. else
  3492. {
  3493. $vars['member_perms'][$row->group_id]['access_y'] = FALSE;
  3494. $vars['member_perms'][$row->group_id]['access_n'] = TRUE;
  3495. }
  3496. }
  3497. }
  3498. $this->javascript->compile();
  3499. $this->load->view('admin/status_edit', $vars);
  3500. }
  3501. // --------------------------------------------------------------------
  3502. /**
  3503. * Status submission handler
  3504. *
  3505. * This function receives the submitted status data and inserts it in the database.
  3506. *
  3507. * @access public
  3508. * @return mixed
  3509. */
  3510. function status_update()
  3511. {
  3512. $this->_restrict_prefs_access();
  3513. $edit = ( ! $this->input->post('status_id')) ? FALSE : TRUE;
  3514. if ($this->input->post('status') == '')
  3515. {
  3516. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=status_group_management');
  3517. }
  3518. if (preg_match('/[^a-z0-9\_\-\+\s]/i', $this->input->post('status')))
  3519. {
  3520. show_error(lang('invalid_status_name'));
  3521. }
  3522. $data = array(
  3523. 'status' => $this->input->post('status'),
  3524. 'status_order' => (is_numeric($this->input->post('status_order'))) ? $this->input->get_post('status_order') : 0,
  3525. 'highlight' => $this->input->post('highlight')
  3526. );
  3527. if ($edit == FALSE)
  3528. {
  3529. $query = $this->db->query("SELECT count(*) AS count FROM exp_statuses WHERE status = '".$this->db->escape_str($_POST['status'])."' AND group_id = '".$this->db->escape_str($_POST['group_id'])."'");
  3530. if ($query->row('count') > 0)
  3531. {
  3532. show_error(lang('duplicate_status_name'));
  3533. }
  3534. $data['group_id'] = $_POST['group_id'];
  3535. $data['site_id'] = $this->config->item('site_id');
  3536. $this->db->insert('statuses', $data);
  3537. $status_id = $this->db->insert_id();
  3538. $cp_message = lang('status_created');
  3539. }
  3540. else
  3541. {
  3542. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_statuses WHERE status = '".$this->db->escape_str($_POST['status'])."' AND group_id = '".$this->db->escape_str($_POST['group_id'])."' AND status_id != '".$this->db->escape_str($_POST['status_id'])."'");
  3543. if ($query->row('count') > 0)
  3544. {
  3545. show_error(lang('duplicate_status_name'));
  3546. }
  3547. $status_id = $this->input->get_post('status_id');
  3548. $sql = $this->db->update_string(
  3549. 'exp_statuses',
  3550. $data,
  3551. array(
  3552. 'status_id' => $status_id,
  3553. 'group_id' => $this->input->post('group_id')
  3554. )
  3555. );
  3556. $this->db->query($sql);
  3557. $this->db->query("DELETE FROM exp_status_no_access WHERE status_id = '$status_id'");
  3558. // If the status name has changed, we need to update channel entries with the new status.
  3559. if ($_POST['old_status'] != $_POST['status'])
  3560. {
  3561. $query = $this->db->query("SELECT channel_id FROM exp_channels WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."' AND status_group = '".$this->db->escape_str($_POST['group_id'])."'");
  3562. if ($query->num_rows() > 0)
  3563. {
  3564. foreach ($query->result_array() as $row)
  3565. {
  3566. $this->db->query("UPDATE exp_channel_titles SET status = '".$this->db->escape_str($_POST['status'])."'
  3567. WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."'
  3568. AND status = '".$this->db->escape_str($_POST['old_status'])."'
  3569. AND channel_id = '".$row['channel_id']."'");
  3570. }
  3571. }
  3572. }
  3573. $cp_message = lang('status_updated');
  3574. }
  3575. // Set access privs
  3576. foreach ($_POST as $key => $val)
  3577. {
  3578. if (substr($key, 0, 7) == 'access_' AND $val == 'n')
  3579. {
  3580. $this->db->query("INSERT INTO exp_status_no_access (status_id, member_group) VALUES ('$status_id', '".substr($key, 7)."')");
  3581. }
  3582. }
  3583. $this->session->set_flashdata('message_success', $cp_message);
  3584. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=status_management'.AMP.'group_id='.$this->input->post('group_id'));
  3585. }
  3586. // --------------------------------------------------------------------
  3587. /**
  3588. * Delete Status confirm
  3589. *
  3590. * Creates Delete Status Confirmation page
  3591. *
  3592. * @access public
  3593. * @return void
  3594. */
  3595. function status_delete_confirm()
  3596. {
  3597. $this->_restrict_prefs_access();
  3598. $status_id = $this->input->get_post('status_id');
  3599. if ($status_id == '' OR ! is_numeric($status_id))
  3600. {
  3601. show_error(lang('not_authorized'));
  3602. }
  3603. $this->lang->loadfile('admin_content');
  3604. $this->load->model('status_model');
  3605. $this->cp->set_variable('cp_page_title', lang('delete_status'));
  3606. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content'.AMP.'M=status_management', lang('statuses'));
  3607. $vars['form_action'] = 'C=admin_content'.AMP.'M=status_delete';
  3608. $vars['form_extra'] = '';
  3609. $vars['form_hidden']['status_id'] = $status_id;
  3610. $vars['message'] = lang('delete_status_confirmation');
  3611. // Grab status with this id
  3612. $items = $this->status_model->get_status($status_id);
  3613. $vars['items'] = array();
  3614. foreach($items->result() as $item)
  3615. {
  3616. $vars['items'][] = $item->status;
  3617. }
  3618. $this->javascript->compile();
  3619. $this->load->view('admin/preference_delete_confirm', $vars);
  3620. }
  3621. // --------------------------------------------------------------------
  3622. /**
  3623. * Delete Status
  3624. *
  3625. * @access public
  3626. * @return void
  3627. */
  3628. function status_delete()
  3629. {
  3630. $this->_restrict_prefs_access();
  3631. $status_id = $this->input->get_post('status_id');
  3632. if ($status_id == '' OR ! is_numeric($status_id))
  3633. {
  3634. show_error(lang('not_authorized'));
  3635. }
  3636. $this->load->model('status_model');
  3637. $query = $this->status_model->get_status($status_id);
  3638. $group_id = $query->row('group_id') ;
  3639. $status = $query->row('status') ;
  3640. $query = $this->db->query("SELECT channel_id FROM exp_channels WHERE site_id = '".$this->db->escape_str($this->config->item('site_id'))."' AND status_group = '$group_id'");
  3641. if ($query->num_rows() > 0)
  3642. {
  3643. $this->db->query("UPDATE exp_channel_titles SET status = 'closed' WHERE status = '$status' AND channel_id = '".$this->db->escape_str($query->row('channel_id') )."'");
  3644. }
  3645. if ($status != 'open' AND $status != 'closed')
  3646. {
  3647. $this->db->query("DELETE FROM exp_statuses WHERE status_id = '$status_id' AND site_id = '".$this->db->escape_str($this->config->item('site_id'))."' AND group_id = '".$this->db->escape_str($group_id)."'");
  3648. }
  3649. $this->session->set_flashdata('message_success', lang('status_deleted'));
  3650. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=status_management'.AMP.'group_id='.$group_id);
  3651. }
  3652. // --------------------------------------------------------------------
  3653. /**
  3654. * Not Http
  3655. *
  3656. * Custom validation
  3657. *
  3658. * @access private
  3659. * @return boolean
  3660. */
  3661. function not_http($str = '')
  3662. {
  3663. if ($str == 'http://' OR $str == '')
  3664. {
  3665. $this->form_validation->set_message('not_http', lang('no_upload_dir_url'));
  3666. return FALSE;
  3667. }
  3668. return TRUE;
  3669. }
  3670. // --------------------------------------------------------------------
  3671. /**
  3672. * Default Ping Servers
  3673. *
  3674. * Creates the Default Ping Servers page
  3675. *
  3676. * @access public
  3677. * @return void
  3678. */
  3679. function default_ping_servers($message = '', $id = '0')
  3680. {
  3681. $this->_restrict_prefs_access();
  3682. if ($id == 0 && ! $this->cp->allowed_group('can_admin_channels'))
  3683. {
  3684. show_error(lang('unauthorized_access'));
  3685. }
  3686. $this->load->library('table');
  3687. $this->lang->loadfile('admin_content');
  3688. $this->load->model('admin_model');
  3689. $vars['message'] = $message;
  3690. $r = '';
  3691. if ($id != 0)
  3692. {
  3693. $this->cp->set_variable('cp_page_title', lang('ping_servers'));
  3694. $vars['instructions'] = '';
  3695. }
  3696. else
  3697. {
  3698. $this->cp->set_variable('cp_page_title', lang('default_ping_servers'));
  3699. $vars['instructions'] = lang('define_ping_servers');
  3700. }
  3701. $vars['form_hidden']['member_id'] = $id;
  3702. $this->jquery->tablesorter('.mainTable', '{widgets: ["zebra"]}');
  3703. $ping_servers = $this->admin_model->get_ping_servers(0);
  3704. // ping protocols supported (currently only xmlrpc)
  3705. $vars['protocols'] = array('xmlrpc'=>'xmlrpc');
  3706. $vars['is_default_options'] = array('y'=>lang('yes'), 'n'=>lang('no'));
  3707. $i = 1;
  3708. $vars['ping_servers'] = array();
  3709. if ($ping_servers->num_rows() > 0)
  3710. {
  3711. foreach ($ping_servers->result_array() as $row)
  3712. {
  3713. $vars['ping_servers'][$i]['server_id'] = $row['id'];
  3714. $vars['ping_servers'][$i]['server_name'] = $row['server_name'];
  3715. $vars['ping_servers'][$i]['server_url'] = $row['server_url'];
  3716. $vars['ping_servers'][$i]['port'] = $row['port'];
  3717. $vars['ping_servers'][$i]['ping_protocol'] = $row['ping_protocol'];
  3718. $vars['ping_servers'][$i]['server_order'] = $row['server_order'];
  3719. $vars['ping_servers'][$i]['is_default'] = $row['is_default'];
  3720. $i++;
  3721. }
  3722. }
  3723. $vars['blank_count'] = $i;
  3724. $this->javascript->output('
  3725. function setup_js_page() {
  3726. $(".mainTable").tablesorter({widgets: ["zebra"]});
  3727. $(".del_row, .order_arrows").show();
  3728. $(".del_instructions").hide();
  3729. $(".tag_order").css("cursor", "move");
  3730. $(".del_row a").click(function(){
  3731. $(this).parent().parent().remove();
  3732. update_ping_servers("true");
  3733. return false;
  3734. });
  3735. $(".mainTable .tag_order input").hide();
  3736. $(".mainTable tbody").sortable({
  3737. axis:"y",
  3738. containment:"parent",
  3739. placeholder:"tablesize",
  3740. update: function(){
  3741. $("input[name^=server_order]").each(function(i) {
  3742. $(this).val(i+1);
  3743. });
  3744. update_ping_servers("false");
  3745. $(".mainTable").trigger("applyWidgets");
  3746. }
  3747. });
  3748. $("#ping_server_form").submit(function() {
  3749. update_ping_servers("true");
  3750. return false;
  3751. });
  3752. }
  3753. function update_ping_servers(refresh) {
  3754. $.post(
  3755. EE.BASE+"&C=admin_content&M=save_ping_servers&refresh="+refresh,
  3756. $("#ping_server_form").serializeArray(),
  3757. function(res) {
  3758. if ($(res).find("#ping_server_form").length > 0) {
  3759. $("#ping_server_form").replaceWith($(res).find("#ping_server_form"));
  3760. setup_js_page();
  3761. }
  3762. $.ee_notice("'.lang('preferences_updated').'", {"type" : "success"});
  3763. },
  3764. "html");
  3765. }
  3766. setup_js_page();
  3767. ');
  3768. $this->cp->add_to_head('<style type="text/css">.tablesize{height:45px!important;}</style>');
  3769. $this->javascript->compile();
  3770. $this->load->view('admin/default_ping_servers', $vars);
  3771. }
  3772. // --------------------------------------------------------------------
  3773. /**
  3774. * Save ping servers
  3775. */
  3776. function save_ping_servers()
  3777. {
  3778. $this->_restrict_prefs_access();
  3779. $this->load->model('admin_model');
  3780. $id = $this->input->get_post('member_id');
  3781. $data = array();
  3782. foreach ($_POST as $key => $val)
  3783. {
  3784. if (strncmp($key, 'server_name_', 12) == 0 && $val != '')
  3785. {
  3786. $n = substr($key, 12);
  3787. $data[] = array(
  3788. 'member_id' => 0,
  3789. 'server_name' => $this->input->post('server_name_'.$n),
  3790. 'server_url' => $this->input->post('server_url_'.$n),
  3791. 'port' => $this->input->post('server_port_'.$n),
  3792. 'ping_protocol' => $this->input->post('ping_protocol_'.$n),
  3793. 'is_default' => $this->input->post('is_default_'.$n),
  3794. 'server_order' => $this->input->post('server_order_'.$n),
  3795. 'site_id' => $this->config->item('site_id')
  3796. );
  3797. }
  3798. }
  3799. $this->admin_model->update_ping_servers(0, $data);
  3800. $message = lang('preferences_updated');
  3801. $this->default_ping_servers($message);
  3802. }
  3803. // --------------------------------------------------------------------
  3804. /**
  3805. * Default HTML Buttons
  3806. *
  3807. * Creates the Default HTML Buttons page
  3808. *
  3809. * @access public
  3810. * @return void
  3811. */
  3812. function default_html_buttons()
  3813. {
  3814. $this->_restrict_prefs_access();
  3815. $this->load->library('table');
  3816. $this->lang->loadfile('admin_content');
  3817. $this->load->model('admin_model');
  3818. $member_id = (int) $this->input->get_post('member_id');
  3819. if ($member_id == 0)
  3820. {
  3821. //show_error(lang('unauthorized_access'));
  3822. }
  3823. $this->cp->set_variable('cp_page_title', lang('default_html_buttons'));
  3824. $this->cp->add_js_script(array('file' => 'cp/account_html_buttons'));
  3825. $vars['form_hidden']['member_id'] = $this->session->userdata('member_id');
  3826. $vars['form_hidden']['button_submit'] = TRUE;
  3827. // load the systems's predefined buttons
  3828. include(APPPATH.'config/html_buttons.php');
  3829. $vars['predefined_buttons'] = $predefined_buttons;
  3830. $vars['html_buttons'] = $this->admin_model->get_html_buttons(0);
  3831. $button_count = $vars['html_buttons']->num_rows();
  3832. // any predefined buttons?
  3833. $button = $this->input->get_post('button');
  3834. if ($button != '')
  3835. {
  3836. // all buttons also share these settings
  3837. $predefined_buttons[$button]['member_id'] = 0;
  3838. $predefined_buttons[$button]['site_id'] = $this->config->item('site_id');
  3839. $predefined_buttons[$button]['tag_order'] = $button_count++;
  3840. $predefined_buttons[$button]['tag_row'] = 1;
  3841. $this->admin_model->update_html_buttons(0, array($predefined_buttons[$button]), FALSE);
  3842. $this->session->set_flashdata('message_success', lang('preferences_updated'));
  3843. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=default_html_buttons');
  3844. }
  3845. elseif (is_numeric($member_id) AND $member_id != 0 AND $this->input->get_post('button_submit') != '')
  3846. {
  3847. $data = array();
  3848. foreach ($_POST as $key => $val)
  3849. {
  3850. if (strncmp($key, 'tag_name_', 9) == 0 && $val != '')
  3851. {
  3852. $n = substr($key, 9);
  3853. $data[] = array(
  3854. 'member_id' => 0,
  3855. 'tag_name' => $this->input->post('tag_name_'.$n),
  3856. 'tag_open' => $this->input->post('tag_open_'.$n),
  3857. 'tag_close' => $this->input->post('tag_close_'.$n),
  3858. 'accesskey' => $this->input->post('accesskey_'.$n),
  3859. 'tag_order' => ($this->input->post('tag_order_'.$n) != '') ? $this->input->post('tag_order_'.$n) : $button_count++,
  3860. 'tag_row' => 1, // $_POST['tag_row_'.$n],
  3861. 'site_id' => $this->config->item('site_id'),
  3862. 'classname' => "btn_".str_replace(array(' ', '<', '>', '[', ']', ':', '-', '"', "'"), '', $this->input->post('tag_name_'.$n))
  3863. );
  3864. }
  3865. }
  3866. $this->admin_model->update_html_buttons(0, $data);
  3867. $this->session->set_flashdata('message_success', lang('preferences_updated'));
  3868. $this->functions->redirect(BASE.AMP.'C=admin_content'.AMP.'M=default_html_buttons');
  3869. }
  3870. $vars['html_buttons'] = $this->admin_model->get_html_buttons(0); // recall it in case in insert happened
  3871. $vars['i'] = 1;
  3872. $this->javascript->compile();
  3873. $this->load->view('admin/default_html_buttons', $vars);
  3874. }
  3875. // --------------------------------------------------------------------
  3876. /**
  3877. * Delete HTML Button
  3878. *
  3879. * @access public
  3880. * @return void
  3881. */
  3882. function delete_html_button()
  3883. {
  3884. $this->_restrict_prefs_access();
  3885. $this->load->model('admin_model');
  3886. $this->admin_model->delete_html_button($this->input->get_post('id'));
  3887. }
  3888. // --------------------------------------------------------------------
  3889. /**
  3890. * Reorder HTML Buttons
  3891. *
  3892. * @access public
  3893. * @return void
  3894. */
  3895. function reorder_html_buttons()
  3896. {
  3897. $this->_restrict_prefs_access();
  3898. foreach($this->input->post('ajax_tag_order') as $order=>$tag_id)
  3899. {
  3900. $this->db->set('tag_order', $order);
  3901. $this->db->where('id', $tag_id);
  3902. $this->db->update('html_buttons');
  3903. }
  3904. $this->output->send_ajax_response(lang('preferences_updated'));
  3905. }
  3906. // --------------------------------------------------------------------
  3907. /**
  3908. * Global Channel Preferences
  3909. *
  3910. * @access public
  3911. * @return void
  3912. */
  3913. function global_channel_preferences()
  3914. {
  3915. $this->_restrict_prefs_access();
  3916. $this->cp->set_breadcrumb(BASE.AMP.'C=admin_content', lang('admin_content'));
  3917. $this->_config_manager('channel_cfg', __FUNCTION__);
  3918. }
  3919. // --------------------------------------------------------------------
  3920. /**
  3921. * Config Manager
  3922. *
  3923. * Used to display the various preference pages
  3924. *
  3925. * @access public
  3926. * @return void
  3927. */
  3928. function _config_manager($type, $return_loc)
  3929. {
  3930. $this->jquery->tablesorter('.mainTable', '{
  3931. widgets: ["zebra"],
  3932. headers: {
  3933. 1: { sorter: false }
  3934. },
  3935. textExtraction: function(node) {
  3936. var c = $(node).children();
  3937. if (c.length) {
  3938. return c.text();
  3939. }
  3940. else {
  3941. return node.innerHTML;
  3942. }
  3943. }
  3944. }');
  3945. $this->load->library('table');
  3946. $this->load->model('admin_model');
  3947. if ( ! in_array($type, array(
  3948. 'general_cfg',
  3949. 'cp_cfg',
  3950. 'channel_cfg',
  3951. 'member_cfg',
  3952. 'output_cfg',
  3953. 'debug_cfg',
  3954. 'db_cfg',
  3955. 'security_cfg',
  3956. 'throttling_cfg',
  3957. 'localization_cfg',
  3958. 'email_cfg',
  3959. 'cookie_cfg',
  3960. 'image_cfg',
  3961. 'captcha_cfg',
  3962. 'template_cfg',
  3963. 'censoring_cfg',
  3964. 'mailinglist_cfg',
  3965. 'emoticon_cfg',
  3966. 'tracking_cfg',
  3967. 'avatar_cfg',
  3968. 'search_log_cfg'
  3969. )
  3970. )
  3971. )
  3972. {
  3973. show_error(lang('unauthorized_access'));
  3974. }
  3975. $vars['type'] = $type;
  3976. $vars['form_action'] = 'C=admin_content'.AMP.'M=update_config';
  3977. $f_data = $this->admin_model->get_config_fields($type);
  3978. $subtext = $this->admin_model->get_config_field_subtext();
  3979. /** -----------------------------
  3980. /** Blast through the array
  3981. /** -----------------------------*/
  3982. // If we're dealing with a database configuration we need to pull the data
  3983. // out of the DB config file. To make thigs simple we will set the DB config
  3984. // items as general config values
  3985. if ($type == 'db_cfg')
  3986. {
  3987. require $this->config->database_path;
  3988. if ( ! isset($active_group))
  3989. {
  3990. $active_group = 'expressionengine';
  3991. }
  3992. if (isset($db[$active_group]))
  3993. {
  3994. $db[$active_group]['pconnect'] = ($db[$active_group]['pconnect'] === TRUE) ? 'y' : 'n';
  3995. $db[$active_group]['cache_on'] = ($db[$active_group]['cache_on'] === TRUE) ? 'y' : 'n';
  3996. $db[$active_group]['db_debug'] = ($db[$active_group]['db_debug'] === TRUE) ? 'y' : 'n';
  3997. $this->config->set_item('pconnect', $db[$active_group]['pconnect']);
  3998. $this->config->set_item('cache_on', $db[$active_group]['cache_on']);
  3999. $this->config->set_item('cachedir', $db[$active_group]['cachedir']);
  4000. $this->config->set_item('db_debug', $db[$active_group]['db_debug']);
  4001. }
  4002. }
  4003. foreach ($f_data as $name => $options)
  4004. {
  4005. $value = $this->config->item($name);
  4006. $sub = '';
  4007. $details = '';
  4008. $selected = '';
  4009. if (isset($subtext[$name]))
  4010. {
  4011. foreach ($subtext[$name] as $txt)
  4012. {
  4013. $sub .= lang($txt);
  4014. }
  4015. }
  4016. switch ($options[0])
  4017. {
  4018. case 's':
  4019. // Select fields
  4020. foreach ($options[1] as $k => $v)
  4021. {
  4022. $details[$k] = lang($v);
  4023. }
  4024. $selected = $value;
  4025. break;
  4026. case 'r':
  4027. // Radio buttons
  4028. foreach ($options[1] as $k => $v)
  4029. {
  4030. // little cheat for some values popped into a build update
  4031. if ($value === FALSE)
  4032. {
  4033. $checked = (isset($options['2']) && $k == $options['2']) ? TRUE : FALSE;
  4034. }
  4035. else
  4036. {
  4037. $checked = ($k == $value) ? TRUE : FALSE;
  4038. }
  4039. $details[] = array('name' => $name, 'value' => $k, 'id' => $name.'_'.$k, 'label' => $v, 'checked' => $checked);
  4040. }
  4041. break;
  4042. case 't':
  4043. // Textareas
  4044. // The "kill_pipes" index instructs us to turn pipes into newlines
  4045. if (isset($options['1']['kill_pipes']) && $options['1']['kill_pipes'] === TRUE)
  4046. {
  4047. $text = str_replace('|', NL, $value);
  4048. }
  4049. else
  4050. {
  4051. $text = $value;
  4052. }
  4053. $rows = (isset($options['1']['rows'])) ? $options['1']['rows'] : '20';
  4054. $text = str_replace("\\'", "'", $text);
  4055. $details = array('name' => $name, 'value' => $text, 'rows' => $rows, 'id' => $name);
  4056. break;
  4057. case 'f':
  4058. // Function calls
  4059. switch ($options['1'])
  4060. {
  4061. case 'language_menu' :
  4062. $options[0] = 's';
  4063. $details = $this->admin_model->get_installed_language_packs();
  4064. $selected = $value;
  4065. break;
  4066. case 'fetch_encoding' :
  4067. $options[0] = 's';
  4068. $details = $this->admin_model->get_xml_encodings();
  4069. $selected = $value;
  4070. break;
  4071. case 'site_404' :
  4072. $options[0] = 's';
  4073. $details = array('' => lang('none'));
  4074. if (is_array($list = $this->admin_model->get_template_list()))
  4075. {
  4076. $details = array_merge($details, $list);
  4077. }
  4078. $selected = $value;
  4079. break;
  4080. case 'theme_menu' :
  4081. $options[0] = 's';
  4082. $details = $this->admin_model->get_cp_theme_list();
  4083. $selected = $value;
  4084. break;
  4085. case 'timezone' :
  4086. $options[0] = 's';
  4087. foreach ($this->localize->zones as $k => $v)
  4088. {
  4089. $details[$k] = lang($k);
  4090. }
  4091. $selected = $value;
  4092. break;
  4093. }
  4094. break;
  4095. case 'i':
  4096. // Input fields
  4097. $details = array('name' => $name, 'value' => str_replace("\\'", "'", $value), 'id' => $name);
  4098. break;
  4099. }
  4100. $vars['fields'][$name] = array('type' => $options[0], 'value' => $details, 'subtext' => $sub, 'selected' => $selected);
  4101. }
  4102. // if this is an update, show the success message
  4103. //$vars['alert'] = ($this->input->get_post('U')) ? lang('preferences_updated') : FALSE;
  4104. $vars['return_loc'] = BASE.AMP.'C=admin_content'.AMP.'M='.$return_loc;
  4105. $this->cp->set_variable('cp_page_title', lang($type));
  4106. $this->javascript->compile();
  4107. $this->load->view('admin/config_pages', $vars);
  4108. }
  4109. // --------------------------------------------------------------------
  4110. /**
  4111. * Update Config
  4112. *
  4113. * Handles system and site pref form submissions
  4114. *
  4115. * @access public
  4116. * @return void
  4117. */
  4118. function update_config()
  4119. {
  4120. $this->_restrict_prefs_access();
  4121. $loc = $this->input->get_post('return_location');
  4122. $this->config->update_site_prefs($_POST);
  4123. if ($loc !== FALSE)
  4124. {
  4125. $this->session->set_flashdata('message_success', lang('preferences_updated'));
  4126. $this->functions->redirect($loc);
  4127. }
  4128. }
  4129. // --------------------------------------------------------------------
  4130. /**
  4131. * Restrict Access
  4132. *
  4133. * Helper function for the most common access level in this class
  4134. *
  4135. * @access private
  4136. * @return void
  4137. */
  4138. private function _restrict_prefs_access()
  4139. {
  4140. if ( ! $this->cp->allowed_group(
  4141. 'can_access_admin',
  4142. 'can_admin_channels',
  4143. 'can_access_content_prefs'
  4144. ))
  4145. {
  4146. show_error(lang('unauthorized_access'));
  4147. }
  4148. }
  4149. }
  4150. // END CLASS
  4151. /* End of file admin_content.php */
  4152. /* Location: ./system/expressionengine/controllers/cp/admin_content.php */