Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
152 lines (119 sloc) 6.94 KB
<?php
/*
Copyright (c) 2018, G Burton
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class ht_datepicker_jquery {
var $code = 'ht_datepicker_jquery';
var $group = 'footer_scripts';
var $title;
var $description;
var $sort_order;
var $enabled = false;
function __construct() {
$this->title = MODULE_HEADER_TAGS_DATEPICKER_JQUERY_TITLE;
$this->description = MODULE_HEADER_TAGS_DATEPICKER_JQUERY_DESCRIPTION;
if ( defined('MODULE_HEADER_TAGS_DATEPICKER_JQUERY_STATUS') ) {
$this->sort_order = MODULE_HEADER_TAGS_DATEPICKER_JQUERY_SORT_ORDER;
$this->enabled = (MODULE_HEADER_TAGS_DATEPICKER_JQUERY_STATUS == 'True');
}
}
function execute() {
global $PHP_SELF, $oscTemplate;
if (tep_not_null(MODULE_HEADER_TAGS_DATEPICKER_JQUERY_PAGES)) {
$pages_array = array();
foreach (explode(';', MODULE_HEADER_TAGS_DATEPICKER_JQUERY_PAGES) as $page) {
$page = trim($page);
if (!empty($page)) {
$pages_array[] = $page;
}
}
if (in_array(basename($PHP_SELF), $pages_array)) {
$oscTemplate->addBlock('<script src="ext/datepicker/js/bootstrap-datepicker.min.js"></script>' . "\n", $this->group);
$oscTemplate->addBlock('<link rel="stylesheet" href="ext/datepicker/css/bootstrap-datepicker.min.css" />' . "\n", 'header_tags');
// create_account
// account edit
$oscTemplate->addBlock('<script>$(\'#dob\').datepicker({endDate: "+0d", startView: 2});</script>', $this->group);
}
}
}
function isEnabled() {
return $this->enabled;
}
function check() {
return defined('MODULE_HEADER_TAGS_DATEPICKER_JQUERY_STATUS');
}
function install() {
tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Datepicker jQuery Module', 'MODULE_HEADER_TAGS_DATEPICKER_JQUERY_STATUS', 'True', 'Do you want to enable the Datepicker module?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Pages', 'MODULE_HEADER_TAGS_DATEPICKER_JQUERY_PAGES', '" . implode(';', $this->get_default_pages()) . "', 'The pages to add the Datepicker jQuery Scripts to.', '6', '0', 'ht_datepicker_jquery_show_pages', 'ht_datepicker_jquery_edit_pages(', now())");
tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_DATEPICKER_JQUERY_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}
function remove() {
tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_HEADER_TAGS_DATEPICKER_JQUERY_STATUS', 'MODULE_HEADER_TAGS_DATEPICKER_JQUERY_PAGES', 'MODULE_HEADER_TAGS_DATEPICKER_JQUERY_SORT_ORDER');
}
function get_default_pages() {
return array('advanced_search.php',
'account_edit.php',
'create_account.php');
}
}
function ht_datepicker_jquery_show_pages($text) {
return nl2br(implode("\n", explode(';', $text)));
}
function ht_datepicker_jquery_edit_pages($values, $key) {
global $PHP_SELF;
$file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
$files_array = array();
if ($dir = @dir(DIR_FS_CATALOG)) {
while ($file = $dir->read()) {
if (!is_dir(DIR_FS_CATALOG . $file)) {
if (substr($file, strrpos($file, '.')) == $file_extension) {
$files_array[] = $file;
}
}
}
sort($files_array);
$dir->close();
}
$values_array = explode(';', $values);
$output = '';
foreach ($files_array as $file) {
$output .= tep_draw_checkbox_field('ht_datepicker_jquery_file[]', $file, in_array($file, $values_array)) . '&nbsp;' . tep_output_string($file) . '<br />';
}
if (!empty($output)) {
$output = '<br />' . substr($output, 0, -6);
}
$output .= tep_draw_hidden_field('configuration[' . $key . ']', '', 'id="htrn_files"');
$output .= '<script>
function htrn_update_cfg_value() {
var htrn_selected_files = \'\';
if ($(\'input[name="ht_datepicker_jquery_file[]"]\').length > 0) {
$(\'input[name="ht_datepicker_jquery_file[]"]:checked\').each(function() {
htrn_selected_files += $(this).attr(\'value\') + \';\';
});
if (htrn_selected_files.length > 0) {
htrn_selected_files = htrn_selected_files.substring(0, htrn_selected_files.length - 1);
}
}
$(\'#htrn_files\').val(htrn_selected_files);
}
$(function() {
htrn_update_cfg_value();
if ($(\'input[name="ht_datepicker_jquery_file[]"]\').length > 0) {
$(\'input[name="ht_datepicker_jquery_file[]"]\').change(function() {
htrn_update_cfg_value();
});
}
});
</script>';
return $output;
}
?>
You can’t perform that action at this time.