-
Notifications
You must be signed in to change notification settings - Fork 2
/
create-settings.php
146 lines (128 loc) · 7.13 KB
/
create-settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
include_once('printer-settings-page.php');
function star_cloudprnt_is_woo_activated()
{
return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')));
}
function star_cloudprnt_settings()
{
add_settings_section("star_cloudprnt_setup_section", "CloudPRNT Setup", "star_cloudprnt_setup_section_info", "star_cloudprnt_setup");
add_settings_field("star-cloudprnt-select", "CloudPRNT", "star_cloudprnt_select_display", "star_cloudprnt_setup", "star_cloudprnt_setup_section");
add_settings_field("star-cloudprnt-printer-select", "Selected Printer", "star_cloudprnt_printer_select_display", "star_cloudprnt_setup", "star_cloudprnt_setup_section");
add_settings_section("star_cloudprnt_print_logo_settings_section", "Printer Logo Settings", null, "star_cloudprnt_setup");
add_settings_field("star-cloudprnt-print-logo-top-cb", "Print Logo (Top of Receipt)",
"star_cloudprnt_print_logo_top_display", "star_cloudprnt_setup", "star_cloudprnt_print_logo_settings_section");
add_settings_field("star-cloudprnt-print-logo-top-input", "Top Logo Key Code",
"star_cloudprnt_print_logo_top_input_display", "star_cloudprnt_setup", "star_cloudprnt_print_logo_settings_section");
add_settings_field("star-cloudprnt-print-logo-bottom-cb", "Print Logo (Bottom of Receipt)",
"star_cloudprnt_print_logo_bottom_display", "star_cloudprnt_setup", "star_cloudprnt_print_logo_settings_section");
add_settings_field("star-cloudprnt-print-logo-bottom-input", "Bottom Logo Key Code",
"star_cloudprnt_print_logo_bottom_input_display", "star_cloudprnt_setup", "star_cloudprnt_print_logo_settings_section");
register_setting("star_cloudprnt_setup_section", "star-cloudprnt-select");
register_setting("star_cloudprnt_setup_section", "star-cloudprnt-printer-select");
register_setting("star_cloudprnt_setup_section", "star-cloudprnt-print-logo-top-cb");
register_setting("star_cloudprnt_setup_section", "star-cloudprnt-print-logo-top-input");
register_setting("star_cloudprnt_setup_section", "star-cloudprnt-print-logo-bottom-cb");
register_setting("star_cloudprnt_setup_section", "star-cloudprnt-print-logo-bottom-input");
}
function star_cloudprnt_menu_item()
{
add_submenu_page("options-general.php", "Star CloudPRNT for WooCommerce", "Star CloudPRNT for WooCommerce", "manage_options", "star-cloudprnt-settings-admin", "star_cloudprnt_page");
}
function star_cloudprnt_setup_section_info()
{
print '<strong>Set your printer "Server URL" to:</strong><br>';
print plugins_url('cloudprnt/cloudprnt.php', __FILE__);
}
function star_cloudprnt_select_display()
{
?>
<select name="star-cloudprnt-select">
<option value="disable" <?php selected(get_option('star-cloudprnt-select'), "disable"); ?>>DISABLE</option>
<option value="enable" <?php selected(get_option('star-cloudprnt-select'), "enable"); ?>>ENABLE</option>
</select>
<?php
}
function star_cloudprnt_printer_select_display()
{
$printerList = star_cloudprnt_get_printer_list();
if (empty($printerList)) echo '<select name="star-cloudprnt-printer-select" disabled><option value="none">No printer found</option></select>';
else
{
$selectedPrinter = "";
echo '<select id="star-cloudprnt-printer-select-id" name="star-cloudprnt-printer-select">';
foreach ($printerList as $printer)
{
?>
<script type="text/javascript">
function star_cloudprnt_load_printer_settings()
{
var selected_printer_cb = document.getElementById("star-cloudprnt-printer-select-id");
var selected_printer = selected_printer_cb.options[selected_printer_cb.selectedIndex].value;
window.location.href = '?page=<?php echo $_GET['page']; ?>&printersettings='+btoa(selected_printer);
}
</script>
<option value="<?php echo $printer['name']; ?>" <?php selected(get_option('star-cloudprnt-printer-select'), $printer['name']); ?>><?php echo $printer['name']; ?></option>
<?php
if (get_option('star-cloudprnt-printer-select') == $printer['name']) $selectedPrinter = $printer['printerMAC'];
}
echo '</select>';
echo '<a href="javascript: void(0);" onclick="star_cloudprnt_load_printer_settings()" style="margin-left: 10px">Edit</a>';
}
}
function star_cloudprnt_print_logo_top_display()
{
echo '<input type="checkbox" name="star-cloudprnt-print-logo-top-cb" '.checked(get_option('star-cloudprnt-print-logo-top-cb'), 'on', false).' onclick="document.getElementById(\'star-cloudprnt-top-logo-input\').disabled = !this.checked;">';
}
function star_cloudprnt_print_logo_top_input_display()
{
$option_value = '01';
if (get_option('star-cloudprnt-print-logo-top-input')) $option_value = esc_attr(get_option('star-cloudprnt-print-logo-top-input'));
$disabled = (get_option('star-cloudprnt-print-logo-top-cb') === 'on') ? "" : " disabled";
echo '<input type="text" style="width: 30px;" id="star-cloudprnt-top-logo-input" name="star-cloudprnt-print-logo-top-input" value="'.$option_value.'"'.$disabled.'>';
}
function star_cloudprnt_print_logo_bottom_display()
{
echo '<input type="checkbox" name="star-cloudprnt-print-logo-bottom-cb" '.checked(get_option('star-cloudprnt-print-logo-bottom-cb'), 'on', false).' onclick="document.getElementById(\'star-cloudprnt-bottom-logo-input\').disabled = !this.checked;">';
}
function star_cloudprnt_print_logo_bottom_input_display()
{
$option_value = '01';
if (get_option('star-cloudprnt-print-logo-bottom-input')) $option_value = esc_attr(get_option('star-cloudprnt-print-logo-bottom-input'));
$disabled = (get_option('star-cloudprnt-print-logo-bottom-cb') === 'on') ? "" : " disabled";
echo '<input type="text" style="width: 30px;" id="star-cloudprnt-bottom-logo-input" name="star-cloudprnt-print-logo-bottom-input" value="'.$option_value.'"'.$disabled.'>';
}
function star_cloudprnt_show_settings_page()
{
echo '<form method="post" action="options.php">';
settings_fields("star_cloudprnt_setup_section");
do_settings_sections("star_cloudprnt_setup");
submit_button();
echo '</form>';
}
function star_cloudprnt_page()
{
echo '<div class="wrap">';
echo '<img src="'.plugins_url('images/logo.png', __FILE__).'">';
echo '<h1>Star CloudPRNT for WooCommerce Settings</h1>';
if (star_cloudprnt_is_woo_activated())
{
if (isset($_GET['printersettings']))
{
if (isset($_GET['npn'])) star_cloudprnt_change_printer_name();
else if (isset($_GET['cq'])) star_cloudprnt_clear_printer_queue();
else if (isset($_GET['coh'])) star_cloudprnt_clear_order_history();
else if (isset($_GET['dp'])) star_cloudprnt_delete_printer();
else star_cloudprnt_show_printer_settings_page();
}
else star_cloudprnt_show_settings_page();
}
else echo '<br><span style="color: red"><span class="dashicons dashicons-no"></span>Error: WooCommerce plugin is not activated.</span>';
echo '</div>';
}
function star_cloudprnt_create_settings_page()
{
add_action("admin_init", "star_cloudprnt_settings");
add_action("admin_menu", "star_cloudprnt_menu_item");
}
?>