| 1 |
<?php |
| 2 |
|
| 3 |
/*=====================( END SETTINGS FUNCTIONS )======================= |
| 4 |
======================================================================== |
| 5 |
NOW PRINT OUT OUR DATA IN SETTINGS PAGE |
| 6 |
======================================================================== |
| 7 |
========================( BEGIN SETTINGS PAGE )========================*/ |
| 8 |
|
| 9 |
?> |
| 10 |
|
| 11 |
|
| 12 |
<!-- Tab Head --> |
| 13 |
<div class="container"> |
| 14 |
<div class="tab"> |
| 15 |
<button class="tablinks" onclick="openTabs(event, 'add-content')" id="default" title="Add Content" data="add-content"><i class="dashicons dashicons-plus-alt"></i><span>Add Content</span></button> |
| 16 |
<button class="tablinks" onclick="openTabs(event, 'settings')" title="Settings" data="settings"><i class="dashicons dashicons-admin-generic"></i><span>Settings</span></button> |
| 17 |
</div> |
| 18 |
|
| 19 |
<div class="educare_post educare_settings"> |
| 20 |
|
| 21 |
<!-- Tab add-content --> |
| 22 |
<div id="add-content" class="tab_content"> |
| 23 |
|
| 24 |
<div class="cover"> |
| 25 |
<img src="<?php echo esc_url(EDUCARE_URL.'assets/img/cover.svg'); ?>" alt="educare cover"/> |
| 26 |
</div> |
| 27 |
|
| 28 |
<!-- <h1>Add Content</h1> --> |
| 29 |
|
| 30 |
<?php |
| 31 |
echo '<div id="msg_for_class">'; |
| 32 |
educare_setting_subject("subject"); |
| 33 |
echo '</div>'; |
| 34 |
|
| 35 |
educare_setting_subject("subject", true); |
| 36 |
|
| 37 |
?> |
| 38 |
<script> |
| 39 |
$(document).on("click", "[name=add_class], [name=edit_class], [name=update_class], [name=remove_class], [name=add_subject], [name=edit_subject], [name=update_subject], [name=remove_subject]", function(event) { |
| 40 |
event.preventDefault(); |
| 41 |
var current = $(this); |
| 42 |
var form_data = $(this).parents('form').serialize(); |
| 43 |
// alert(form_data); |
| 44 |
var action_for = $(this).attr("name"); |
| 45 |
// alert(action_for); |
| 46 |
|
| 47 |
$.ajax({ |
| 48 |
url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>", |
| 49 |
data: { |
| 50 |
action: 'educare_process_content', |
| 51 |
form_data: form_data, |
| 52 |
action_for |
| 53 |
}, |
| 54 |
type: 'POST', |
| 55 |
beforeSend:function(event) { |
| 56 |
if (action_for == 'remove_class' || action_for == 'remove_subject') { |
| 57 |
if (action_for == 'remove_class') { |
| 58 |
var target = $(current).prevAll("[name='class']").val(); |
| 59 |
} else { |
| 60 |
var target = $(current).prevAll("[name='subject']").val(); |
| 61 |
} |
| 62 |
|
| 63 |
<?php |
| 64 |
if (educare_check_status('confirmation') == 'checked') { |
| 65 |
echo 'return confirm("Are you sure to remove (" + target + ") from this list?")'; |
| 66 |
} |
| 67 |
?> |
| 68 |
} |
| 69 |
}, |
| 70 |
success: function(data) { |
| 71 |
$('#msg_for_class').html(data); |
| 72 |
}, |
| 73 |
error: function(data) { |
| 74 |
$('#msg_for_class').html("<?php echo educare_guide_for('db_error')?>"); |
| 75 |
}, |
| 76 |
complete: function() { |
| 77 |
// event.remove(); |
| 78 |
}, |
| 79 |
}); |
| 80 |
|
| 81 |
}); |
| 82 |
</script> |
| 83 |
|
| 84 |
<?php educare_get_content();?> |
| 85 |
|
| 86 |
</div> <!-- End Tab add-content --> |
| 87 |
|
| 88 |
<!-- Tab settings --> |
| 89 |
<div id="settings" class="tab_content"> |
| 90 |
|
| 91 |
<?php |
| 92 |
if ( isset( $_POST['educare_default_photos'] ) && isset( $_POST['educare_attachment_id'] ) ) : |
| 93 |
update_option( 'educare_files_selector', absint( sanitize_text_field($_POST['educare_attachment_id'] )) ); |
| 94 |
endif; |
| 95 |
|
| 96 |
wp_enqueue_media(); |
| 97 |
$educare_save_attachment = get_option( 'educare_files_selector', 0 ); |
| 98 |
|
| 99 |
$default_photos = wp_get_attachment_url( get_option( 'educare_files_selector' ) ); |
| 100 |
if ($default_photos == null) { |
| 101 |
$visibility = 'none'; |
| 102 |
$img = EDUCARE_URL.'assets/img/default.svg'; |
| 103 |
$img_type = "<h3 id='educare_img_type' class='title'>Default Photos</h3>"; |
| 104 |
$guide = "<p id='educare_guide'>Current students photos are default. Please upload or select a custom photos from gallery that's you want!</p>"; |
| 105 |
} else { |
| 106 |
$visibility = 'block'; |
| 107 |
$img = wp_get_attachment_url( get_option( 'educare_files_selector' ) ); |
| 108 |
$img_type = "<h3 id='educare_img_type' class='title'>Custom Photos</h3>"; |
| 109 |
$guide = "<p id='educare_guide'></p>"; |
| 110 |
} |
| 111 |
?> |
| 112 |
|
| 113 |
<form method='post'> |
| 114 |
<div id='educare_files_selector_disabled'> |
| 115 |
<div id='educare_files_uploader' class='educare_upload'> |
| 116 |
<div class='educare_files_selector'> |
| 117 |
<img id='educare_attachment_preview' class='educare_student_photos' src='<?php echo esc_url($img);?>'> |
| 118 |
<?php echo wp_kses_post($img_type);?> |
| 119 |
</div> |
| 120 |
|
| 121 |
<?php echo wp_kses_post($guide);?> |
| 122 |
<div id="photos_help"></div> |
| 123 |
<div class="select"> |
| 124 |
<input type="hidden" name='educare_attachment_id' id='educare_attachment_id' value='<?php echo esc_attr(get_option( 'educare_files_selector' )); ?>'> |
| 125 |
|
| 126 |
<input type='hidden' name='educare_attachment_url' id='educare_attachment_url' value='<?php echo esc_url(get_option( 'educare_files_selector' )); ?>'> |
| 127 |
|
| 128 |
<input id="educare_upload_button" type="button" class="button" value="<?php _e( 'Upload Students Photos' ); ?>"/> |
| 129 |
|
| 130 |
<input type='button' id='educare_attachment_title' class="button" value='Pleace Select a students photos' disabled> |
| 131 |
|
| 132 |
<a id='educare_attachment_clean' class='dashicons dashicons-no educare_clean' style='width: auto; display: <?php echo esc_attr($visibility);?>' href='<?php echo esc_js('javascript:;');?>'></a> |
| 133 |
</div> |
| 134 |
<button id='educare_default_photos' type="submit" name="educare_default_photos" class="educare_button full"><i class="dashicons dashicons-yes-alt"></i> Save</button> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
</form> |
| 138 |
|
| 139 |
<h1>Settings</h1> |
| 140 |
|
| 141 |
<div id="msg_for_settings"><?php educare_settings_form();?></div> |
| 142 |
</div> |
| 143 |
|
| 144 |
</div> <!-- / .educare Settings --> |
| 145 |
</div> <!-- / .Container --> |
| 146 |
|
| 147 |
|
| 148 |
<script type='text/javascript'> |
| 149 |
jQuery( document ).ready( function( $ ) { |
| 150 |
// Uploading files |
| 151 |
var file_frame; |
| 152 |
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id |
| 153 |
var educare_media_post_id = <?php echo esc_attr($educare_save_attachment); ?>; // Set this |
| 154 |
jQuery('#educare_upload_button').on('click', function( event ){ |
| 155 |
event.preventDefault(); |
| 156 |
// If the media frame already exists, reopen it. |
| 157 |
if ( file_frame ) { |
| 158 |
// Set the post ID to what we want |
| 159 |
file_frame.uploader.uploader.param( 'post_id', educare_media_post_id ); |
| 160 |
// Open frame |
| 161 |
file_frame.open(); |
| 162 |
return; |
| 163 |
} else { |
| 164 |
// Set the wp.media post id so the uploader grabs the ID we want when initialised |
| 165 |
wp.media.model.settings.post.id = educare_media_post_id; |
| 166 |
} |
| 167 |
// Create the media frame. |
| 168 |
file_frame = wp.media.frames.file_frame = wp.media({ |
| 169 |
title: 'Select Students Photos', |
| 170 |
button: { |
| 171 |
text: 'Use this image', |
| 172 |
}, |
| 173 |
multiple: false // Set to true to allow multiple files to be selected |
| 174 |
}); |
| 175 |
// When an image is selected, run a callback. |
| 176 |
file_frame.on( 'select', function() { |
| 177 |
// We set multiple to false so only get one image from the uploader |
| 178 |
attachment = file_frame.state().get('selection').first().toJSON(); |
| 179 |
// Do something with attachment.id and/or attachment.url here |
| 180 |
// $( '#educare_attachment_preview' ).attr( 'src', attachment.url ).css( 'width', '100px' ); |
| 181 |
$( '#educare_attachment_preview' ).attr( 'src', attachment.url ); |
| 182 |
$( '#educare_upload_button' ).val( 'Edit Photos' ); |
| 183 |
$( '#educare_attachment_clean' ).css( 'display', 'block' ); |
| 184 |
$("#educare_img_type").html('Custom photos'); |
| 185 |
$( '#educare_attachment_id' ).val( attachment.id ); |
| 186 |
$( '#educare_attachment_url' ).val( attachment.url ); |
| 187 |
$( '#educare_attachment_title' ).val( attachment.title ).attr( 'value', this(val) ); |
| 188 |
// Restore the main post ID |
| 189 |
wp.media.model.settings.post.id = wp_media_post_id; |
| 190 |
}); |
| 191 |
// Finally, open the modal |
| 192 |
file_frame.open(); |
| 193 |
}); |
| 194 |
// Restore the main ID when the add media button is pressed |
| 195 |
jQuery( 'a.add_media' ).on( 'click', function() { |
| 196 |
wp.media.model.settings.post.id = wp_media_post_id; |
| 197 |
}); |
| 198 |
// clean files |
| 199 |
$("a.educare_clean").on("click", function() { |
| 200 |
$("#educare_attachment_url").val(""); |
| 201 |
$("#educare_attachment_id").val(""); |
| 202 |
$( '#educare_attachment_preview' ).attr( 'src', "<?php echo esc_url(EDUCARE_URL.'assets/img/default.svg');?>" ); |
| 203 |
$("a.educare_clean").css('display', 'none'); |
| 204 |
$( '#educare_attachment_title' ).val('Cleaned! please select onother one'); |
| 205 |
$( '#educare_upload_button' ).val( 'Upload photos again' ); |
| 206 |
$("#educare_img_type").html('Default photos'); |
| 207 |
$("#educare_guide").html("Current students photos are default. Please upload or select a custom photos from gallery that's you want!"); |
| 208 |
}); |
| 209 |
}); |
| 210 |
|
| 211 |
|
| 212 |
<?php |
| 213 |
if (educare_check_status('photos') == 'unchecked') { |
| 214 |
$photos = 'disabled'; |
| 215 |
} else { |
| 216 |
$photos = ''; |
| 217 |
} |
| 218 |
?> |
| 219 |
|
| 220 |
var photos = '<?php echo educare_esc_str($photos);?>'; |
| 221 |
if (photos == 'disabled') { |
| 222 |
document.getElementById('educare_upload_button').setAttribute('disabled', 'disabled'); |
| 223 |
document.getElementById('educare_default_photos').setAttribute('disabled', 'disabled'); |
| 224 |
document.getElementById('educare_attachment_clean').style.display= 'none'; |
| 225 |
document.getElementById('educare_files_selector_disabled').className = 'educare_files_selector_disabled'; |
| 226 |
document.getElementById('photos_help').innerHTML = 'Currently students photos are disabled. If you upload or display student photos, first check/anable students photos under the settings sections'; |
| 227 |
} |
| 228 |
</script> |
| 229 |
|
| 230 |
|
| 231 |
<script type="text/javascript"> |
| 232 |
function openTabs(evt, tabName) { |
| 233 |
// Declare all variables |
| 234 |
var i, tab_content, tablinks; |
| 235 |
|
| 236 |
// Get all elements with class="tab_content" and hide them |
| 237 |
tab_content = document.getElementsByClassName("tab_content"); |
| 238 |
for (i = 0; i < tab_content.length; i++) { |
| 239 |
tab_content[i].style.display = "none"; |
| 240 |
} |
| 241 |
|
| 242 |
// Get all elements with class="tablinks" and remove the class "active" |
| 243 |
tablinks = document.getElementsByClassName("tablinks"); |
| 244 |
for (i = 0; i < tablinks.length; i++) { |
| 245 |
tablinks[i].className = tablinks[i].className.replace(" active", ""); |
| 246 |
} |
| 247 |
|
| 248 |
// Show the current tab, and add an "active" class to the button that opened the tab |
| 249 |
document.getElementById(tabName).style.display = "block"; |
| 250 |
evt.currentTarget.className += " active"; |
| 251 |
} |
| 252 |
|
| 253 |
// Get the element with id="defaultOpen" and click on it |
| 254 |
document.getElementById("default").click(); |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
jQuery( document ).ready( function( $ ) { |
| 259 |
var advance = '<?php echo educare_esc_str(educare_check_status('advance'));?>'; |
| 260 |
if (advance == 'unchecked') { |
| 261 |
$( '#advance_settings' ).css( 'display', "none" ); |
| 262 |
} |
| 263 |
}); |
| 264 |
|
| 265 |
$(document).on("click", "[name=educare_update_settings_status], [name=educare_reset_default_settings]", function(event) { |
| 266 |
event.preventDefault(); |
| 267 |
// var currenTab = $(".head[name=subject]:checked").attr("id"); |
| 268 |
var current = $(this); |
| 269 |
var form_data = $(this).parent('form').serialize(); |
| 270 |
var action_for = $(this).attr("name"); |
| 271 |
$.ajax({ |
| 272 |
url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>", |
| 273 |
data: { |
| 274 |
action: 'educare_process_content', |
| 275 |
form_data: form_data, |
| 276 |
action_for |
| 277 |
}, |
| 278 |
type: 'POST', |
| 279 |
beforeSend:function(event) { |
| 280 |
$(current).css('color', 'red'); |
| 281 |
if (action_for == 'educare_reset_default_settings') { |
| 282 |
<?php |
| 283 |
if (educare_check_status('confirmation') == 'checked') { |
| 284 |
echo 'return confirm("Are you sure to reset default settings? This will not effect your content (Class, Subject, Exam, Year, Extra Field), Its only reset your current settings status and value.")'; |
| 285 |
} |
| 286 |
?> |
| 287 |
} |
| 288 |
}, |
| 289 |
success: function(data) { |
| 290 |
$('#msg_for_settings').html(data); |
| 291 |
}, |
| 292 |
error: function(data) { |
| 293 |
$('#msg_for_settings').html("<?php echo educare_guide_for('db_error')?>"); |
| 294 |
}, |
| 295 |
complete: function() { |
| 296 |
$(current).css('color', 'white'); |
| 297 |
// event.remove(); |
| 298 |
}, |
| 299 |
}); |
| 300 |
|
| 301 |
}); |
| 302 |
</script> |
| 303 |
|
| 304 |
|