1: <?php
2:
3: 4: 5:
6: class Quform_Admin_Page_Entries_View extends Quform_Admin_Page_Entries
7: {
8: 9: 10:
11: protected $formFactory;
12:
13: 14: 15:
16: protected $options;
17:
18: 19: 20: 21: 22: 23:
24: public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository,
25: Quform_Form_Factory $formFactory, Quform_Options $options)
26: {
27: parent::__construct($viewFactory, $repository);
28:
29: $this->formFactory = $formFactory;
30: $this->options = $options;
31: }
32:
33: public function init()
34: {
35: $this->template = QUFORM_TEMPLATE_PATH . '/admin/entries/view.php';
36: }
37:
38: 39: 40:
41: protected function enqueueScripts()
42: {
43: wp_enqueue_script('js-cookie', Quform::adminUrl('js/js.cookie.min.js'), array(), '2.2.1', true);
44:
45: parent::enqueueScripts();
46:
47: wp_enqueue_script('quform-entries-view', Quform::adminUrl('js/entries.view.min.js'), array('jquery'), QUFORM_VERSION, true);
48:
49: wp_localize_script('quform-entries-view', 'quformEntriesViewL10n', array(
50: 'resendNotificationsNonce' => wp_create_nonce('quform_resend_notifications')
51: ));
52: }
53:
54: 55: 56: 57: 58:
59: protected function getAdminTitle()
60: {
61: return __('View Entry', 'quform');
62: }
63:
64: 65: 66: 67: 68: 69: 70:
71: public function getNavHtml(array $currentForm = null, array $extra = array())
72: {
73: $extra[10] = sprintf(
74: '<div class="qfb-nav-item"><a class="qfb-nav-item-link" href="%s"><i class="qfb-icon qfb-icon-arrow-left"></i></a></div>',
75: esc_url(add_query_arg(array(
76: 'id' => $currentForm['id'],
77: 'sp' => false,
78: 'eid' => false,
79: 'read' => false,
80: 'unread' => false,
81: 'error' => false,
82: 'deleted' => false
83: )))
84: );
85:
86: $extra[40] = sprintf(
87: '<div class="qfb-nav-item qfb-nav-page-info"><i class="qfb-nav-page-icon qfb-mdi qfb-mdi-message"></i><span class="qfb-nav-page-title">%s</span></div>',
88:
89: Quform::escape(sprintf(__('Viewing entry for %s', 'quform'), $currentForm['name']))
90: );
91:
92: return parent::getNavHtml($currentForm, $extra);
93: }
94:
95: 96: 97:
98: public function process()
99: {
100: if ( ! current_user_can('quform_view_entries')) {
101: wp_die(__( 'You do not have sufficient permissions to access this page.', 'quform'), 403);
102: }
103:
104: $entryId = isset($_GET['eid']) && is_numeric($_GET['eid']) ? (int) $_GET['eid'] : null;
105:
106: $entry = $this->repository->findEntry($entryId);
107:
108: if ( ! is_array($entry)) {
109: wp_die(__("You attempted to edit an item that doesn't exist. Perhaps it was deleted?", 'quform'));
110: }
111:
112: $formId = $this->repository->getFormIdFromEntryId($entryId);
113:
114: $config = $this->repository->getConfig($formId);
115:
116: if ( ! is_array($config)) {
117: wp_die(__("You attempted to edit an item that doesn't exist. Perhaps it was deleted?", 'quform'));
118: }
119:
120: $config['entryId'] = $entryId;
121: $config['environment'] = 'viewEntry';
122:
123: $form = $this->formFactory->create($config);
124:
125: $form->setValues(array(), true);
126:
127: foreach ($entry as $key => $value) {
128: if (preg_match('/element_(\d+)/', $key, $matches)) {
129: $elementId = $matches[1];
130: $form->setValueFromStorage($elementId, $value);
131: unset($entry[$key]);
132: }
133: }
134:
135:
136: $form->calculateElementVisibility();
137:
138:
139: if ($entry['unread'] == 1) {
140: $this->repository->readEntries(array($entry['id']));
141: }
142:
143:
144: $entry['labels'] = $this->repository->getEntryLabels($entryId);
145:
146: $data = array(
147: 'options' => $this->options,
148: 'form' => $form,
149: 'entry' => $entry,
150: 'showEmptyFields' => Quform::get($_COOKIE, 'qfb-show-empty-fields') ? true : false,
151: 'labels' => $this->repository->getFormEntryLabels($form->getId()),
152: 'notifications' => $form->getNotifications()
153: );
154:
155: $this->view->with($data);
156: }
157: }
158: