1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $page; |
---|
5 | |
---|
6 | $piwecard = get_plugin_data($plugin_id); |
---|
7 | |
---|
8 | if (isset($_POST['submit'])) { |
---|
9 | $errors = array(); |
---|
10 | $configuration = array(); |
---|
11 | |
---|
12 | $configuration['nb_max_recipients'] = $_POST['ecard_nb_max_recipients']; |
---|
13 | |
---|
14 | if (intval($configuration['nb_max_recipients']) == 0) { |
---|
15 | $configuration['nb_max_recipients'] = 1; |
---|
16 | $piwecard->config['nb_max_recipients'] = $configuration['nb_max_recipients']; |
---|
17 | } else { |
---|
18 | $piwecard->config['nb_max_recipients'] = intval($configuration['nb_max_recipients']); |
---|
19 | } |
---|
20 | |
---|
21 | $configuration['validity'] = $_POST['ecard_validity_list']; |
---|
22 | $configuration['validity'] = explode(',', $configuration['validity']); |
---|
23 | |
---|
24 | $configuration['validity_default'] = isset($_POST['ecard_validity_default']) ? $_POST['ecard_validity_default'] : null; |
---|
25 | |
---|
26 | if ($configuration['validity'][0] == null) { |
---|
27 | $errors['validity'] = array( |
---|
28 | 'style_error_text' => 'display: block;', |
---|
29 | 'style_error_input' => 'class="ecard_error_input"', |
---|
30 | ); |
---|
31 | } elseif (!in_array($configuration['validity_default'], $configuration['validity'])) { |
---|
32 | $configuration['validity_default'] = $configuration['validity']; |
---|
33 | } |
---|
34 | $conf_validity = array(); |
---|
35 | foreach ($configuration['validity'] as $validity) { |
---|
36 | array_push($conf_validity, intval($validity)); |
---|
37 | } |
---|
38 | $configuration['validity'] = array_unique($conf_validity, SORT_NUMERIC); |
---|
39 | asort($configuration['validity']); |
---|
40 | |
---|
41 | $configuration['validity_choice'] = ((isset($_POST['ecard_validity_choice']) && $_POST['ecard_validity_choice'] == '1') ? true : false); |
---|
42 | $configuration['sender_copy'] = isset($_POST['ecard_sender_copy']); |
---|
43 | $configuration['image_size'] = $_POST['ecard_image_size']; |
---|
44 | |
---|
45 | $configuration['image_border']['display'] = ((isset($_POST['ecard_image_border']) && $_POST['ecard_image_border'] == '1') ? true : false); |
---|
46 | $configuration['image_border']['style'] = $_POST['ecard_image_border_style']; |
---|
47 | $configuration['image_border']['width'] = ((isset($_POST['ecard_image_border_width']) && $_POST['ecard_image_border_width'] != '1') ? $_POST['ecard_image_border_width'] : $piwecard->get_default_config_param('ecard_image_border_width')); |
---|
48 | $configuration['image_border']['color'] = ((isset($_POST['ecard_image_border_color']) && $_POST['ecard_image_border_color'] != '1') ? $_POST['ecard_image_border_color'] : $piwecard->get_default_config_param('ecard_image_border_color')); |
---|
49 | |
---|
50 | $configuration['sender_email_change'] = isset($_POST['ecard_sender_email_change']); |
---|
51 | |
---|
52 | $ecard_email_format_array = array(); |
---|
53 | foreach($_POST['ecard_email_format'] as $ecard_email_format) { |
---|
54 | array_push($ecard_email_format_array, $ecard_email_format); |
---|
55 | } |
---|
56 | $configuration['email_format_authorized'] = $ecard_email_format_array; |
---|
57 | $configuration['email_format_default'] = $_POST['ecard_email_format_default']; |
---|
58 | if (!in_array($configuration['email_format_default'], $configuration['email_format_authorized'])) |
---|
59 | $errors['email_format_default'] = array( |
---|
60 | 'style_error_text' => 'display: block;', |
---|
61 | ); |
---|
62 | $configuration['show_image_infos'] = ((isset($_POST['ecard_show_image_infos']) && $_POST['ecard_show_image_infos'] == '1') ? true : false); |
---|
63 | $configuration['default_guest_email'] = $_POST['ecard_default_guest_email']; |
---|
64 | if ($configuration['default_guest_email'] != '' && !$piwecard->is_valid_email($configuration['default_guest_email'])) |
---|
65 | $errors['default_guest_email'] = array( |
---|
66 | 'style_error_text' => 'display: block;', |
---|
67 | 'style_error_input' => 'class="ecard_error_input"', |
---|
68 | ); |
---|
69 | $configuration['email_subject'] = htmlspecialchars($_POST['ecard_email_subject']); |
---|
70 | if ($configuration['email_subject'] == '') |
---|
71 | $errors['email_subject'] = array( |
---|
72 | 'style_error_text' => 'display: block;', |
---|
73 | 'style_error_input' => 'class="ecard_error_input"', |
---|
74 | ); |
---|
75 | $configuration['email_message']['text'] = htmlspecialchars($_POST['ecard_email_message_text']); |
---|
76 | if ($configuration['email_message']['text'] == '') |
---|
77 | $errors['email_message']['text'] = array( |
---|
78 | 'style_error_text' => 'display: block;', |
---|
79 | 'style_error_input' => 'class="ecard_error_input"', |
---|
80 | ); |
---|
81 | $configuration['email_message']['html'] = stripslashes($_POST['ecard_email_message_html']); |
---|
82 | if ($configuration['email_message']['html'] == '') |
---|
83 | $errors['email_message']['html'] = array( |
---|
84 | 'style_error_text' => 'display: block;', |
---|
85 | 'style_error_input' => 'class="ecard_error_input"', |
---|
86 | ); |
---|
87 | |
---|
88 | foreach ($configuration as $key => $item) { |
---|
89 | if (!array_key_exists($key, $errors)) { |
---|
90 | $piwecard->config[$key] = $configuration[$key]; |
---|
91 | } |
---|
92 | } |
---|
93 | $piwecard->set_config(); |
---|
94 | |
---|
95 | if (empty($errors)) { |
---|
96 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
97 | } else { |
---|
98 | $template->assign('ecard_errors', $errors); |
---|
99 | array_push($page['errors'], l10n('piwecard_errors')); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | if (isset($_POST['reset'])) { |
---|
104 | $piwecard->config['email_subject'] = $piwecard->get_default_config_param('email_subject'); |
---|
105 | $email_message = $piwecard->get_default_config_param('email_message'); |
---|
106 | $piwecard->config['email_message']['text'] = $email_message['text']; |
---|
107 | $piwecard->config['email_message']['html'] = $email_message['html']; |
---|
108 | |
---|
109 | $piwecard->set_config(); |
---|
110 | |
---|
111 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
112 | } |
---|
113 | |
---|
114 | $template->assign('ecard_nb_max_recipients',((isset($configuration['nb_max_recipients'])) ? $configuration['nb_max_recipients'] : $piwecard->config['nb_max_recipients'])); |
---|
115 | |
---|
116 | if (isset($errors['validity'])) { |
---|
117 | $piwecard->config['validity'] = null; |
---|
118 | $configuration['validity'] = null; |
---|
119 | } |
---|
120 | $template->assign('ecard_validity_list',((isset($configuration['validity'])) ? $configuration['validity'] : $piwecard->config['validity'])); |
---|
121 | |
---|
122 | if (isset($piwecard->config['validity'])) { |
---|
123 | foreach($piwecard->config['validity'] as $validity) { |
---|
124 | $template->append('ecard_validity', array( |
---|
125 | 'id' => $validity, |
---|
126 | 'name' => ($validity == 0) ? l10n('piwecard_nolimit') : $validity.' '.l10n('piwecard_days'), |
---|
127 | 'selected' => (($piwecard->config['validity_default'] == $validity) ? 'selected' : ''), |
---|
128 | ) |
---|
129 | ); |
---|
130 | } |
---|
131 | } |
---|
132 | $template->assign('ecard_validity_choice', $piwecard->config['validity_choice'] ? 'checked="checked"' : ''); |
---|
133 | |
---|
134 | $derivative_map = array(); |
---|
135 | foreach(ImageStdParams::get_defined_type_map() as $params) { |
---|
136 | $derivative_map[$params->type]['name'] = l10n($params->type); |
---|
137 | if ($params->type == $piwecard->config['image_size']) |
---|
138 | $derivative_map[$params->type]['selected'] = 'checked="checked"'; |
---|
139 | else |
---|
140 | $derivative_map[$params->type]['selected'] = ''; |
---|
141 | } |
---|
142 | $template->assign('generate_derivatives_types', $derivative_map); |
---|
143 | |
---|
144 | $template->assign('ecard_image_border', (($piwecard->config['image_border']['display']) ? 'checked="checked"' : '')); |
---|
145 | $template->assign('ecard_image_border_style', array( |
---|
146 | 'solid' => (($piwecard->config['image_border']['style'] == 'solid') ? 'checked="checked"' : ''), |
---|
147 | 'dashed' => (($piwecard->config['image_border']['style'] == 'dashed') ? 'checked="checked"' : ''), |
---|
148 | 'dotted' => (($piwecard->config['image_border']['style'] == 'dotted') ? 'checked="checked"' : ''), |
---|
149 | 'double' => (($piwecard->config['image_border']['style'] == 'double') ? 'checked="checked"' : ''), |
---|
150 | ) |
---|
151 | ); |
---|
152 | $template->assign('ecard_image_border_width', $piwecard->config['image_border']['width']); |
---|
153 | $template->assign('ecard_image_border_color', $piwecard->config['image_border']['color']); |
---|
154 | |
---|
155 | $template->assign('ecard_sender_copy', $piwecard->config['sender_copy'] ? 'checked="checked"' : ''); |
---|
156 | $template->assign('ecard_sender_email_change', $piwecard->config['sender_email_change'] ? 'checked="checked"' : ''); |
---|
157 | $email_format_array = array(); |
---|
158 | foreach($piwecard->config['email_format'] as $email_format) { |
---|
159 | array_push($email_format_array, array( |
---|
160 | 'id' => $email_format, |
---|
161 | 'selected' => (in_array($email_format, $piwecard->config['email_format_authorized']) ? 'checked="checked"' : ''), |
---|
162 | 'selected_default' => (($piwecard->config['email_format_default'] == $email_format) ? 'checked="checked"' : ''), |
---|
163 | 'language_string' => 'piwecard_email_format_'.$email_format, |
---|
164 | ) |
---|
165 | ); |
---|
166 | } |
---|
167 | $template->assign('ecard_email_format', $email_format_array); |
---|
168 | $template->assign('ecard_email_format_default', $email_format_array); |
---|
169 | $template->assign('ecard_show_image_infos', $piwecard->config['show_image_infos'] ? 'checked="checked"' : ''); |
---|
170 | $template->assign('ecard_default_guest_email', ((isset($configuration['default_guest_email'])) ? $configuration['default_guest_email'] : $piwecard->config['default_guest_email'])); |
---|
171 | $template->assign('ecard_email_subject', ((isset($configuration['email_subject'])) ? $configuration['email_subject'] : htmlspecialchars_decode($piwecard->config['email_subject']))); |
---|
172 | $template->assign('ecard_email_message_text', ((isset($configuration['email_message']['text'])) ? $configuration['email_message']['text'] : htmlspecialchars_decode($piwecard->config['email_message']['text']))); |
---|
173 | $template->assign('ecard_email_message_html', ((isset($configuration['email_message']['html'])) ? $configuration['email_message']['html'] : htmlspecialchars_decode($piwecard->config['email_message']['html']))); |
---|
174 | $template->assign('preview_image', get_root_url().PIWECARD_PATH.'admin/images/image.jpg'); |
---|
175 | |
---|
176 | $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/admin_configuration.tpl'); |
---|
177 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|