1: <?php
2:
3: 4: 5:
6: class Quform_Admin_Page_Forms_Edit extends Quform_Admin_Page
7: {
8: 9: 10:
11: protected $builder;
12:
13: 14: 15:
16: protected $license;
17:
18: 19: 20:
21: protected $options;
22:
23: 24: 25: 26: 27: 28: 29:
30: public function __construct(Quform_ViewFactory $viewFactory, Quform_Repository $repository, Quform_Builder $builder,
31: Quform_License $license, Quform_Options $options)
32: {
33: parent::__construct($viewFactory, $repository);
34:
35: $this->builder = $builder;
36: $this->viewFactory = $viewFactory;
37: $this->license = $license;
38: $this->options = $options;
39: }
40:
41: public function init()
42: {
43: $this->template = QUFORM_TEMPLATE_PATH . '/admin/forms/edit.php';
44: }
45:
46: protected function enqueueStyles()
47: {
48: wp_enqueue_style('qtip2', Quform::url('css/jquery.qtip.min.css'), array(), '3.0.4');
49: wp_enqueue_style('quform-select2', Quform::url('css/select2.min.css'), array(), '4.0.13');
50: wp_enqueue_style('spectrum', Quform::adminUrl('css/spectrum.min.css'), array(), '1.8.1');
51: wp_enqueue_style('quform-icons', Quform::url('css/quform-icons.min.css'), array(), QUFORM_VERSION);
52: wp_enqueue_style('kendo-common-material', Quform::url('css/kendo.common-material.min.css'), array(), '2020.2.617');
53: wp_enqueue_style('kendo-material', Quform::url('css/kendo.material.min.css'), array(), '2020.2.617');
54:
55: parent::enqueueStyles();
56:
57: wp_enqueue_style('quform-builder', Quform::adminUrl('css/builder.min.css'), array(), QUFORM_VERSION);
58: }
59:
60: protected function enqueueScripts()
61: {
62: parent::enqueueScripts();
63:
64: wp_enqueue_script('jeditable', Quform::adminUrl('js/jquery.jeditable.min.js'), array('jquery'), '2.0.17', true);
65: wp_enqueue_script('spectrum', Quform::adminUrl('js/spectrum.min.js'), array(), '1.8.1', true);
66: wp_enqueue_script('qtip2', Quform::url('js/jquery.qtip.min.js'), array('jquery'), '3.0.4', true);
67: wp_enqueue_script('quform-select2', Quform::url('js/select2.min.js'), array('jquery'), '4.0.13', true);
68: wp_enqueue_script('themecatcher-tabs', Quform::adminUrl('js/tc.tabs.min.js'), array('jquery'), '1.0.0', true);
69: wp_enqueue_script('kendo-core', Quform::url('js/kendo.core.min.js'), array('jquery'), '2020.2.617', true);
70: wp_enqueue_script('kendo-data', Quform::url('js/kendo.data.min.js'), array('kendo-core'), '2020.2.617', true);
71: wp_enqueue_script('kendo-tabstrip', Quform::url('js/kendo.tabstrip.min.js'), array('kendo-data'), '2020.2.617', true);
72: wp_enqueue_script('kendo-userevents', Quform::url('js/kendo.userevents.min.js'), array('kendo-core'), '2020.2.617', true);
73: wp_enqueue_script('kendo-draganddrop', Quform::url('js/kendo.draganddrop.min.js'), array('kendo-core', 'kendo-userevents'), '2020.2.617', true);
74: wp_enqueue_script('kendo-resizable', Quform::url('js/kendo.resizable.min.js'), array('kendo-core', 'kendo-draganddrop'), '2020.2.617', true);
75: wp_enqueue_script('kendo-splitter', Quform::url('js/kendo.splitter.min.js'), array('kendo-resizable'), '2020.2.617', true);
76: wp_enqueue_script('kendo-calendar', Quform::url('js/kendo.calendar.min.js'), array(), '2020.2.617', true);
77: wp_enqueue_script('kendo-popup', Quform::url('js/kendo.popup.min.js'), array(), '2020.2.617', true);
78: wp_enqueue_script('kendo-datepicker', Quform::url('js/kendo.datepicker.min.js'), array(), '2020.2.617', true);
79: wp_enqueue_script('kendo-timepicker', Quform::url('js/kendo.timepicker.min.js'), array(), '2020.2.617', true);
80: wp_enqueue_script('kendo-datetimepicker', Quform::url('js/kendo.datetimepicker.min.js'), array(), '2020.2.617', true);
81: wp_enqueue_script('quform-builder', Quform::adminUrl('js/builder.all.min.js'), array('jquery', 'jquery-color', 'json2', 'jquery-ui-draggable', 'jquery-ui-sortable', 'underscore'), QUFORM_VERSION, true);
82:
83: wp_localize_script('quform-builder', 'quformBuilderL10n', $this->builder->getScriptL10n());
84: }
85:
86: 87: 88: 89: 90:
91: protected function getAdminTitle()
92: {
93: return __('Edit Form', 'quform');
94: }
95:
96: 97: 98: 99: 100: 101: 102:
103: public function getNavHtml(array $currentForm = null, array $extra = array())
104: {
105: ob_start();
106: $shortcode = sprintf('[quform id="%d" name="%s"]', $currentForm['id'], $currentForm['name']);
107: ?>
108: <div class="qfb-nav-item">
109: <a id="qfb-add-to-website" class="qfb-nav-item-link" title="<?php esc_html_e('Add to website', 'quform'); ?>"><i class="qfb-mdi qfb-mdi-add_to_queue"></i></a>
110: </div>
111: <div class="qfb-nav-form-info"><i class="qfb-nav-form-id"><?php echo Quform::escape($currentForm['id']); ?></i><span id="qfb-nav-form-name" class="qfb-nav-form-name"><?php echo Quform::escape($currentForm['name']); ?></span><input type="text" id="qfb-nav-form-shortcode" class="qfb-nav-form-shortcode" readonly value="<?php echo Quform::escape($shortcode); ?>" size="<?php echo Quform::strlen($shortcode); ?>"></div>
112: <?php
113:
114: return parent::getNavHtml($currentForm, array(40 => ob_get_clean()));
115: }
116:
117: 118: 119:
120: public function process()
121: {
122: if ( ! current_user_can('quform_edit_forms')) {
123: wp_die(__( 'You do not have sufficient permissions to access this page.', 'quform'), 403);
124: }
125:
126: if ( ! isset($_GET['id']) || ! is_array($config = $this->repository->getConfig((int) $_GET['id']))) {
127: wp_die(__("You attempted to edit an item that doesn't exist. Perhaps it was deleted?", 'quform'));
128: }
129:
130: if ($config['trashed']) {
131: wp_die(__("You can't edit this item because it is in the Trash. Please restore it and try again.", 'quform'));
132: }
133:
134: $this->updateUserRecentForms($config['id']);
135:
136: if ( ! $this->license->isValid()) {
137:
138: $this->addMessage('error', '<strong>' . sprintf(esc_html__('You are using an unlicensed version. Please %1$senter your license key%2$s or %3$spurchase a license key%4$s.', 'quform'), '<a href="' . esc_url(admin_url('admin.php?page=quform.settings#license-updates')) .'">', '</a>', '<a href="https://www.quform.com/buy.php" target="_blank">', '</a>') . '</strong>');
139: }
140:
141: $this->view->with(array(
142: 'form' => $this->builder->prepare($config),
143: 'builder' => $this->builder,
144: 'options' => $this->options
145: ));
146: }
147:
148: 149: 150: 151: 152:
153: protected function updateUserRecentForms($formId)
154: {
155: if ( ! $this->options->get('toolbarMenu')) {
156: return;
157: }
158:
159: $currentUserId = get_current_user_id();
160: $recentFormIds = get_user_meta($currentUserId, 'quform_recent_forms', true);
161:
162: if ( ! is_array($recentFormIds)) {
163: $recentFormIds = array();
164: }
165:
166: $index = array_search($formId, $recentFormIds);
167:
168: if ($index !== false) {
169: unset($recentFormIds[$index]);
170: $recentFormIds = array_values($recentFormIds);
171: }
172:
173: array_unshift($recentFormIds, $formId);
174:
175: update_user_meta($currentUserId, 'quform_recent_forms', array_slice($recentFormIds, 0, 8));
176: }
177: }
178: