PageRenderTime 266ms CodeModel.GetById 30ms RepoModel.GetById 2ms app.codeStats 1ms

/system/expressionengine/third_party/freeform/mcp.freeform.php

https://bitbucket.org/studiobreakfast/sync
PHP | 6572 lines | 3700 code | 1362 blank | 1510 comment | 411 complexity | 51f7cd09070ec34e760f2c338908caf7 MD5 | raw file

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

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Solspace - Freeform
  4. *
  5. * @package Solspace:Freeform
  6. * @author Solspace DevTeam
  7. * @copyright Copyright (c) 2008-2012, Solspace, Inc.
  8. * @link http://solspace.com/docs/addon/c/Freeform/
  9. * @version 4.0.8
  10. * @filesource ./system/expressionengine/third_party/freeform/
  11. */
  12. /**
  13. * Freeform - Control Panel
  14. *
  15. * The Control Panel master class that handles all of the CP Requests and Displaying
  16. *
  17. * @package Solspace:Freeform
  18. * @author Solspace DevTeam
  19. * @filesource ./system/expressionengine/third_party/freeform/mcp.freeform.php
  20. */
  21. if ( ! class_exists('Module_builder_freeform'))
  22. {
  23. require_once 'addon_builder/module_builder.php';
  24. }
  25. class Freeform_mcp extends Module_builder_freeform
  26. {
  27. private $migration_batch_limit = 100;
  28. private $pro_update = FALSE;
  29. // --------------------------------------------------------------------
  30. /**
  31. * Constructor
  32. *
  33. * @access public
  34. * @param bool Enable calling of methods based on URI string
  35. * @return string
  36. */
  37. public function __construct( $switch = TRUE )
  38. {
  39. parent::__construct('freeform');
  40. // Install or Uninstall Request
  41. if ((bool) $switch === FALSE) return;
  42. if ( ! function_exists('lang'))
  43. {
  44. ee()->load->helper('language');
  45. }
  46. // --------------------------------------------
  47. // Module Menu Items
  48. // --------------------------------------------
  49. $menu = array(
  50. 'module_forms' => array(
  51. 'link' => $this->base,
  52. 'title' => lang('forms')
  53. ),
  54. 'module_fields' => array(
  55. 'link' => $this->base . AMP . 'method=fields',
  56. 'title' => lang('fields')
  57. ),
  58. 'module_fieldtypes' => array(
  59. 'link' => $this->base . AMP . 'method=fieldtypes',
  60. 'title' => lang('fieldtypes')
  61. ),
  62. 'module_notifications' => array(
  63. 'link' => $this->base . AMP . 'method=notifications',
  64. 'title' => lang('notifications')
  65. ),
  66. /*'module_export' => array(
  67. 'link' => $this->base . AMP . 'method=export',
  68. 'title' => lang('export')
  69. ),*/
  70. 'module_utilities' => array(
  71. 'link' => $this->base . AMP . 'method=utilities',
  72. 'title' => lang('utilities')
  73. ),
  74. 'module_preferences' => array(
  75. 'link' => $this->base . AMP . 'method=preferences',
  76. 'title' => lang('preferences')
  77. ),
  78. 'module_documentation' => array(
  79. 'link' => FREEFORM_DOCS_URL,
  80. 'title' => lang('help'),
  81. 'new_window' => TRUE
  82. ),
  83. );
  84. $this->cached_vars['lang_module_version'] = lang('freeform_module_version');
  85. $this->cached_vars['module_version'] = FREEFORM_VERSION;
  86. $this->cached_vars['module_menu_highlight'] = 'module_forms';
  87. $this->cached_vars['inner_nav_links'] = array();
  88. // -------------------------------------
  89. // css includes. WOOT!
  90. // -------------------------------------
  91. $this->cached_vars['cp_stylesheet'] = array(
  92. 'chosen',
  93. 'standard_cp'
  94. );
  95. $this->cached_vars['cp_javascript'] = array(
  96. 'standard_cp.min',
  97. 'chosen.jquery.min'
  98. );
  99. // -------------------------------------
  100. // custom CP?
  101. // -------------------------------------
  102. $debug_normal = (ee()->input->get_post('debug_normal') !== FALSE);
  103. $is_crappy_ie_version = FALSE;
  104. $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
  105. if (stristr($ua, 'msie 6') OR
  106. stristr($ua, 'msie 7') OR
  107. stristr($ua, 'msie 8'))
  108. {
  109. $is_crappy_ie_version = TRUE;
  110. }
  111. if ( ! $debug_normal AND
  112. ! $is_crappy_ie_version AND
  113. ! $this->check_no($this->preference('use_solspace_mcp_style')))
  114. {
  115. $this->cached_vars['cp_stylesheet'][] = 'custom_cp';
  116. }
  117. // -------------------------------------
  118. // Module Installed and What Version?
  119. // -------------------------------------
  120. if ($this->database_version() == FALSE)
  121. {
  122. return;
  123. }
  124. else if ($this->version_compare($this->database_version(), '<', FREEFORM_VERSION)
  125. OR ! $this->extensions_enabled())
  126. {
  127. // For EE 2.x, we need to redirect the request to
  128. // Update Routine
  129. $_GET['method'] = 'freeform_module_update';
  130. }
  131. //avoids AR collisions
  132. $this->data->get_module_preferences();
  133. $this->data->get_global_module_preferences();
  134. $this->data->show_all_sites();
  135. // -------------------------------------
  136. // run upgrade or downgrade scripts
  137. // -------------------------------------
  138. if (FREEFORM_PRO AND $this->data->global_preference('ffp') === 'n' OR
  139. ! FREEFORM_PRO AND $this->data->global_preference('ffp') === 'y')
  140. {
  141. $_GET['method'] = 'freeform_module_update';
  142. $this->pro_update = TRUE;
  143. }
  144. $this->cached_vars['module_menu'] = $menu;
  145. }
  146. // END Freeform_cp_base()
  147. //---------------------------------------------------------------------
  148. // begin views
  149. //---------------------------------------------------------------------
  150. // --------------------------------------------------------------------
  151. /**
  152. * Module's Main Homepage
  153. *
  154. * @access public
  155. * @param string
  156. * @return null
  157. */
  158. public function index ($message='')
  159. {
  160. if ($message == '' AND ee()->input->get('msg') !== FALSE)
  161. {
  162. $message = lang(ee()->input->get('msg'));
  163. }
  164. return $this->forms($message);
  165. }
  166. // END index()
  167. // --------------------------------------------------------------------
  168. /**
  169. * My Forms
  170. *
  171. * @access public
  172. * @param string $message incoming message for flash data
  173. * @return string html output
  174. */
  175. public function forms ( $message = '' )
  176. {
  177. // -------------------------------------
  178. // Messages
  179. // -------------------------------------
  180. if ($message == '' AND ! in_array(ee()->input->get('msg'), array(FALSE, '')) )
  181. {
  182. $message = lang(ee()->input->get('msg'));
  183. }
  184. $this->cached_vars['message'] = $message;
  185. //--------------------------------------------
  186. // Crumbs and tab highlight
  187. //--------------------------------------------
  188. $new_form_link = $this->mod_link(array(
  189. 'method' => 'edit_form'
  190. ));
  191. $this->cached_vars['new_form_link'] = $new_form_link;
  192. $this->add_crumb( lang('forms') );
  193. $this->freeform_add_right_link(lang('new_form'), $new_form_link);
  194. $this->set_highlight('module_forms');
  195. //--------------------------------------
  196. // start vars
  197. //--------------------------------------
  198. $row_limit = $this->data->defaults['mcp_row_limit'];
  199. $paginate = '';
  200. $row_count = 0;
  201. // -------------------------------------
  202. // pagination?
  203. // -------------------------------------
  204. ee()->load->model('freeform_form_model');
  205. if ( ! $this->data->show_all_sites())
  206. {
  207. ee()->freeform_form_model->where(
  208. 'site_id',
  209. ee()->config->item('site_id')
  210. );
  211. }
  212. $total_results = ee()->freeform_form_model->count(array(), FALSE);
  213. // do we need pagination?
  214. if ( $total_results > $row_limit )
  215. {
  216. $row_count = $this->get_post_or_zero('row');
  217. $url = $this->mod_link(array(
  218. 'method' => 'forms'
  219. ));
  220. //get pagination info
  221. $pagination_data = $this->universal_pagination(array(
  222. 'total_results' => $total_results,
  223. 'limit' => $row_limit,
  224. 'current_page' => $row_count,
  225. 'pagination_config' => array('base_url' => $url),
  226. 'query_string_segment' => 'row'
  227. ));
  228. ee()->freeform_form_model->limit(
  229. $row_limit,
  230. $pagination_data['pagination_page']
  231. );
  232. $paginate = $pagination_data['pagination_links'];
  233. }
  234. ee()->freeform_form_model->order_by('form_label');
  235. $this->cached_vars['paginate'] = $paginate;
  236. // -------------------------------------
  237. // Did they upgrade from FF3?
  238. // -------------------------------------
  239. $this->cached_vars['legacy'] = FALSE;
  240. $this->cached_vars['migrate_link'] = '';
  241. ee()->load->library('freeform_migration');
  242. if ( ee()->freeform_migration->legacy() === TRUE )
  243. {
  244. $this->cached_vars['legacy'] = TRUE;
  245. $this->cached_vars['migrate_link'] = $this->mod_link(array('method' => 'utilities'));
  246. }
  247. // -------------------------------------
  248. // data
  249. // -------------------------------------
  250. $rows = ee()->freeform_form_model->get();
  251. $form_data = array();
  252. if ($rows !== FALSE)
  253. {
  254. // -------------------------------------
  255. // check for composer for each form
  256. // -------------------------------------
  257. $form_ids = array();
  258. $potential_composer_ids = array();
  259. foreach ($rows as $row)
  260. {
  261. $form_ids[] = $row['form_id'];
  262. if ($this->is_positive_intlike($row['composer_id']))
  263. {
  264. $potential_composer_ids[$row['form_id']] = $row['composer_id'];
  265. }
  266. }
  267. $has_composer = array();
  268. if ( ! empty($potential_composer_ids))
  269. {
  270. ee()->load->model('freeform_composer_model');
  271. $composer_ids = ee()->freeform_composer_model
  272. ->key('composer_id', 'composer_id')
  273. ->where('preview !=', 'y')
  274. ->where_in(
  275. 'composer_id',
  276. array_values($potential_composer_ids)
  277. )
  278. ->get();
  279. if ( ! empty($composer_ids))
  280. {
  281. foreach ($potential_composer_ids as $form_id => $composer_id)
  282. {
  283. if (in_array($composer_id, $composer_ids))
  284. {
  285. $has_composer[$form_id] = $composer_id;
  286. }
  287. }
  288. }
  289. }
  290. // -------------------------------------
  291. // suppliment rows
  292. // -------------------------------------
  293. foreach ($rows as $row)
  294. {
  295. $row['submissions_count'] = (
  296. $this->data->get_form_submissions_count($row['form_id'])
  297. );
  298. $row['moderate_count'] = (
  299. $this->data->get_form_needs_moderation_count($row['form_id'])
  300. );
  301. $row['has_composer'] = isset(
  302. $has_composer[$row['form_id']]
  303. );
  304. // -------------------------------------
  305. // piles o' links
  306. // -------------------------------------
  307. $row['form_submissions_link'] = $this->mod_link(array(
  308. 'method' => 'entries',
  309. 'form_id' => $row['form_id']
  310. ));
  311. $row['form_moderate_link'] = $this->mod_link(array(
  312. 'method' => 'moderate_entries',
  313. 'form_id' => $row['form_id'],
  314. 'search_status' => 'pending'
  315. ));
  316. $row['form_edit_composer_link'] = $this->mod_link(array(
  317. 'method' => 'form_composer',
  318. 'form_id' => $row['form_id']
  319. ));
  320. $row['form_settings_link'] = $this->mod_link(array(
  321. 'method' => 'edit_form',
  322. 'form_id' => $row['form_id']
  323. ));
  324. $row['form_duplicate_link'] = $this->mod_link(array(
  325. 'method' => 'edit_form',
  326. 'duplicate_id' => $row['form_id']
  327. ));
  328. $row['form_delete_link'] = $this->mod_link(array(
  329. 'method' => 'delete_confirm_form',
  330. 'form_id' => $row['form_id']
  331. ));
  332. $form_data[] = $row;
  333. }
  334. }
  335. $this->cached_vars['form_data'] = $form_data;
  336. $this->cached_vars['form_url'] = $this->mod_link(array(
  337. 'method' => 'delete_confirm_form'
  338. ));
  339. // ----------------------------------------
  340. // Load vars
  341. // ----------------------------------------
  342. // -------------------------------------
  343. // JS
  344. // -------------------------------------
  345. ee()->cp->add_js_script(
  346. array('plugin' => array('tooltip', 'dataTables'))
  347. );
  348. // --------------------------------------------
  349. // Load page
  350. // --------------------------------------------
  351. $this->cached_vars['current_page'] = $this->view(
  352. 'forms.html',
  353. NULL,
  354. TRUE
  355. );
  356. return $this->ee_cp_view('index.html');
  357. }
  358. //END forms
  359. // --------------------------------------------------------------------
  360. /**
  361. * delete_confirm_form
  362. *
  363. * @access public
  364. * @return string
  365. */
  366. public function delete_confirm_form ()
  367. {
  368. $form_ids = ee()->input->get_post('form_id', TRUE);
  369. if ( ! is_array($form_ids) AND
  370. ! $this->is_positive_intlike($form_ids) )
  371. {
  372. $this->actions()->full_stop(lang('no_form_ids_submitted'));
  373. }
  374. //already checked for numeric :p
  375. if ( ! is_array($form_ids))
  376. {
  377. $form_ids = array($form_ids);
  378. }
  379. return $this->delete_confirm(
  380. 'delete_forms',
  381. array('form_ids' => $form_ids),
  382. 'delete_form_confirmation'
  383. );
  384. }
  385. //END delete_confirm_form
  386. // --------------------------------------------------------------------
  387. /**
  388. * delete_forms
  389. *
  390. * @access public
  391. * @return string
  392. */
  393. public function delete_forms ($form_ids = array())
  394. {
  395. $message = 'delete_form_success';
  396. if ( empty($form_ids) )
  397. {
  398. $form_ids = ee()->input->get_post('form_ids');
  399. }
  400. if ( ! is_array($form_ids) AND
  401. $this->is_positive_intlike($form_ids))
  402. {
  403. $form_ids = array($form_ids);
  404. }
  405. //if everything is all nice and array like, DELORT
  406. //but one last check on each item to make sure its a number
  407. if ( is_array($form_ids))
  408. {
  409. ee()->load->library('freeform_forms');
  410. foreach ($form_ids as $form_id)
  411. {
  412. if ($this->is_positive_intlike($form_id))
  413. {
  414. ee()->freeform_forms->delete_form($form_id);
  415. }
  416. }
  417. }
  418. //the voyage home
  419. ee()->functions->redirect($this->mod_link(array(
  420. 'method' => 'index',
  421. 'msg' => $message
  422. )));
  423. }
  424. //END delete_forms
  425. // --------------------------------------------------------------------
  426. /**
  427. * Edit Form
  428. *
  429. * @access public
  430. * @return string html output
  431. */
  432. public function edit_form ()
  433. {
  434. // -------------------------------------
  435. // form ID? we must be editing
  436. // -------------------------------------
  437. $form_id = $this->get_post_or_zero('form_id');
  438. $update = $this->cached_vars['update'] = ($form_id != 0);
  439. // -------------------------------------
  440. // default data
  441. // -------------------------------------
  442. $inputs = array(
  443. 'form_id' => '0',
  444. 'form_name' => '',
  445. 'form_label' => '',
  446. 'default_status' => $this->data->defaults['default_form_status'],
  447. 'notify_admin' => 'n',
  448. 'notify_user' => 'n',
  449. 'user_email_field' => '',
  450. 'user_notification_id' => '0',
  451. 'admin_notification_id' => '0',
  452. 'admin_notification_email' => ee()->config->item('webmaster_email'),
  453. 'form_description' => '',
  454. 'template_id' => '0',
  455. 'composer_id' => '0',
  456. 'field_ids' => '',
  457. 'field_order' => '',
  458. );
  459. // -------------------------------------
  460. // updating?
  461. // -------------------------------------
  462. if ($update)
  463. {
  464. $form_data = $this->data->get_form_info($form_id);
  465. if ($form_data)
  466. {
  467. foreach ($form_data as $key => $value)
  468. {
  469. if ($key == 'admin_notification_email')
  470. {
  471. $value = str_replace('|', ', ', $value);
  472. }
  473. if ($key == 'field_ids' AND ! empty($value))
  474. {
  475. $value = implode('|', $value);
  476. }
  477. $inputs[$key] = form_prep($value);
  478. }
  479. }
  480. else
  481. {
  482. $this->actions()->full_stop(lang('invalid_form_id'));
  483. }
  484. }
  485. //--------------------------------------------
  486. // Crumbs and tab highlight
  487. //--------------------------------------------
  488. $this->add_crumb(
  489. lang('forms'),
  490. $this->mod_link(array('method' => 'forms'))
  491. );
  492. $this->add_crumb(
  493. $update ?
  494. lang('update_form') . ': ' . $form_data['form_label'] :
  495. lang('new_form')
  496. );
  497. $this->set_highlight('module_forms');
  498. // -------------------------------------
  499. // duplicating?
  500. // -------------------------------------
  501. $duplicate_id = $this->get_post_or_zero('duplicate_id');
  502. $this->cached_vars['duplicate_id'] = $duplicate_id;
  503. $this->cached_vars['duplicated'] = FALSE;
  504. if ( ! $update AND $duplicate_id > 0)
  505. {
  506. $form_data = $this->data->get_form_info($duplicate_id);
  507. if ($form_data)
  508. {
  509. foreach ($form_data as $key => $value)
  510. {
  511. if (in_array($key, array('form_id', 'form_label', 'form_name')))
  512. {
  513. continue;
  514. }
  515. if ($key == 'admin_notification_email')
  516. {
  517. $value = str_replace('|', ', ', $value);
  518. }
  519. $inputs[$key] = $value;
  520. }
  521. $this->cached_vars['duplicated'] = TRUE;
  522. $this->cached_vars['duplicated_from'] = $form_data['form_label'];
  523. }
  524. }
  525. if (isset($form_data['field_ids']) AND
  526. ! empty($form_data['field_ids']) AND
  527. isset($form_data['field_order']) AND
  528. ! empty($form_data['field_order']))
  529. {
  530. $field_ids = $form_data['field_ids'];
  531. if ( ! is_array($field_ids))
  532. {
  533. $field_ids = $this->actions()->pipe_split($field_ids);
  534. }
  535. $field_order = $form_data['field_order'];
  536. if ( ! is_array($field_order))
  537. {
  538. $field_order = $this->actions()->pipe_split($field_order);
  539. }
  540. $missing_ids = array_diff($field_ids, $field_order);
  541. $inputs['field_order'] = implode('|', array_merge($field_order, $missing_ids));
  542. }
  543. // -------------------------------------
  544. // load inputs
  545. // -------------------------------------
  546. foreach ($inputs as $key => $value)
  547. {
  548. $this->cached_vars[$key] = $value;
  549. }
  550. // -------------------------------------
  551. // select boxes
  552. // -------------------------------------
  553. $this->cached_vars['statuses'] = $this->data->get_form_statuses();
  554. ee()->load->model('freeform_field_model');
  555. $available_fields = ee()->freeform_field_model->get();
  556. $available_fields = ($available_fields !== FALSE) ?
  557. $available_fields :
  558. array();
  559. //fields
  560. $this->cached_vars['available_fields'] = $available_fields;
  561. //notifications
  562. $this->cached_vars['notifications'] = $this->data->get_available_notification_templates();
  563. // -------------------------------------
  564. // user email fields
  565. // -------------------------------------
  566. $user_email_fields = array('' => lang('choose_user_email_field'));
  567. $f_rows = ee()->freeform_field_model
  568. ->select('field_id, field_label, settings')
  569. ->get(array('field_type' => 'text'));
  570. //we only want fields that are being validated as email
  571. if ($f_rows)
  572. {
  573. foreach ($f_rows as $row)
  574. {
  575. $row_settings = json_decode($row['settings'], TRUE);
  576. $row_settings = (is_array($row_settings)) ? $row_settings : array();
  577. if (isset($row_settings['field_content_type']) AND
  578. $row_settings['field_content_type'] == 'email')
  579. {
  580. $user_email_fields[$row['field_id']] = $row['field_label'];
  581. }
  582. }
  583. }
  584. $this->cached_vars['user_email_fields'] = $user_email_fields;
  585. // ----------------------------------------
  586. // Load vars
  587. // ----------------------------------------
  588. $this->cached_vars['form_uri'] = $this->mod_link(array(
  589. 'method' => 'save_form'
  590. ));
  591. // -------------------------------------
  592. // js libs
  593. // -------------------------------------
  594. $this->load_fancybox();
  595. $this->cached_vars['cp_javascript'][] = 'jquery.smooth-scroll.min';
  596. ee()->cp->add_js_script(array(
  597. 'ui' => array('draggable', 'droppable', 'sortable')
  598. ));
  599. // --------------------------------------------
  600. // Load page
  601. // --------------------------------------------
  602. $this->cached_vars['current_page'] = $this->view(
  603. 'edit_form.html',
  604. NULL,
  605. TRUE
  606. );
  607. return $this->ee_cp_view('index.html');
  608. }
  609. //END edit_form
  610. // --------------------------------------------------------------------
  611. /**
  612. * form composer
  613. *
  614. * ajax form and field builder
  615. *
  616. * @access public
  617. * @param string message lang line
  618. * @return string html output
  619. */
  620. public function form_composer ( $message = '' )
  621. {
  622. // -------------------------------------
  623. // Messages
  624. // -------------------------------------
  625. if ($message == '' AND ! in_array(ee()->input->get('msg'), array(FALSE, '')) )
  626. {
  627. $message = lang(ee()->input->get('msg'));
  628. }
  629. $this->cached_vars['message'] = $message;
  630. // -------------------------------------
  631. // form_id
  632. // -------------------------------------
  633. $form_id = ee()->input->get_post('form_id', TRUE);
  634. $form_data = $this->data->get_form_info($form_id);
  635. if ( ! $form_data)
  636. {
  637. return $this->actions()->full_stop(lang('invalid_form_id'));
  638. }
  639. $update = $form_data['composer_id'] != 0;
  640. //--------------------------------------------
  641. // Crumbs and tab highlight
  642. //--------------------------------------------
  643. $this->add_crumb( lang('forms'), $this->base );
  644. $this->add_crumb( lang('composer') . ': ' . $form_data['form_label'] );
  645. $this->set_highlight('module_forms');
  646. // -------------------------------------
  647. // data
  648. // -------------------------------------
  649. $this->cached_vars['form_data'] = $form_data;
  650. // -------------------------------------
  651. // fields for composer
  652. // -------------------------------------
  653. ee()->load->model('freeform_field_model');
  654. $available_fields = ee()->freeform_field_model
  655. ->where('composer_use', 'y')
  656. ->order_by('field_label')
  657. ->key('field_name')
  658. ->get();
  659. $available_fields = ($available_fields !== FALSE) ?
  660. $available_fields :
  661. array();
  662. // -------------------------------------
  663. // templates
  664. // -------------------------------------
  665. ee()->load->model('freeform_template_model');
  666. $available_templates = ee()->freeform_template_model
  667. ->where('enable_template', 'y')
  668. ->order_by('template_label')
  669. ->key('template_id', 'template_label')
  670. ->get();
  671. $available_templates = ($available_templates !== FALSE) ?
  672. $available_templates :
  673. array();
  674. // -------------------------------------
  675. // get field output for composer
  676. // -------------------------------------
  677. ee()->load->library('freeform_fields');
  678. $field_composer_output = array();
  679. $field_id_list = array();
  680. foreach ($available_fields as $field_name => $field_data)
  681. {
  682. $field_id_list[$field_data['field_id']] = $field_name;
  683. //encode to keep JS from running
  684. //camel case because its exposed in JS
  685. $field_composer_output[$field_name] = $this->composer_field_data(
  686. $field_data['field_id'],
  687. $field_data,
  688. TRUE
  689. );
  690. }
  691. $this->cached_vars['field_id_list'] = $this->json_encode($field_id_list);
  692. $this->cached_vars['field_composer_output_json'] = $this->json_encode($field_composer_output);
  693. $this->cached_vars['available_fields'] = $available_fields;
  694. $this->cached_vars['available_templates'] = $available_templates;
  695. $this->cached_vars['prohibited_field_names'] = $this->data->prohibited_names;
  696. $this->cached_vars['notifications'] = $this->data->get_available_notification_templates();
  697. // -------------------------------------
  698. // previous composer data?
  699. // -------------------------------------
  700. $composer_data = '{}';
  701. if ($form_data['composer_id'] > 0)
  702. {
  703. ee()->load->model('freeform_composer_model');
  704. $composer = ee()->freeform_composer_model
  705. ->select('composer_data')
  706. ->where('composer_id', $form_data['composer_id'])
  707. ->get_row();
  708. if ($composer !== FALSE)
  709. {
  710. $composer_data_test = $this->json_decode($composer['composer_data']);
  711. if ($composer_data_test)
  712. {
  713. $composer_data = $composer['composer_data'];
  714. }
  715. }
  716. }
  717. $this->cached_vars['composer_layout_data'] = $composer_data;
  718. // ----------------------------------------
  719. // Load vars
  720. // ----------------------------------------
  721. $this->cached_vars['lang_allowed_html_tags'] = (
  722. lang('allowed_html_tags') .
  723. "&lt;" . implode("&gt;, &lt;", $this->data->allowed_html_tags) . "&gt;"
  724. );
  725. $this->cached_vars['captcha_dummy_url'] = $this->sc->addon_theme_url .
  726. 'images/captcha.png';
  727. $this->cached_vars['new_field_url'] = $this->mod_link(array(
  728. 'method' => 'edit_field',
  729. //this builds a URL, so yes this is intentionally a string
  730. 'modal' => 'true'
  731. ), TRUE);
  732. $this->cached_vars['field_data_url'] = $this->mod_link(array(
  733. 'method' => 'composer_field_data'
  734. ), TRUE);
  735. $this->cached_vars['composer_preview_url'] = $this->mod_link(array(
  736. 'method' => 'composer_preview',
  737. 'form_id' => $form_id
  738. ), TRUE);
  739. $this->cached_vars['composer_ajax_save_url'] = $this->mod_link(array(
  740. 'method' => 'save_composer_data',
  741. 'form_id' => $form_id
  742. ), TRUE);
  743. //
  744. $this->cached_vars['composer_save_url'] = $this->mod_link(array(
  745. 'method' => 'save_composer_data',
  746. 'form_id' => $form_id
  747. ));
  748. $this->cached_vars['allowed_html_tags'] = "'" .
  749. implode("','", $this->data->allowed_html_tags) . "'";
  750. // -------------------------------------
  751. // js libs
  752. // -------------------------------------
  753. $this->load_fancybox();
  754. ee()->cp->add_js_script(array(
  755. 'ui' => array('sortable', 'draggable', 'droppable'),
  756. 'file' => array('underscore', 'json2')
  757. ));
  758. // --------------------------------------------
  759. // Load page
  760. // --------------------------------------------
  761. $this->cached_vars['cp_javascript'][] = 'composer_cp.min';
  762. $this->cached_vars['cp_javascript'][] = 'edit_field_cp.min';
  763. $this->cached_vars['cp_javascript'][] = 'security.min';
  764. $this->cached_vars['current_page'] = $this->view(
  765. 'composer.html',
  766. NULL,
  767. TRUE
  768. );
  769. return $this->ee_cp_view('index.html');
  770. }
  771. //END form_composer
  772. // --------------------------------------------------------------------
  773. /**
  774. * Composer preview
  775. *
  776. * @access public
  777. * @return mixed ajax return if detected or else html without cp
  778. */
  779. public function composer_preview ()
  780. {
  781. $form_id = $this->get_post_or_zero('form_id');
  782. $template_id = $this->get_post_or_zero('template_id');
  783. $composer_id = $this->get_post_or_zero('composer_id');
  784. $preview_id = $this->get_post_or_zero('preview_id');
  785. $subpreview = (ee()->input->get_post('subpreview') !== FALSE);
  786. $composer_page = $this->get_post_or_zero('composer_page');
  787. if ( ! $this->data->is_valid_form_id($form_id))
  788. {
  789. $this->actions()->full_stop(lang('invalid_form_id'));
  790. }
  791. // -------------------------------------
  792. // is this a preview?
  793. // -------------------------------------
  794. if ($preview_id > 0)
  795. {
  796. $preview_mode = TRUE;
  797. $composer_id = $preview_id;
  798. }
  799. $page_count = 1;
  800. // -------------------------------------
  801. // main output or sub output?
  802. // -------------------------------------
  803. if ( ! $subpreview)
  804. {
  805. // -------------------------------------
  806. // get composer data and build page count
  807. // -------------------------------------
  808. if ($composer_id > 0)
  809. {
  810. ee()->load->model('freeform_composer_model');
  811. $composer = ee()->freeform_composer_model
  812. ->select('composer_data')
  813. ->where('composer_id', $composer_id)
  814. ->get_row();
  815. if ($composer !== FALSE)
  816. {
  817. $composer_data = $this->json_decode(
  818. $composer['composer_data'],
  819. TRUE
  820. );
  821. if ($composer_data AND
  822. isset($composer_data['rows']) AND
  823. ! empty($composer_data['rows']))
  824. {
  825. foreach ($composer_data['rows'] as $row)
  826. {
  827. if ($row == 'page_break')
  828. {
  829. $page_count++;
  830. }
  831. }
  832. }
  833. }
  834. }
  835. $page_url = array();
  836. for ($i = 1, $l = $page_count; $i <= $l; $i++)
  837. {
  838. $page_url[] = $this->mod_link(array(
  839. 'method' => __FUNCTION__,
  840. 'form_id' => $form_id,
  841. 'template_id' => $template_id,
  842. 'preview_id' => $preview_id,
  843. 'subpreview' => 'true',
  844. 'composer_page' => $i
  845. ));
  846. }
  847. $this->cached_vars['page_url'] = $page_url;
  848. $this->cached_vars['default_preview_css'] = $this->sc->addon_theme_url .
  849. 'css/default_composer.css';
  850. $this->cached_vars['jquery_src'] = rtrim(ee()->config->item('theme_folder_url'), '/') .
  851. '/javascript/compressed/jquery/jquery.js';
  852. $html = $this->view('composer_preview.html', NULL, TRUE);
  853. }
  854. else
  855. {
  856. $subhtml = "{exp:freeform:composer form_id='$form_id'";
  857. $subhtml .= ($composer_page > 1) ? " multipage_page='" . $composer_page . "'" : '';
  858. $subhtml .= ($template_id > 0) ? " composer_template_id='" . $template_id . "'" : '';
  859. $subhtml .= ($preview_id > 0) ? " preview_id='" . $preview_id . "'" : '';
  860. $subhtml .= "}";
  861. $html = $this->actions()->template()->process_string_as_template($subhtml);
  862. }
  863. if ($this->is_ajax_request())
  864. {
  865. return $this->send_ajax_response(array(
  866. 'success' => TRUE,
  867. 'html' => $html
  868. ));
  869. }
  870. else
  871. {
  872. exit($html);
  873. }
  874. }
  875. //end composer preview
  876. // --------------------------------------------------------------------
  877. /**
  878. * entries
  879. *
  880. * @access public
  881. * @param string $message message lang line
  882. * @param bool $moderate are we moderating?
  883. * @param bool $export export?
  884. * @return string html output
  885. */
  886. public function entries ( $message = '' , $moderate = FALSE, $export = FALSE)
  887. {
  888. // -------------------------------------
  889. // Messages
  890. // -------------------------------------
  891. if ($message == '' AND
  892. ! in_array(ee()->input->get('msg'), array(FALSE, '')) )
  893. {
  894. $message = lang(ee()->input->get('msg', TRUE));
  895. }
  896. $this->cached_vars['message'] = $message;
  897. // -------------------------------------
  898. // moderate
  899. // -------------------------------------
  900. $search_status = ee()->input->get_post('search_status');
  901. $moderate = (
  902. $moderate AND
  903. ($search_status == 'pending' OR
  904. $search_status === FALSE
  905. )
  906. );
  907. //if moderate and search status was not submitted, fake into pending
  908. if ($moderate AND $search_status === FALSE)
  909. {
  910. $_POST['search_status'] = 'pending';
  911. }
  912. $this->cached_vars['moderate'] = $moderate;
  913. $this->cached_vars['method'] = $method = (
  914. $moderate ? 'moderate_entries' : 'entries'
  915. );
  916. // -------------------------------------
  917. // form data? legit? GTFO?
  918. // -------------------------------------
  919. $form_id = ee()->input->get_post('form_id');
  920. ee()->load->library('freeform_forms');
  921. ee()->load->model('freeform_form_model');
  922. //form data does all of the proper id validity checks for us
  923. $form_data = $this->data->get_form_info($form_id);
  924. if ( ! $form_data)
  925. {
  926. $this->actions()->full_stop(lang('invalid_form_id'));
  927. exit();
  928. }
  929. $this->cached_vars['form_id'] = $form_id;
  930. $this->cached_vars['form_label'] = $form_data['form_label'];
  931. //--------------------------------------------
  932. // Crumbs and tab highlight
  933. //--------------------------------------------
  934. $this->add_crumb(
  935. lang('forms'),
  936. $this->mod_link(array('method' => 'forms'))
  937. );
  938. $this->add_crumb(
  939. $form_data['form_label'] . ': ' .
  940. lang($moderate ? 'moderate' : 'entries')
  941. );
  942. $this->set_highlight('module_forms');
  943. $this->freeform_add_right_link(
  944. lang('new_entry'),
  945. $this->mod_link(array(
  946. 'method' => 'edit_entry',
  947. 'form_id' => $form_id
  948. ))
  949. );
  950. // -------------------------------------
  951. // status prefs
  952. // -------------------------------------
  953. $form_statuses = $this->data->get_form_statuses();
  954. $this->cached_vars['form_statuses'] = $form_statuses;
  955. // -------------------------------------
  956. // rest of models
  957. // -------------------------------------
  958. ee()->load->model('freeform_entry_model');
  959. ee()->freeform_entry_model->id($form_id);
  960. // -------------------------------------
  961. // custom field labels
  962. // -------------------------------------
  963. $standard_columns = $this->get_standard_column_names();
  964. //we want author instead of author id until we get data
  965. $possible_columns = $standard_columns;
  966. //key = value
  967. $all_columns = array_combine($standard_columns, $standard_columns);
  968. $column_labels = array();
  969. $field_column_names = array();
  970. //field prefix
  971. $f_prefix = ee()->freeform_form_model->form_field_prefix;
  972. //keyed labels for the front end
  973. foreach ($standard_columns as $column_name)
  974. {
  975. $column_labels[$column_name] = lang($column_name);
  976. }
  977. // -------------------------------------
  978. // check for fields with custom views for entry tables
  979. // -------------------------------------
  980. ee()->load->library('freeform_fields');
  981. //fields in this form
  982. foreach ($form_data['fields'] as $field_id => $field_data)
  983. {
  984. //outputs form_field_1, form_field_2, etc for ->select()
  985. $field_id_name = $f_prefix . $field_id;
  986. $field_column_names[$field_id_name] = $field_data['field_name'];
  987. $all_columns[$field_id_name] = $field_data['field_name'];
  988. $column_labels[$field_data['field_name']] = $field_data['field_label'];
  989. $column_labels[$field_id_name] = $field_data['field_label'];
  990. $possible_columns[] = $field_id;
  991. $instance =& ee()->freeform_fields->get_field_instance(array(
  992. 'field_id' => $field_id,
  993. 'field_data' => $field_data
  994. ));
  995. if ( ! empty($instance->entry_views))
  996. {
  997. foreach ($instance->entry_views as $e_lang => $e_method)
  998. {
  999. $this->freeform_add_right_link(
  1000. $e_lang,
  1001. $this->mod_link(array(
  1002. 'method' => 'field_method',
  1003. 'field_id' => $field_id,
  1004. 'field_method' => $e_method,
  1005. 'form_id' => $form_id
  1006. ))
  1007. );
  1008. }
  1009. }
  1010. }
  1011. // -------------------------------------
  1012. // visible columns
  1013. // -------------------------------------
  1014. $visible_columns = $this->visible_columns($standard_columns, $possible_columns);
  1015. $this->cached_vars['visible_columns'] = $visible_columns;
  1016. $this->cached_vars['column_labels'] = $column_labels;
  1017. $this->cached_vars['possible_columns'] = $possible_columns;
  1018. $this->cached_vars['all_columns'] = $all_columns;
  1019. // -------------------------------------
  1020. // prep unused from from possible
  1021. // -------------------------------------
  1022. //so so used
  1023. $un_used = array();
  1024. foreach ($possible_columns as $pcid)
  1025. {
  1026. $check = ($this->is_positive_intlike($pcid)) ?
  1027. $f_prefix . $pcid :
  1028. $pcid;
  1029. if ( ! in_array($check, $visible_columns))
  1030. {
  1031. $un_used[] = $check;
  1032. }
  1033. }
  1034. $this->cached_vars['unused_columns'] = $un_used;
  1035. // -------------------------------------
  1036. // build query
  1037. // -------------------------------------
  1038. //base url for pagination
  1039. $pag_url = array(
  1040. 'method' => $method,
  1041. 'form_id' => $form_id
  1042. );
  1043. //cleans out blank keys from unset
  1044. $find_columns = array_merge(array(), $visible_columns);
  1045. $must_haves = array('entry_id');
  1046. // -------------------------------------
  1047. // search criteria
  1048. // building query
  1049. // -------------------------------------
  1050. $has_search = FALSE;
  1051. $search_vars = array(
  1052. 'search_keywords',
  1053. 'search_status',
  1054. 'search_date_range',
  1055. 'search_date_range_start',
  1056. 'search_date_range_end',
  1057. 'search_on_field'
  1058. );
  1059. foreach ($search_vars as $search_var)
  1060. {
  1061. $$search_var = ee()->input->get_post($search_var, TRUE);
  1062. //set for output
  1063. $this->cached_vars[$search_var] = (
  1064. ($$search_var) ? trim($$search_var) : ''
  1065. );
  1066. }
  1067. // -------------------------------------
  1068. // search keywords
  1069. // -------------------------------------
  1070. if ($search_keywords AND
  1071. trim($search_keywords) !== '' AND
  1072. $search_on_field AND
  1073. in_array($search_on_field, $visible_columns))
  1074. {
  1075. ee()->freeform_entry_model->like(
  1076. $search_on_field,
  1077. $search_keywords
  1078. );
  1079. //pagination
  1080. $pag_url['search_keywords'] = $search_keywords;
  1081. $pag_url['search_on_field'] = $search_on_field;
  1082. $has_search = TRUE;
  1083. }
  1084. //no search on field? guess we had better search it all *gulp*
  1085. else if ($search_keywords AND trim($search_keywords) !== '')
  1086. {
  1087. $first = TRUE;
  1088. ee()->freeform_entry_model->group_like(
  1089. $search_keywords,
  1090. array_values($visible_columns)
  1091. );
  1092. $pag_url['search_keywords'] = $search_keywords;
  1093. $has_search = TRUE;
  1094. }
  1095. //status search?
  1096. if ($moderate)
  1097. {
  1098. ee()->freeform_entry_model->where('status', 'pending');
  1099. }
  1100. else if ($search_status AND in_array($search_status, array_flip( $form_statuses)))
  1101. {
  1102. ee()->freeform_entry_model->where('status', $search_status);
  1103. //pagination
  1104. $pag_url['search_status'] = $search_status;
  1105. $has_search = TRUE;
  1106. }
  1107. // -------------------------------------
  1108. // date range?
  1109. // -------------------------------------
  1110. //pagination
  1111. if ($search_date_range == 'date_range')
  1112. {
  1113. if ($search_date_range_start !== FALSE)
  1114. {
  1115. $pag_url['search_date_range_start'] = $search_date_range_start;
  1116. }
  1117. if ($search_date_range_end !== FALSE)
  1118. {
  1119. $pag_url['search_date_range_end'] = $search_date_range_end;
  1120. }
  1121. //pagination
  1122. if ($search_date_range_start OR $search_date_range_end)
  1123. {
  1124. $pag_url['search_date_range'] = 'date_range';
  1125. $has_search = TRUE;
  1126. }
  1127. }
  1128. else if ($search_date_range !== FALSE)
  1129. {
  1130. $pag_url['search_date_range'] = $search_date_range;
  1131. $has_search = TRUE;
  1132. }
  1133. ee()->freeform_entry_model->date_where(
  1134. $search_date_range,
  1135. $search_date_range_start,
  1136. $search_date_range_end
  1137. );
  1138. // -------------------------------------
  1139. // any searches?
  1140. // -------------------------------------
  1141. $this->cached_vars['has_search'] = $has_search;
  1142. // -------------------------------------
  1143. // data from all sites?
  1144. // -------------------------------------
  1145. if ( ! $this->data->show_all_sites())
  1146. {
  1147. ee()->freeform_entry_model->where(
  1148. 'site_id',
  1149. ee()->config->item('site_id')
  1150. );
  1151. }
  1152. //we need the counts for exports and end results
  1153. $total_entries = ee()->freeform_entry_model->count(array(), FALSE);
  1154. // -------------------------------------
  1155. // orderby
  1156. // -------------------------------------
  1157. $order_by = 'entry_date';
  1158. $p_order_by = ee()->input->get_post('order_by');
  1159. if ($p_order_by !== FALSE AND in_array($p_order_by, $all_columns))
  1160. {
  1161. $order_by = $p_order_by;
  1162. $pag_url['order_by'] = $order_by;
  1163. }
  1164. // -------------------------------------
  1165. // sort
  1166. // -------------------------------------
  1167. $sort = ($order_by == 'entry_date') ? 'desc' : 'asc';
  1168. $p_sort = ee()->input->get_post('sort');
  1169. if ($p_sort !== FALSE AND
  1170. in_array(strtolower($p_sort), array('asc', 'desc')))
  1171. {
  1172. $sort = strtolower($p_sort);
  1173. $pag_url['sort'] = $sort;
  1174. }
  1175. ee()->freeform_entry_model->order_by($order_by, $sort);
  1176. $this->cached_vars['order_by'] = $order_by;
  1177. $this->cached_vars['sort'] = $sort;
  1178. // -------------------------------------
  1179. // export button
  1180. // -------------------------------------
  1181. if ($total_entries > 0)
  1182. {
  1183. $this->freeform_add_right_link(
  1184. lang('export_entries'),
  1185. '#export_entries'
  1186. );
  1187. }
  1188. // -------------------------------------
  1189. // export url
  1190. // -------------------------------------
  1191. $export_url = $pag_url;
  1192. $export_url['moderate'] = $moderate ? 'true' : 'false';
  1193. $export_url['method'] = 'export_entries';
  1194. $this->cached_vars['export_url'] = $this->mod_link($export_url);
  1195. // -------------------------------------
  1196. // export?
  1197. // -------------------------------------
  1198. if ($export)
  1199. {
  1200. $export_fields = ee()->input->get_post('export_fields');
  1201. $export_labels = $column_labels;
  1202. // -------------------------------------
  1203. // build possible select alls
  1204. // -------------------------------------
  1205. $select = array();
  1206. //are we sending just the selected fields?
  1207. if ($export_fields != 'all')
  1208. {
  1209. $select = array_unique(array_merge($must_haves, $find_columns));
  1210. foreach ($export_labels as $key => $value)
  1211. {
  1212. //clean export labels for json
  1213. if ( ! in_array($key, $select))
  1214. {
  1215. unset($export_labels[$key]);
  1216. }
  1217. }
  1218. //get real names
  1219. foreach ($select as $key => $value)
  1220. {
  1221. if (isset($field_column_names[$value]))
  1222. {
  1223. $select[$key] = $field_column_names[$value];
  1224. }
  1225. }
  1226. }
  1227. //sending all fields means we need to still clean some labels
  1228. else
  1229. {
  1230. foreach ($all_columns as $field_id_name => $field_name)
  1231. {
  1232. //clean export labels for json
  1233. if ($field_id_name != $field_name)
  1234. {
  1235. unset($export_labels[$field_id_name]);
  1236. }
  1237. $select[] = $field_name;
  1238. }
  1239. }
  1240. foreach ($export_labels as $key => $value)
  1241. {
  1242. //fix entities
  1243. $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
  1244. $export_labels[$key] = $value;
  1245. if (isset($field_column_names[$key]))
  1246. {
  1247. $export_labels[$field_column_names[$key]] = $value;
  1248. }
  1249. }
  1250. ee()->freeform_entry_model->select(implode(', ', $select));
  1251. // -------------------------------------
  1252. // check for chunking, etc
  1253. // -------------------------------------
  1254. ee()->load->library('freeform_export');
  1255. ee()->freeform_export->export(array(
  1256. 'method' => ee()->input->get_post('export_method'),
  1257. 'form_id' => $form_id,
  1258. 'form_name' => $form_data['form_name'],
  1259. 'output' => 'download',
  1260. 'model' => ee()->freeform_entry_model,
  1261. 'remove_entry_id' => ($export_fields != 'all' AND ! in_array('entry_id', $visible_columns)),
  1262. 'header_labels' => $export_labels,
  1263. 'total_entries' => $total_entries
  1264. ));
  1265. }
  1266. //END if ($export)
  1267. // -------------------------------------
  1268. // selects
  1269. // -------------------------------------
  1270. $needed_selects = array_unique(array_merge($must_haves, $find_columns));
  1271. ee()->freeform_entry_model->select(implode(', ', $needed_selects));
  1272. //--------------------------------------
  1273. // pagination start vars
  1274. //--------------------------------------
  1275. $pag_url = $this->mod_link($pag_url);
  1276. $row_limit = $this->data->defaults['mcp_row_limit'];
  1277. $paginate = '';
  1278. $row_count = 0;
  1279. //moved above exports
  1280. //$total_entries = ee()->freeform_entry_model->count(array(), FALSE);
  1281. $current_page = 0;
  1282. // -------------------------------------
  1283. // pagination?
  1284. // -------------------------------------
  1285. // do we need pagination?
  1286. if ($total_entries > $row_limit )
  1287. {
  1288. $row_count = $this->get_post_or_zero('row');
  1289. //get pagination info
  1290. $pagination_data = $this->universal_pagination(array(
  1291. 'total_results' => $total_entries,
  1292. 'limit' => $row_limit,
  1293. 'current_page' => $row_count,
  1294. 'pagination_config' => array('base_url' => $pag_url),
  1295. 'query_string_segment' => 'row'
  1296. ));
  1297. $paginate = $pagination_data['pagination_links'];
  1298. $current_page = $pagination_data['pagination_page'];
  1299. ee()->freeform_entry_model->limit($row_limit, $current_page);
  1300. }
  1301. $this->cached_vars['paginate'] = $paginate;
  1302. // -------------------------------------
  1303. // get data
  1304. // -------------------------------------
  1305. $result_array = ee()->freeform_entry_model->get();
  1306. $count = $row_count;
  1307. $entries = array();
  1308. if ( ! $result_array)
  1309. {
  1310. $result_array = array();
  1311. }
  1312. $entry_ids = array();
  1313. foreach ($result_array as $row)
  1314. {
  1315. $entry_ids[] = $row['entry_id'];
  1316. }
  1317. // -------------------------------------
  1318. // allow pre_process
  1319. // -------------------------------------
  1320. ee()->freeform_fields->apply_field_method(array(
  1321. 'method' => 'pre_process_entries',
  1322. 'form_id' => $form_id,
  1323. 'entry_id' => $entry_ids,
  1324. 'form_data' => $form_data,
  1325. 'field_data' => $form_data['fields']
  1326. ));
  1327. foreach ( $result_array as $row)
  1328. {
  1329. //apply display_entry_cp to our field data
  1330. $field_parse = ee()->freeform_fields->apply_field_method(array(
  1331. 'method' => 'display_entry_cp',
  1332. 'form_id' => $form_id,
  1333. 'entry_id' => $row['entry_id'],
  1334. 'form_data' => $form_data,
  1335. 'field_data' => $form_data['fields'],
  1336. 'field_input_data' => $row
  1337. ));
  1338. $row = array_merge($row, $field_parse['variables']);
  1339. $entry = array();
  1340. $entry['view_entry_link'] = $this->mod_link(array(
  1341. 'method' => 'view_entry',
  1342. 'form_id' => $form_id,
  1343. 'entry_id' => $row['entry_id']
  1344. ));
  1345. $entry['edit_entry_link'] = $this->mod_link(array(
  1346. 'method' => 'edit_entry',
  1347. 'form_id' => $form_id,
  1348. 'entry_id' => $row['entry_id']
  1349. ));
  1350. $entry['approve_link'] = $this->mod_link(array(
  1351. 'method' => 'approve_entries',
  1352. 'form_id' => $form_id,
  1353. 'entry_ids' => $row['entry_id']
  1354. ));
  1355. $entry['count'] = ++$count;
  1356. $entry['id'] = $row['entry_id'];
  1357. // -------------------------------------
  1358. // remove entry_id and author_id if we
  1359. // arent showing them
  1360. // -------------------------------------
  1361. if ( ! in_array('entry_id', $visible_columns))
  1362. {
  1363. unset($row['entry_id']);
  1364. }
  1365. // -------------------------------------
  1366. // dates
  1367. // -------------------------------------
  1368. if (in_array('entry_date', $visible_columns))
  1369. {
  1370. $row['entry_date'] = gmdate(
  1371. $this->preference('cp_date_formatting'),
  1372. ee()->localize->set_localized_time($row['entry_date'])
  1373. );
  1374. }
  1375. if (in_array('edit_date', $visible_columns))
  1376. {
  1377. $row['edit_date'] = (
  1378. ($row['edit_date'] > 0) ?
  1379. gmdate(
  1380. $this->preference('cp_date_formatting'),
  1381. ee()->localize->set_localized_time($row['edit_date'])
  1382. ) :
  1383. lang('n_a')
  1384. );
  1385. }
  1386. $entry['data'] = $row;
  1387. $entries[] = $entry;
  1388. }
  1389. $this->cached_vars['entries'] = $entries;
  1390. // -------------------------------------
  1391. // ajax request?
  1392. // -------------------------------------
  1393. if ($this->is_ajax_request())
  1394. {
  1395. $this->send_ajax_response(array(
  1396. 'entries' => $entries,
  1397. 'paginate' => $paginate,
  1398. 'visibleColumns' => $visible_columns,
  1399. 'allColumns' => $all_columns,
  1400. 'columnLabels' => $column_labels,
  1401. 'success' => TRUE
  1402. ));
  1403. exit();
  1404. }
  1405. // -------------------------------------
  1406. // moderation count?
  1407. // -------------------------------------
  1408. //lets not waste the query if we are already moderating
  1409. $moderation_count = (
  1410. ( ! $moderate) ?
  1411. $this->data->get_form_needs_moderation_count($form_id) :
  1412. 0
  1413. );
  1414. if ($moderation_count > 0)
  1415. {
  1416. $this->cached_vars['lang_num_items_awaiting_moderation'] = str_replace(
  1417. array('%num%', '%form_label%'),
  1418. array($moderation_count, $form_data['form_label']),
  1419. lang('num_items_awaiting_moderation')
  1420. );
  1421. }
  1422. $this->cached_vars['moderation_count'] = $moderation_count;
  1423. $this->cached_vars['moderation_link'] = $this->mod_link(array(
  1424. 'method' => 'moderate_entries',
  1425. 'form_id' => $form_id,
  1426. 'search_status' => 'pending'
  1427. ));
  1428. // -------------------------------------
  1429. // is admin?
  1430. // -------------------------------------
  1431. $this->cached_vars['is_admin'] = $is_admin = (
  1432. ee()->session->userdata('group_id') == 1
  1433. );
  1434. // -------------------------------------
  1435. // can save field layout?
  1436. // -------------------------------------
  1437. //$this->cached_vars['can_edit_layout'] = $can_edit_layout = (
  1438. // $is_admin OR
  1439. // $this->check_yes($this->preference('allow_user_field_layout'))
  1440. //);
  1441. //just in case
  1442. $this->cached_vars['can_edit_layout'] = TRUE;
  1443. $this->freeform_add_right_link(
  1444. lang('edit_field_layout'),
  1445. '#edit_field_layout'
  1446. );
  1447. // -------------------------------------
  1448. // member groups
  1449. // -------------------------------------
  1450. $member_groups = array();
  1451. if ($is_admin)
  1452. {
  1453. ee()->db->select('group_id, group_title');
  1454. $member_groups = $this->prepare_keyed_result(
  1455. ee()->db->get('member_groups'),
  1456. 'group_id',
  1457. 'group_title'
  1458. );
  1459. }
  1460. $this->cached_vars['member_groups'] = $member_groups;
  1461. // -------------------------------------
  1462. // lang items
  1463. // -------------------------------------
  1464. // -------------------------------------
  1465. // no results lang
  1466. // -------------------------------------
  1467. $this->cached_vars['lang_no_results_for_form'] = (
  1468. ($has_search) ?
  1469. lang('no_results_for_search') :
  1470. (
  1471. ($moderate) ?
  1472. lang('no_entries_awaiting_approval') :
  1473. lang('no_entries_for_form')
  1474. )
  1475. );
  1476. // -------------------------------------
  1477. // moderation lang
  1478. // -------------------------------------
  1479. $this->cached_vars['lang_viewing_moderation'] = str_replace(
  1480. '%form_label%',
  1481. $form_data['form_label'],
  1482. lang('viewing_moderation')
  1483. );
  1484. // -------------------------------------
  1485. // other vars
  1486. // -------------------------------------
  1487. $this->cached_vars['form_url'] = $this->mod_link(array(
  1488. 'method' => 'entries_action',
  1489. 'return_method' => (($moderate) ? 'moderate_' : '' ) . 'entries'
  1490. ));
  1491. $this->cached_vars['save_layout_url'] = $this->mod_link(array(
  1492. 'method' => 'save_field_layout'
  1493. ));
  1494. // -------------------------------------
  1495. // js libs
  1496. // -------------------------------------
  1497. $this->load_fancybox();
  1498. //$this->load_datatables();
  1499. ee()->cp->add_js_script(array(
  1500. 'ui' => array('datepicker', 'sortable'),
  1501. 'file' => 'underscore'
  1502. ));
  1503. // --------------------------------------------
  1504. // Load page
  1505. // --------------------------------------------
  1506. $this->cached_vars['current_page'] = $this->view(
  1507. 'entries.html',
  1508. NULL,
  1509. TRUE
  1510. );
  1511. return $this->ee_cp_view('index.html');
  1512. }
  1513. //END entries
  1514. // --------------------------------------------------------------------
  1515. public function field_method ($message = '')
  1516. {
  1517. // -------------------------------------
  1518. // Messages
  1519. // -------------------------------------
  1520. if ($message == '' AND
  1521. ! in_array(ee()->input->get('msg'), array(FALSE, '')) )
  1522. {
  1523. $message = lang(ee()->input->get('msg', TRUE));
  1524. }
  1525. $this->cached_vars['message'] = $message;
  1526. // -------------------------------------
  1527. // goods
  1528. // -------------------------------------
  1529. $form_id = $this->get_post_or_zero('form_id');
  1530. $field_id = $this->get_post_or_zero('field_id');
  1531. $field_method = ee()->input->get_post('field_method');
  1532. $instance = FALSE;
  1533. if ( $field_method == FALSE OR
  1534. ! $this->data->is_valid_form_id($form_id) OR
  1535. $field_id == 0)
  1536. {
  1537. ee()->functions->redirect($this->mod_link(array('method' => 'forms')));
  1538. }
  1539. ee()->load->library('freeform_fields');
  1540. $instance =& ee()->freeform_fields->get_field_instance(array(
  1541. 'form_id' => $form_id,
  1542. 'field_id' => $field_id
  1543. ));
  1544. //legit?
  1545. if ( ! is_object($instance) OR
  1546. empty($instance->entry_views) OR
  1547. //removed so you can post to this
  1548. //! in_array($field_method, $instance->entry_views) OR
  1549. ! is_callable(array($instance, $field_method)))
  1550. {
  1551. ee()->functions->redirect($this->mod_link(array('method' => 'forms')));
  1552. }
  1553. $method_lang = lang('field_entry_view');
  1554. foreach ($instance->entry_views as $e_lang => $e_method)
  1555. {
  1556. if ($field_method == $e_method)
  1557. {
  1558. $method_lang = $e_lang;
  1559. }
  1560. }
  1561. //--------------------------------------------
  1562. // Crumbs and tab highlight
  1563. //--------------------------------------------
  1564. $this->add_crumb(
  1565. lang('entries'),
  1566. $this->mod_link(array(
  1567. 'method' => 'entries',
  1568. 'form_id' => $form_id
  1569. ))
  1570. );
  1571. $this->add_crumb($method_lang);
  1572. $this->set_highlight('module_forms');
  1573. // --------------------------------------------
  1574. // Load page
  1575. // --------------------------------------------
  1576. $this

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