PluginProbe
Name Directory / 1.12
Name Directory v1.12
1.34.1 1.34.0 trunk 1.10 1.11 1.11.1 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.12 1.13 1.13.1 1.13.2 1.13.3 1.13.4 1.13.5 1.13.6 1.13.7 1.14 1.14.1 1.14.2 1.15 1.15.1 All 91 releases
name-directory / admin.php

admin.php in Name Directory 1.12, at admin.php

1,211 lines 51.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action('admin_menu', 'name_directory_register_menu_entry');
4 add_action('wp_ajax_name_directory_ajax_names', 'name_directory_names');
5 add_action('wp_ajax_name_directory_switch_name_published_status', 'name_directory_ajax_switch_name_published_status');
6
7
8 /**
9 * Add a menu entry on options
10 */
11 function name_directory_register_menu_entry()
12 {
13 add_menu_page(
14 __('Name Directory', 'name-directory'),
15 __('Name Directory', 'name-directory'),
16 'manage_options',
17 'name-directory',
18 'name_directory_options',
19 'dashicons-index-card',
20 120);
21
22 add_submenu_page(
23 'name-directory',
24 __('Add directory', 'name-directory'),
25 __('Add directory', 'name-directory'),
26 'manage_options',
27 'admin.php?page=name-directory&sub=new-directory');
28 }
29
30
31 /**
32 * This is a little router for the
33 * name-directory plugin
34 */
35 function name_directory_options()
36 {
37 if (!current_user_can('manage_options'))
38 {
39 wp_die( __('You do not have sufficient permissions to access this page.', 'name-directory') );
40 }
41
42 $sub_page = '';
43 if(! empty($_GET['sub']))
44 {
45 $sub_page = $_GET['sub'];
46 }
47 switch($sub_page)
48 {
49 case 'manage-directory':
50 name_directory_names();
51 break;
52 case 'edit-directory':
53 name_directory_edit();
54 break;
55 case 'new-directory':
56 name_directory_edit('new');
57 break;
58 case 'import':
59 name_directory_import();
60 break;
61 case 'export':
62 name_directory_export();
63 break;
64 default:
65 name_directory_show_list();
66 break;
67 }
68
69 }
70
71
72 /**
73 * Show the list of directories and all of the
74 * links to manage the directories
75 */
76 function name_directory_show_list()
77 {
78 global $wpdb;
79 global $name_directory_table_directory;
80 global $name_directory_table_directory_name;
81
82 if(! empty($_GET['delete_dir']) && is_numeric($_GET['delete_dir']))
83 {
84 $name = $wpdb->get_var(sprintf("SELECT `name` FROM %s WHERE id=%d", $name_directory_table_directory, $_GET['delete_dir']));
85 $wpdb->delete($name_directory_table_directory, array('id' => $_GET['delete_dir']), array('%d'));
86 $wpdb->delete($name_directory_table_directory_name, array('directory' => $_GET['delete_dir']), array('%d'));
87 echo "<div class='updated'><p><strong>"
88 . sprintf(__('Name directory %s and all entries deleted', 'name-directory'), "<i>" . $name . "</i>")
89 . "</strong></p></div>";
90 }
91
92 $wp_file = admin_url('admin.php');
93 $wp_page = $_GET['page'];
94 $wp_url_path = sprintf("%s?page=%s", $wp_file, $wp_page);
95 $wp_new_url = sprintf("%s&sub=%s", $wp_url_path, 'new-directory');
96
97
98 echo '<div class="wrap">';
99 echo "<h2>"
100 . __('Name Directory management', 'name-directory')
101 . " <a href='" . $wp_new_url . "' class='add-new-h2'>" . __('Add directory', 'name-directory') . "</a>"
102 . "</h2>";
103
104 if(! empty($_POST['mode']) && ! empty($_POST['dir_id']))
105 {
106 $wpdb->update(
107 $name_directory_table_directory,
108 array(
109 'name' => $_POST['name'],
110 'description' => $_POST['description'],
111 'show_title' => $_POST['show_title'],
112 'show_description' => $_POST['show_description'],
113 'show_submit_form' => $_POST['show_submit_form'],
114 'show_search_form' => $_POST['show_search_form'],
115 'show_submitter_name' => $_POST['show_submitter_name'],
116 'show_line_between_names' => $_POST['show_line_between_names'],
117 'show_all_names_on_index' => $_POST['show_all_names_on_index'],
118 'show_all_index_letters' => $_POST['show_all_index_letters'],
119 'jump_to_search_results' => $_POST['jump_to_search_results'],
120 'nr_columns' => $_POST['nr_columns'],
121 'nr_most_recent' => intval($_POST['nr_most_recent']),
122 'nr_words_description' => intval($_POST['nr_words_description']),
123 'name_term' => $_POST['name_term'],
124 'name_term_singular' => $_POST['name_term_singular'],
125 ),
126 array('id' => intval($_POST['dir_id']))
127 );
128
129 echo "<div class='updated'><p>"
130 . sprintf(__('Directory %s updated.', 'name-directory'), "<i>" . esc_sql($_POST['name']) . "</i>")
131 . "</p></div>";
132
133 unset($_GET['dir_id']);
134 }
135 elseif(! empty($_POST['mode']) && $_POST['mode'] == "new")
136 {
137 $wpdb->insert(
138 $name_directory_table_directory,
139 array(
140 'name' => $_POST['name'],
141 'description' => $_POST['description'],
142 'show_title' => $_POST['show_title'],
143 'show_description' => $_POST['show_description'],
144 'show_submit_form' => $_POST['show_submit_form'],
145 'show_search_form' => $_POST['show_search_form'],
146 'show_submitter_name' => $_POST['show_submitter_name'],
147 'show_line_between_names' => $_POST['show_line_between_names'],
148 'show_all_names_on_index' => $_POST['show_all_names_on_index'],
149 'show_all_index_letters' => $_POST['show_all_index_letters'],
150 'jump_to_search_results' => $_POST['jump_to_search_results'],
151 'nr_columns' => $_POST['nr_columns'],
152 'nr_most_recent' => $_POST['nr_most_recent'],
153 'nr_words_description' => $_POST['nr_words_description'],
154 'name_term' => $_POST['name_term'],
155 'name_term_singular' => $_POST['name_term_singular'],
156 ),
157 array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s')
158 );
159
160 echo "<div class='updated'><p>"
161 . sprintf(__('Directory %s created.', 'name-directory'), "<i>" . esc_sql($_POST['name']) . "</i>")
162 . "</p></div>";
163 }
164
165 $directories = $wpdb->get_results("SELECT * FROM $name_directory_table_directory");
166 $num_directories = $wpdb->num_rows;
167 $plural = ($num_directories==1)?__('name directory', 'name-directory'):__('name directories', 'name-directory');
168
169 echo "<p>"
170 . sprintf(__('You currently have %d %s.', 'name-directory'), $num_directories, $plural)
171 . "</p>";
172 ?>
173
174 <table class="wp-list-table widefat fixed name-directory" cellspacing="0">
175 <thead><?php name_directory_render_admin_overview_table_headerfooter(); ?></thead>
176
177 <tbody>
178 <?php
179 foreach ( $directories as $directory )
180 {
181 $entries = $wpdb->get_var(sprintf("SELECT COUNT(`id`) FROM %s WHERE directory=%d", $name_directory_table_directory_name, $directory->id));
182 $unpublished = $wpdb->get_var(sprintf("SELECT COUNT(`id`) FROM %s WHERE directory=%d AND `published` = 0", $name_directory_table_directory_name, $directory->id));
183 echo sprintf("
184 <tr class='type-page status-publish hentry alternate iedit author-self' valign='top'>
185 <th scope='col'>&nbsp;</th>
186 <td class='post-title page-title column-title' style='padding-left: 0;'>
187 <strong><a class='row-title' href='" . $wp_url_path . "&sub=manage-directory&dir=%d' title='%s'>%s</a>
188 <span style='font-weight: normal;'>&nbsp;%s</span></strong>
189 <div class='locked-info'>&nbsp;</div>
190 <div class='row-actions'>
191 <span class='manage'><a href='" . $wp_url_path . "&sub=manage-directory&dir=%d' title='%s'>%s</a>
192 | </span><span><a href='" . $wp_url_path . "&sub=manage-directory&dir=%d#anchor_add_form' title='%s'>%s</a>
193 | </span><span><a href='" . $wp_url_path . "&sub=edit-directory&dir=%d' title='%s'>%s</a>
194 | </span><span><a href='" . $wp_url_path . "&sub=import&dir=%d' title='%s'>%s</a>
195 | </span><span><a href='" . $wp_url_path . "&sub=export&dir=%d' title='%s'>%s</a>
196 | </span><span class='view'><a class='toggle-info' data-id='%s' href='" . $wp_url_path . "&sub=manage-directory&dir=%d#shortcode' title='%s'>%s</a></span>
197 | </span><span class='trash'><a class='namedirectory_confirmdelete submitdelete' href='" . $wp_url_path . "&delete_dir=%d' title=%s'>%s</a>
198 </div>
199 </td>
200 <td>
201 &nbsp; <strong title='%s'>%d</strong>
202 <br /><br />&nbsp;
203 </td>
204 <td>%d</td>
205 <td>%d</td>
206 </tr>",
207
208 $directory->id, $directory->name, $directory->name,
209 substr($directory->description, 0, 70),
210 $directory->id, __('Add, edit and remove names', 'name-directory'), __('Manage names', 'name-directory'),
211 $directory->id, __('Go to the add-name-form on the Manage page', 'name-directory'), __('Add name', 'name-directory'),
212 $directory->id, __('Edit name, description and appearance settings', 'name-directory'), __('Settings', 'name-directory'),
213 $directory->id, __('Import entries for this directory by uploading a .csv file', 'name-directory'), __('Import', 'name-directory'),
214 $directory->id, __('Download the contents of this directory as a .csv file', 'name-directory'), __('Export', 'name-directory'),
215 $directory->id, $directory->id, __('Show the copy-paste shortcode for this directory', 'name-directory'), __('Shortcode', 'name-directory'),
216 $directory->id, __('Permanently remove this name directory', 'name-directory'), __('Delete', 'name-directory'),
217
218 __('Number of names in this directory', 'name-directory'),
219 $entries,
220 ($entries - $unpublished),
221 $unpublished
222 );
223 echo sprintf("
224 <tr id='embed_code_%s' style='display: none;'>
225 <td>&nbsp;</td>
226 <td align='right'>%s</td>
227 <td colspan='5'>
228 <input value='[namedirectory dir=\"%s\"]' type='text' size='25' id='title'
229 style='text-align: center; padding: 8px 5px;' />
230 </td>
231 </tr>
232 <tr style='display: none;'><td colspan='7'>&nbsp;</td></tr>",
233 $directory->id,
234 __('To show your directory on your website, use the shortcode on the right.', 'name-directory') . '<br />' .
235 __('Copy the code and paste it in a post or in a page.', 'name-directory') . '<br /><small>' .
236 __('If you want to start with a specific character, like "J", use [namedirectory dir="X" start_with="j"].', 'name-directory') . '</small>',
237 $directory->id);
238 }
239 ?>
240 </tbody>
241
242 <tfoot><?php name_directory_render_admin_overview_table_headerfooter(); ?></tfoot>
243 </table>
244
245 <script type='text/javascript'>
246 jQuery(document).ready(function()
247 {
248 jQuery('.toggle-info').on('click', function(event)
249 {
250 event.preventDefault();
251 var toggle_id = jQuery(this).attr('data-id');
252 jQuery('#embed_code_' + toggle_id).toggle();
253 return false;
254 });
255
256 jQuery('.namedirectory_confirmdelete').click(function(){
257 delete_directory = confirm('<?php echo __('Are you sure you want to delete this name directory?', 'name-directory') ?>');
258 if(delete_directory == false)
259 {
260 return false;
261 }
262 });
263
264 });
265 </script>
266 <?php
267 }
268
269
270 /**
271 * A double purpose function for editing a name-directory and
272 * creating a new directory.
273 * @param string $mode
274 */
275 function name_directory_edit($mode = 'edit')
276 {
277 if (!current_user_can('manage_options'))
278 {
279 wp_die( __('You do not have sufficient permissions to access this page.', 'name-directory') );
280 }
281
282 global $wpdb;
283 global $name_directory_table_directory;
284
285 $wp_file = admin_url('admin.php');
286 $wp_page = $_GET['page'];
287 $wp_sub = $_GET['sub'];
288 $overview_url = sprintf("%s?page=%s", $wp_file, $wp_page, $wp_sub);
289 $wp_url_path = sprintf("%s?page=%s", $wp_file, $wp_page);
290
291 $directory_id = 0;
292 if(! empty($_GET['dir']))
293 {
294 $directory_id = intval($_GET['dir']);
295 }
296 $directory = $wpdb->get_row("SELECT * FROM " . $name_directory_table_directory . " WHERE `id` = " . $directory_id, ARRAY_A);
297
298 echo '<div class="wrap">';
299 if($mode == "new")
300 {
301 $table_heading = __('Create new name directory', 'name-directory');
302 $button_text = __('Create', 'name-directory');
303 echo "<h2>" . __('Create new name directory', 'name-directory') . "</h2>";
304 echo "<p>" . __('Complete the form below to create a new name directory.', 'name-directory');
305 }
306 else
307 {
308 $table_heading = __('Edit this directory', 'name-directory');
309 $button_text = __('Save Changes', 'name-directory');
310 echo "<h2>" . __('Edit name directory', 'name-directory') . "</h2>";
311 echo "<p>"
312 . sprintf(__('You are editing the name, description and settings of directory %s', 'name-directory'),
313 $directory['name']);
314 }
315 echo " <a style='float: right;' href='" . $overview_url . "'>" . __('Back to the directory overview', 'name-directory') . "</a></p>";
316 ?>
317
318 <form name="add_name" method="post" action="<?php echo $wp_url_path; ?>">
319 <table class="wp-list-table widefat" cellpadding="0">
320 <thead>
321 <tr>
322 <th colspan="2">
323 <?php echo $table_heading; ?>
324 <input type="hidden" name="dir_id" value="<?php echo $directory_id; ?>">
325 <input type="hidden" name="mode" value="<?php echo $mode; ?>">
326 </th>
327 </tr>
328 </thead>
329 <tbody>
330 <tr>
331 <td width="29%"><?php echo __('Title', 'name-directory'); ?></td>
332 <td width="70%"><input type="text" name="name" value="<?php echo $directory['name']; ?>" size="20" style="width: 100%;"></td>
333 </tr>
334 <tr>
335 <td><?php echo __('Description', 'name-directory'); ?></td>
336 <td><textarea name="description" rows="5" style="width: 100%;"><?php echo $directory['description']; ?></textarea></td>
337 </tr>
338
339 <?php
340 $dir_boolean_settings = array(
341 'show_title' => array(
342 'friendly_name' => __('Show title', 'name-directory'),
343 'description' => false,
344 ),
345 'show_description' => array(
346 'friendly_name' => __('Show description', 'name-directory'),
347 'description' => false,
348 ),
349 'show_submit_form' => array(
350 'friendly_name' => __('Submit form', 'name-directory'),
351 'description' => __('Visitors can submit suggestions', 'name-directory'),
352 ),
353 'show_submitter_name' => array(
354 'friendly_name' => __('Submitter name', 'name-directory'),
355 'description' => __('Show the name of the submitter', 'name-directory'),
356 ),
357 'show_search_form' => array(
358 'friendly_name' => __('Show search form', 'name-directory'),
359 'description' => false,
360 ),
361 'show_line_between_names' => array(
362 'friendly_name' => __('Show line between names', 'name-directory'),
363 'description' => false,
364 ),
365 'show_all_names_on_index' => array(
366 'friendly_name' => __('Show all names by default', 'name-directory'),
367 'description' => __('If no, user HAS to use the index before entries are shown', 'name-directory'),
368 ),
369 'show_all_index_letters' => array(
370 'friendly_name' => __('Show all letters on index', 'name-directory'),
371 'description' => __('If no, just A B D E are shown if there are no entries starting with C', 'name-directory'),
372 ),
373 'jump_to_search_results' => array(
374 'friendly_name' => __('Jump to Name Directory when searching', 'name-directory'),
375 'description' => __('On the front-end, jump to the Name Directory search box. Particularly useful if you have Name Directory on a long page or onepage websites', 'name-directory'),
376 ),
377 );
378
379 $dir_options_settings = array(
380 'nr_most_recent' => array(
381 'friendly_name' => __('Show most recent names', 'name-directory'),
382 'description' => __('If No, frontend will not show \'Latest\' option.', 'name-directory'),
383 'options' => array(0 => __('No', 'name-directory'), 3 => 3, 5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100)
384 ),
385 'nr_words_description' => array(
386 'friendly_name' => __('Limit amount of words in description', 'name-directory'),
387 'description' => __('Display a "read-more" link on the website if the description exceeds X characters.', 'name-directory'),
388 'options' => array(0 => __('No', 'name-directory'), 10 => 10, 20 => 20, 25 => 25, 50 => 50, 100 => 100)
389 ),
390 'nr_columns' => array(
391 'friendly_name' => __('Number of columns', 'name-directory'),
392 'description' => __('The number of (vertical) columns to display the names in', 'name-directory'),
393 'options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4)
394 ),
395 );
396
397
398 foreach($dir_boolean_settings as $setting_name => $setting_props)
399 {
400 name_directory_render_admin_setting_boolean($directory, $setting_name, $setting_props['friendly_name'], $setting_props['description']);
401 }
402
403 foreach($dir_options_settings as $setting_name => $setting_props)
404 {
405 name_directory_render_admin_setting_options($directory, $setting_name, $setting_props['friendly_name'], $setting_props['description'], $setting_props['options']);
406 }
407 ?>
408 <tr>
409 <td width="29%"><?php echo __('Name term', 'name-directory'); ?><br>
410 <small><?php echo __('Alternative (plural) term for "names", i.e. movies', 'name-directory'); ?></small></td>
411 <td width="70%"><input type="text" name="name_term" value="<?php echo $directory['name_term']; ?>" size="20" style="width: 100%;">
412 <br>
413 <small><?php echo __('If you provide an alternative term for name, your website will display:', 'name-directory'); ?>
414 "<i><?php echo sprintf(__('There are currently %d %s in this directory', 'name-directory'), 1337, "movies"); ?></i>"<br>
415 <?php echo __('When left blank, the word "names" will be displayed.', 'name-directory'); ?></small></td>
416 </tr>
417 <tr>
418 <td width="29%"><?php echo __('Name term (singular)', 'name-directory'); ?><br>
419 <small><?php echo __('The singular term for "names", i.e. movie', 'name-directory'); ?></small></td>
420 <td width="70%"><input type="text" name="name_term_singular" value="<?php echo $directory['name_term_singular']; ?>" size="20" style="width: 100%;"></td>
421 </tr>
422 <tr>
423 <td>&nbsp;</td>
424 <td>
425 <input type="submit" name="submit" class="button button-primary button-large"
426 value="<?php echo $button_text; ?>" />
427
428 <a class='button button-large' href='<?php echo $overview_url; ?>'>
429 <?php echo __('Cancel', 'name-directory'); ?>
430 </a>
431 </td>
432 </tr>
433 </tbody>
434 </table>
435 </form>
436
437 <?php
438
439 }
440
441
442 /**
443 * Handle the names in the name directory
444 * - Display all names
445 * - Edit names (ajax and 'oldskool' view)
446 * - Create new names
447 */
448 function name_directory_names()
449 {
450 if (!current_user_can('manage_options'))
451 {
452 wp_die( __('You do not have sufficient permissions to access this page.', 'name-directory') );
453 }
454
455 global $wpdb;
456 global $name_directory_table_directory;
457 global $name_directory_table_directory_name;
458
459 if(! empty($_GET['delete_name']) && is_numeric($_GET['delete_name']))
460 {
461 $name = $wpdb->get_var(sprintf("SELECT `name` FROM %s WHERE id=%d", $name_directory_table_directory_name, $_GET['delete_name']));
462 $wpdb->delete($name_directory_table_directory_name, array('id' => $_GET['delete_name']), array('%d'));
463 echo "<div class='updated'><p>"
464 . sprintf(__('Name %s deleted', 'name-directory'), "<i>" . $name . "</i>")
465 . "</p></div>";
466 }
467 else if(! empty($_POST['name_id']))
468 {
469 $wpdb->update(
470 $name_directory_table_directory_name,
471 array(
472 'name' => stripslashes_deep($_POST['name']),
473 'letter' => name_directory_get_first_char($_POST['name']),
474 'description' => stripslashes_deep($_POST['description']),
475 'published' => $_POST['published'],
476 'submitted_by' => $_POST['submitted_by'],
477 ),
478 array('id' => intval($_POST['name_id']))
479 );
480
481 if($_POST['action'] == "name_directory_ajax_names")
482 {
483 echo '<p>';
484 echo sprintf(__('Name %s updated', 'name-directory'), "<i>" . esc_sql($_POST['name']) . "</i>");
485 echo '. <small><i>' . __('Will be visible when the page is refreshed.', 'name-directory') . '</i> ';
486 echo ' <a href="">' . __('Refresh now', 'name-directory') . '</a></small>';
487 echo '</p>';
488 exit;
489 }
490
491 echo "<div class='updated'><p>"
492 . sprintf(__('Name %s updated', 'name-directory'), "<i>" . esc_sql($_POST['name']) . "</i>")
493 . "</p></div>";
494
495 unset($_GET['edit_name']);
496 }
497 else if(! empty($_POST['name']))
498 {
499 $name_exists = name_directory_name_exists_in_directory($_POST['name'], $_POST['directory']);
500 if($name_exists && $_POST['action'] == "name_directory_ajax_names")
501 {
502 echo '<p>';
503 echo sprintf(__('Name %s was already on the list, so it was not added', 'name-directory'),
504 '<i>' . esc_sql($_POST['name']) . '</i>');
505 echo '</p>';
506 exit;
507 }
508
509 $wpdb->insert(
510 $name_directory_table_directory_name,
511 array(
512 'directory' => $_POST['directory'],
513 'name' => stripslashes_deep($_POST['name']),
514 'letter' => name_directory_get_first_char($_POST['name']),
515 'description' => stripslashes_deep($_POST['description']),
516 'published' => $_POST['published'],
517 'submitted_by' => $_POST['submitted_by'],
518 ),
519 array('%d', '%s', '%s', '%s', '%d', '%s')
520 );
521
522 if($_POST['action'] == "name_directory_ajax_names")
523 {
524 echo '<p>';
525 printf(__('New name %s added', 'name-directory'), '<i>' . esc_sql($_POST['name']) . '</i> ');
526 echo '. <small><i>' . __('Will be visible when the page is refreshed.', 'name-directory') . '</i> ';
527 echo ' <a href="">' . __('Refresh now', 'name-directory') . '</a></small>';
528 echo '</p>';
529 exit;
530 }
531
532 echo "<div class='updated'><p><strong>"
533 . sprintf(__('New name %s added', 'name-directory'), "<i>" . esc_sql($_POST['name']) . "</i> ")
534 . "</strong></p></div>";
535 }
536 else if($_SERVER['REQUEST_METHOD'] == 'POST')
537 {
538 if($_POST['action'] == "name_directory_ajax_names")
539 {
540 echo '<p>' . __('Please fill in at least a name', 'name-directory') . '</p>';
541 exit;
542 }
543
544 echo "<div class='error'><p><strong>"
545 . __('Please fill in at least a name', 'name-directory')
546 . "</strong></p></div>";
547 }
548
549 $directory_id = intval($_GET['dir']);
550
551 $wp_file = admin_url('admin.php');
552 $wp_page = $_GET['page'];
553 $wp_sub = $_GET['sub'];
554 $overview_url = sprintf("%s?page=%s", $wp_file, $wp_page);
555 $wp_url_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, $wp_sub, $directory_id);
556 $wp_ndir_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, 'manage-directory', $directory_id);
557
558 $published_status = '0,1';
559 $emphasis_class = 's_all';
560 if(! empty($_GET['status']) && $_GET['status'] == 'published')
561 {
562 $published_status = '1';
563 $emphasis_class = 's_published';
564 }
565 else if(! empty($_GET['status']) && $_GET['status'] == 'unpublished')
566 {
567 $published_status = '0';
568 $emphasis_class = 's_unpublished';
569 }
570
571 $directory = $wpdb->get_row("SELECT * FROM " . $name_directory_table_directory . " WHERE `id` = " . $directory_id, ARRAY_A);
572 $names = $wpdb->get_results(sprintf("SELECT * FROM %s WHERE `directory` = %d AND `published` IN (%s) ORDER BY `name` ASC",
573 $name_directory_table_directory_name, $directory_id, $published_status));
574
575 echo '<div class="wrap">';
576 echo "<h2>" . sprintf(__('Manage names for %s', 'name-directory'), $directory['name']) . "</h2>";
577 ?>
578
579 <?php
580 if(! empty($_GET['edit_name']))
581 {
582 $name = $wpdb->get_row(sprintf("SELECT * FROM `%s` WHERE `id` = %d",
583 $name_directory_table_directory_name, $_GET['edit_name']), ARRAY_A);
584 $table_heading = __('Edit a name', 'name-directory');
585 $save_button_txt = __('Save name', 'name-directory');
586 }
587 else
588 {
589 $table_heading = __('Add a new name', 'name-directory');
590 $save_button_txt = __('Add name', 'name-directory');
591 $name = array('name' => null, 'description' => null, 'submitted_by' => null);
592 }
593
594 ?>
595 <span style='float: right';>
596 <a href='<?php echo $overview_url; ?>'><?php _e('Back to the directory overview', 'name-directory'); ?></a>
597 </span>
598
599 <p>&nbsp;</p>
600
601 <div class="hidden" id="add_result"></div>
602
603 <a name="anchor_add_form"></a>
604 <form name="add_name" id="add_name_ajax" method="post" action="<?php echo $wp_url_path; ?>">
605 <table class="wp-list-table widefat" cellpadding="0">
606 <thead>
607 <tr>
608 <th width="18%"><?php echo $table_heading; ?>
609 <input type="hidden" name="directory" value="<?php echo $directory_id; ?>">
610 <?php
611 if(! empty($_GET['edit_name']))
612 {
613 echo '<input type="hidden" name="name_id" id="edit_name_id" value="' . intval($_GET['edit_name']) . '">';
614 }
615 ?>
616 <input type="hidden" name="action" value="0" id="add_form_ajax_submit" />
617 </th>
618 <th align="right">
619
620 <label id="input_compact" title="<?php echo __('Show the compact form, showing only the name, always published)', 'name-directory'); ?>">
621 <input type="radio" name="input_mode" />
622 <?php echo __('Quick add view', 'name-directory'); ?>
623 </label>
624 <label id="input_extensive" title="<?php echo __('Show the full form, which allows you to enter a description and submitter', 'name-directory'); ?>">
625 <input type="radio" name="input_mode" />
626 <?php echo __('Full add view', 'name-directory'); ?>
627 </label>
628
629 </th>
630 </tr>
631 </thead>
632 <tbody>
633 <tr id="add_name">
634 <td width="18%"><?php echo __('Name', 'name-directory'); ?></td>
635 <td width="82%"><input type="text" name="name" value="<?php echo $name['name']; ?>" size="20" style="width: 100%;"></td>
636 </tr>
637 <tr id="add_description">
638 <td><?php echo __('Description', 'name-directory'); ?></td>
639 <td><textarea name="description" rows="5" style="width: 100%;"><?php echo stripslashes($name['description']); ?></textarea>
640 <small><strong><?php echo __('Please be careful!', 'name-directory'); ?></strong>
641 <?php echo __('HTML markup is allowed and will we printed on your website and in the WordPress admin.', 'name-directory'); ?></small></td>
642 </tr>
643 <tr id="add_published">
644 <td><?php echo __('Published', 'name-directory'); ?></td>
645 <td>
646 <input type="radio" name="published" id="published_yes" value="1" checked="checked">
647 <label for="published_yes"><?php echo __('Yes', 'name-directory') ?></label>
648
649 <input type="radio" name="published" id="published_no" value="0"
650 <?php
651 if(isset($name['published']) && empty($name['published']))
652 {
653 echo 'checked="checked"';
654 }?>>
655 <label for="published_no"><?php echo __('No', 'name-directory') ?></label>
656 </td>
657 </tr>
658 <tr id="add_submitter">
659 <td><?php echo __('Submitted by', 'name-directory'); ?></td>
660 <td><input type="text" name="submitted_by" value="<?php echo $name['submitted_by']; ?>" size="20" style="width: 100%;"></td>
661 </tr>
662 <tr>
663 <td>&nbsp;</td>
664 <td>
665 <input type="submit" id="add_button" name="Submit" class="button button-primary button-large"
666 value="<?php echo $save_button_txt; ?>" />
667 </td>
668 </tr>
669 </tbody>
670 </table>
671 </form>
672
673 <p>
674 <a class='s_all' href='<?php echo $wp_url_path; ?>&status=all'><?php _e('all', 'name-directory'); ?></a> |
675 <a class='s_published' href='<?php echo $wp_url_path; ?>&status=published'><?php _e('published', 'name-directory'); ?></a> |
676 <a class='s_unpublished' href='<?php echo $wp_url_path; ?>&status=unpublished'><?php _e('unpublished', 'name-directory'); ?></a>
677 </p>
678
679 <?php
680 $name_filter = array();
681
682 $search_value = '';
683 if(! empty($_GET['s']))
684 {
685 $search_value = htmlspecialchars($_GET['s']);
686 $name_filter['containing'] = $search_value;
687
688 $names = name_directory_get_directory_names($directory, $name_filter);
689 $num_names = count($names);
690 }
691
692 $parsed_url = parse_url($_SERVER['REQUEST_URI']);
693 $search_get_url = array();
694 if(! empty($parsed_url['query']))
695 {
696
697 parse_str($parsed_url['query'], $search_get_url);
698 }
699 unset($search_get_url['s']);
700
701 echo '<form method="get" action="">';
702 echo '<p class="search-box">';
703 foreach($search_get_url as $key_name=>$value)
704 {
705 if($key_name == 'name_directory_startswith')
706 {
707 continue;
708 }
709 echo "<input type='hidden' name='" . htmlspecialchars($key_name) . "' value='" . htmlspecialchars($value) . "' />";
710 }
711 echo "<input type='search' class='tagsdiv newtag' name='s' id='name-directory-search-input-box' value='" . $search_value . "' placeholder='" . __('Search', 'name-directory') . "...' />";
712 echo "<input type='submit' id='name-directory-search-input-button' class='button' value='" . __('Search', 'name-directory') . "' />";
713
714
715 echo '</p>';
716 if(empty($name_filter['character']) && ! empty($search_value))
717 {
718 echo '<br><br><p class="search-box">';
719 if(empty($directory['name_term']))
720 {
721 echo sprintf(__('There are %d names in this directory containing the search term %s.', 'name-directory'), $num_names, "<em><strong>" . $search_value . "</strong></em>");
722 }
723 else
724 {
725 echo sprintf(__('There are %d %s in this directory containing the search term %s.', 'name-directory'), $num_names, $directory['name_term'], "<em><strong>" . $search_value . "</strong></em>");
726 }
727 echo ' <a href="' . $wp_ndir_path . '"><strong><em>' . __('Clear results', 'name-directory') . '</em></strong></a>';
728 echo "</p>";
729 }
730 else
731 {
732 echo "<br><br>";
733 }
734 echo "</form>";
735 ?>
736
737 <table class="wp-list-table widefat name_directory_names fixed" cellpadding="0">
738 <thead>
739 <tr>
740 <th width="18%"><?php echo __('Name', 'name-directory'); ?></th>
741 <th width="54%"><?php echo __('Description', 'name-directory'); ?></th>
742 <th width="12%"><?php echo __('Submitter', 'name-directory'); ?></th>
743 <th width="9%"><?php echo __('Published', 'name-directory'); ?></th>
744 <th width="15%"><?php echo __('Manage', 'name-directory'); ?></th>
745 </tr>
746 </thead>
747 <tbody>
748 <?php
749 if(empty($name))
750 {
751 echo sprintf("<tr class='empty-directory'><td colspan='5'>%s</td></tr>",
752 __('Currently, there are no names in this directory..', 'name-directory'));
753 }
754
755 foreach($names as $name)
756 {
757 if(is_array($name))
758 {
759 $name = (object)$name;
760 }
761
762 echo sprintf("
763 <tr>
764 <td>%s</td><td>%s</td><td>%s</td><td><span title='%s' class='toggle_published' id='nid_%d' data-nameid='%d'>%s</span></td>
765 <td><a class='button button-primary button-small' href='" . $wp_url_path . "&edit_name=%d#anchor_add_form'>%s</a>
766 <a class='button button-small' href='" . $wp_url_path . "&delete_name=%d'>%s</a>
767 </td>
768 </tr>",
769 $name->name, html_entity_decode(stripslashes($name->description)), $name->submitted_by,
770 __('Toggle published status', 'name-directory'), $name->id,
771 $name->id, name_directory_yesno($name->published),
772 $name->id, __('Edit', 'name-directory'),
773 $name->id, __('Delete', 'name-directory'));
774 }
775 ?>
776 </tbody>
777 </table>
778
779 <p>&nbsp;</p>
780
781 <?php
782 name_directory_print_javascript($emphasis_class);
783 name_directory_print_style();
784 }
785
786
787 /**
788 * Import names from a csv file into directory
789 */
790 function name_directory_import()
791 {
792 if (!current_user_can('manage_options'))
793 {
794 wp_die( __('You do not have sufficient permissions to access this page.', 'name-directory') );
795 }
796
797 global $wpdb;
798 global $name_directory_table_directory;
799 global $name_directory_table_directory_name;
800
801 $directory_id = intval($_GET['dir']);
802 $import_success = false;
803
804 if($_SERVER['REQUEST_METHOD'] == 'POST')
805 {
806 $file = wp_import_handle_upload();
807
808 if( isset($file['error']))
809 {
810 echo $file['error'];
811 return;
812 }
813
814 $csv = array_map('str_getcsv', file($file['file']));
815
816 wp_import_cleanup($file['id']);
817 array_shift($csv);
818
819 $names_error = 0;
820 $names_imported = 0;
821 $names_duplicate = 0;
822 foreach($csv as $entry)
823 {
824 if(! $prepared_row = name_directory_prepared_import_row($entry))
825 {
826 continue;
827 }
828
829 if(name_directory_name_exists_in_directory($prepared_row['name'], $directory_id))
830 {
831 $names_duplicate++;
832 continue;
833 }
834
835 $db_res = $wpdb->insert(
836 $name_directory_table_directory_name,
837 array(
838 'directory' => $directory_id,
839 'name' => stripslashes_deep($prepared_row['name']),
840 'letter' => name_directory_get_first_char($prepared_row['name']),
841 'description' => stripslashes_deep($prepared_row['description']),
842 'published' => $prepared_row['published'],
843 'submitted_by' => !empty($prepared_row['submitted_by']) ? $prepared_row['submitted_by'] : '',
844 ),
845 array('%d', '%s', '%s', '%s', '%d', '%s')
846 );
847
848 if($db_res === false)
849 {
850 $names_error++;
851 }
852 else
853 {
854 $names_imported++;
855 }
856 }
857
858 $notice_class = 'updated';
859 $import_success = true;
860 $import_message = sprintf(__('Imported %d entries in this directory', 'name-directory'), $names_imported);
861
862 if($names_imported === 0)
863 {
864 $notice_class = 'error';
865 $import_success = false;
866 $import_message = __('Could not import any names into Name Directory', 'name-directory');
867 }
868
869 if($names_error > 0)
870 {
871 $notice_class = 'error';
872 $import_success = false;
873 if($names_imported === 0)
874 {
875 $import_message .= "! ";
876 }
877 $import_message .= sprintf(__('There were %d names that produces errors with the WordPress database on import', 'name-directory'), $names_error);
878 }
879
880 if($names_duplicate > 0)
881 {
882 $ignored = (count($csv)==$names_duplicate)?__('all', 'name-directory'):$names_duplicate;
883 echo '<div class="error" style="border-left: 4px solid #ffba00;"><p>'
884 . sprintf(__('Ignored %s names, because they were duplicate (already in the directory)', 'name-directory'), $ignored)
885 . '</p></div>';
886 }
887 elseif($names_imported === 0)
888 {
889 $import_message .= ', ' . __('please check your .csv-file', 'name-directory');
890 }
891
892 echo '<div class="' . $notice_class . '"><p>' . $import_message . '</p></div>';
893 }
894
895 $wp_file = admin_url('admin.php');
896 $wp_page = $_GET['page'];
897 $wp_sub = $_GET['sub'];
898 $overview_url = sprintf("%s?page=%s", $wp_file, $wp_page);
899 $wp_url_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, $wp_sub, $directory_id);
900 $wp_ndir_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, 'manage-directory', $directory_id);
901
902 $directory = $wpdb->get_row("SELECT * FROM " . $name_directory_table_directory . " WHERE `id` = " . $directory_id, ARRAY_A);
903
904 echo '<div class="wrap">';
905 echo '<h2>' . sprintf(__('Import names for %s', 'name-directory'), $directory['name']) . '</h2>';
906 echo '<div class="narrow"><p>';
907 if(! $import_success && empty($names_duplicate))
908 {
909 echo __('Use the upload form below to upload a .csv-file containing all of your names (in the first column), description and submitter are optional.', 'name-directory') . ' ';
910 echo '<h4>' . __('If you saved it from Excel or OpenOffice, please ensure that:', 'name-directory') . '</h4> ';
911 echo '<ol><li>' . __('There is a header row (this contains the column names, the first row will NOT be imported)', 'name-directory');
912 echo '</li><li>' . __('Fields are encapsulated by double quotes', 'name-directory');
913 echo '</li><li>' . __('Fields are comma-separated', 'name-directory');
914 echo '</li></ol>';
915 echo '<h4>' . __('If uploading or importing fails, these are your options', 'name-directory') . ':</h4><ol><li>';
916 echo sprintf(__('Please check out %s first and ensure your file is formatted the same.', 'name-directory'),
917 '<a href="http://plugins.svn.wordpress.org/name-directory/assets/name-directory-import-example.csv" target="_blank">' .
918 __('the example import file', 'name-directory') . '</a>') . '</li>';
919 echo '<li>
920 <a href="https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Calc_Guide/Saving_spreadsheets#Saving_as_a_CSV_file">OpenOffice csv-export help</a>
921 </li>
922 <li>
923 <a href="https://support.office.com/en-us/article/Import-or-export-text-txt-or-csv-files-e8ab9ff3-be8d-43f1-9d52-b5e8a008ba5c?CorrelationId=fa46399d-2d7a-40bd-b0a5-27b99e96cf68&ui=en-US&rs=en-US&ad=US#bmexport">Excel csv-export help</a>
924 </li>
925 <li>
926 <a href="http://www.freefileconvert.com" target="_blank">' .
927 __('Use an online File Convertor', 'name-directory') . '</a>
928 </li><li>';
929 echo sprintf(__('If everything else fails, you can always ask a question at the %s.', 'name-directory'),
930 '<a href="https://wordpress.org/support/plugin/name-directory" target="_blank">' .
931 __('plugin support forums', 'name-directory') . '</a>') . ' ';
932 echo '</li></ol></p>';
933
934 if(! function_exists('str_getcsv'))
935 {
936 echo '<div class="error"><p>';
937 echo __('Name Directory Import requires PHP 5.3, you seem to have in older version. Importing names will not work for your website.', 'name-directory');
938 echo '</p></div>';
939 }
940
941 echo '<h3>' . __('Upload your .csv-file', 'name-directory') . '</h3>';
942 wp_import_upload_form($wp_url_path);
943 }
944 echo '</div></div>';
945 echo '<a href="' . $wp_ndir_path . '">' . sprintf(__('Back to %s', 'name-directory'), '<i>' . $directory['name'] . '</i>') . '</a>';
946 echo ' | ';
947 echo '<a href="' . $overview_url . '">' . __('Go to Name Directory Overview', 'name-directory') . '</a>';
948 }
949
950
951 /**
952 * Page to export names from a directory file as a .csv-file
953 */
954 function name_directory_export()
955 {
956 if (!current_user_can('manage_options'))
957 {
958 wp_die( __('You do not have sufficient permissions to access this page.', 'name-directory') );
959 }
960
961 global $wpdb;
962 global $name_directory_table_directory;
963
964 $directory = $wpdb->get_row("SELECT * FROM " . $name_directory_table_directory . " WHERE `id` = " . intval($_GET['dir']), ARRAY_A);
965
966 $names = name_directory_get_directory_names($directory);
967
968 echo '<table id="export_names" class="hidden"><thead><tr><th>name</th><th>description</th><th>submitter</th></tr></thead><tbody>';
969 foreach($names as $entry)
970 {
971 echo '<tr><td>' . $entry['name'] . '</td><td>' . html_entity_decode(stripslashes($entry['description'])) . '</td><td>' . $entry['submitted_by'] . '</td></tr>';
972 }
973 echo '</tbody></table>';
974
975 /* Notify the user of possible not-working export functionality */
976 if(stripos($_SERVER['HTTP_USER_AGENT'], 'Chrome') === false && stripos($_SERVER['HTTP_USER_AGENT'], 'Firefox') === false)
977 {
978 echo '<div class="notice notice-warning"><p>';
979 echo __('Name Directory Export works best in Mozilla Firefox, Google Chrome and Internet Explorer 10+.', 'name-directory') . ' ';
980 echo __('If you encounter problems (or it does not export) in Internet Explorer or Microsoft Edge, please try another browser.', 'name-directory');
981 echo '</div>';
982 }
983
984 echo '<div class="wrap">';
985 echo '<h2>' . sprintf(__('Export directory %s', 'name-directory'), $directory['name']) . '</h2>';
986 echo '<div class="narrow"><p>';
987 echo __('Click the Export button to download a .csv file with the contents of your directory.', 'name-directory');
988 echo '</p><p><a href="#" id="export_name_directory_names_button" style="text-decoration:none;color:#000;background-color:#ddd;border:1px solid #ccc;padding:8px;">' . __('Export', 'name-directory') . '</a></p>';
989 echo '<a href="' . admin_url('admin.php') . '?page=name-directory">' . __('Go to Name Directory Overview', 'name-directory') . '</a>';
990
991 name_directory_print_export_javascript();
992 }
993
994
995 /**
996 * Proxy for the AJAX request to switch published-statusses
997 * No params, assumes POST
998 */
999 function name_directory_ajax_switch_name_published_status()
1000 {
1001 $name_id = intval($_POST['name_id']);
1002 if(! empty($name_id))
1003 {
1004 echo name_directory_switch_name_published_status($name_id);
1005 exit;
1006 }
1007
1008 echo 'Error!';
1009 exit;
1010 }
1011
1012
1013 /**
1014 * Print the Style rules by this plugin
1015 */
1016 function name_directory_print_style()
1017 {
1018 $style = '
1019
1020 <style>
1021 table.name_directory_names td
1022 {
1023 border-bottom: 1px solid #F0F0F0;
1024 }
1025 .toggle_published:hover {
1026 cursor: pointer;
1027 }
1028 </style>';
1029
1030 echo $style;
1031 }
1032
1033
1034 /**
1035 * Print the Javascripts needed by this plugin
1036 * @param string $emphasis_class
1037 */
1038 function name_directory_print_javascript($emphasis_class = '')
1039 {
1040 $js = '
1041
1042 <script type="text/javascript">
1043 /* Save a named preference to a cookie */
1044 function savePreference(name, value)
1045 {
1046 var expires = "";
1047 document.cookie = name+"="+value+expires+"; path=/";
1048 }
1049
1050 /* Read the named preference from cookie */
1051 function readPreference(name)
1052 {
1053 var nameEQ = name + "=";
1054 var ca = document.cookie.split(";");
1055 for(var i=0;i < ca.length;i++) {
1056 var c = ca[i];
1057 while (c.charAt(0)==" ") c = c.substring(1,c.length);
1058 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
1059 }
1060 return null;
1061 }
1062
1063 jQuery(document).ready(function()
1064 {
1065 jQuery("#input_compact").on("click", function(e)
1066 {
1067 jQuery("#published_yes").attr("checked", "checked");
1068 jQuery("#add_description, #add_published, #add_submitter").hide();
1069 savePreference("wp-plugin-nd-add_form", "compact");
1070 });
1071
1072 jQuery("#input_extensive").on("click", function(e)
1073 {
1074 jQuery("#add_description, #add_published, #add_submitter").show();
1075 savePreference("wp-plugin-nd-add_form", "extensive");
1076 });
1077
1078 var pref = readPreference("wp-plugin-nd-add_form");
1079 if(pref != null)
1080 {
1081 jQuery("#input_" + pref).trigger("click");
1082 if(! window.location.hash)
1083 {
1084 jQuery("html, body").animate({scrollTop:0}, 1);
1085 }
1086 }
1087
1088 jQuery("#add_form_ajax_submit").val("name_directory_ajax_names");
1089
1090 jQuery("#add_name_ajax").on("submit", function(e)
1091 {
1092 var form_data = jQuery(this).serialize();
1093
1094 e.preventDefault();
1095
1096 jQuery("#add_button").attr("disabled", "disabled");
1097
1098 jQuery.ajax({
1099 url: "admin-ajax.php",
1100 type: "POST",
1101 data: form_data,
1102 success: function(data)
1103 {
1104 jQuery("#add_result").addClass("updated").slideDown().html(data);
1105 jQuery("#add_name_ajax input[type=text], #add_name_ajax textarea, #edit_name_id").val("");
1106 },
1107 error: function(data)
1108 {
1109 window.location.reload();
1110 },
1111 complete: function(data)
1112 {
1113 jQuery("#add_button").removeAttr("disabled");
1114 }
1115 });
1116
1117 return false;
1118 });
1119
1120 jQuery(".toggle_published").on("click", function(e)
1121 {
1122 name_id = jQuery(this).attr("data-nameid");
1123 update_ref = jQuery(this).attr("id");
1124
1125 jQuery(this).html("<div class=\'spinner\' style=\'display:block;float:left;\'></div>");
1126
1127 jQuery.ajax({
1128 url: "admin-ajax.php",
1129 type: "POST",
1130 data: { action: "name_directory_switch_name_published_status", name_id: name_id }
1131 }).done(function(status)
1132 {
1133 jQuery("#" + update_ref).html(status);
1134 });
1135 });
1136 });
1137 </script>';
1138
1139 if(! empty($emphasis_class))
1140 {
1141 $js .= "<script>jQuery('." . $emphasis_class . "').css('font-weight', 'bold');</script>";
1142 }
1143
1144 if(! empty($_GET['edit_name']))
1145 {
1146 $js .= "<script>jQuery(document).ready(function(){
1147 jQuery('#input_extensive').trigger('click');
1148 });</script>";
1149 }
1150
1151 print $js;
1152 }
1153
1154
1155 /**
1156 * Print some Javascript which helps on exporting CSV files
1157 * From: https://jsfiddle.net/mnsinger/65hqxygo/
1158 * TODO: I really should get around to use .js files :-)
1159 */
1160 function name_directory_print_export_javascript() {
1161 echo <<<JS
1162 <script type="text/javascript">
1163 function exportTableToCSV(table, filename) {
1164
1165 var rows = table.find('tr:has(td),tr:has(th)');
1166
1167 // Temporary delimiter characters unlikely to be typed by keyboard
1168 // This is to avoid accidentally splitting the actual contents
1169 tmpColDelim = String.fromCharCode(11), // vertical tab character
1170 tmpRowDelim = String.fromCharCode(0), // null character
1171
1172 // actual delimiter characters for CSV format
1173 colDelim = '","',
1174 rowDelim = '"\\r\\n"',
1175
1176 // Grab text from table into CSV formatted string
1177 csv = '"' + rows.map(function (i, row) {
1178 var row = jQuery(row), cols = row.find('td,th');
1179
1180 return cols.map(function (j, col) {
1181 var col = jQuery(col), text = col.text();
1182
1183 return text.replace(/"/g, '""'); // escape double quotes
1184
1185 }).get().join(tmpColDelim);
1186
1187 }).get().join(tmpRowDelim).split(tmpRowDelim).join(rowDelim).split(tmpColDelim).join(colDelim) + '"';
1188
1189 // Data URI
1190 csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
1191
1192 if (window.navigator.msSaveBlob) { // IE 10+
1193 window.navigator.msSaveOrOpenBlob(new Blob([csv], {type: "text/plain;charset=utf-8;"}), "csvname.csv")
1194 }
1195 else {
1196 jQuery(this).attr({ 'download': filename, 'href': csvData, 'target': '_blank' });
1197 }
1198 }
1199
1200 jQuery(document).ready(function()
1201 {
1202 // This must be an a-element hyperlink, so it can download 'data:'-uri's
1203 jQuery("#export_name_directory_names_button").on('click', function (event)
1204 {
1205 exportTableToCSV.apply(this, [jQuery('#export_names'), 'name_directory_export.csv']);
1206 });
1207 });
1208 </script>
1209 JS;
1210
1211 }