<?php
/**
* LayerSlider v5.1.2 - Responsive Slideshow Module http://layerslider.webshopworks.com
*
*  @author    WebshopWorks <info@webshopworks.com>
*  @copyright 2015 WebshopWorks
*  @license   One Domain Licence
*/

if (!defined('_PS_VERSION_'))
	exit;

$ls_screen_options = get_option('ls-screen-options', '0');
$ls_screen_options = ($ls_screen_options == 0) ? array() : $ls_screen_options;
$ls_screen_options = is_array($ls_screen_options) ? $ls_screen_options : unserialize($ls_screen_options);

if (!isset($ls_screen_options['showTooltips']))
	$ls_screen_options['showTooltips'] = 'true';
if (!isset($ls_screen_options['showRemovedSliders']))
	$ls_screen_options['showRemovedSliders'] = 'false';
if (!isset($ls_screen_options['numberOfSliders']))
	$ls_screen_options['numberOfSliders'] = '10';

$cur_page = (Tools::getIsset('paged') && is_numeric(Tools::getValue('paged'))) ? (int)Tools::getValue('paged') : 1;

$filters = array('page' => $cur_page, 'limit' => (int)$ls_screen_options['numberOfSliders']);
if ($ls_screen_options['showRemovedSliders'] == 'true')
	$filters['exclude'] = array('hidden');

$sliders = LSSliders::find($filters);

$max_item = LSSliders::$count;
$max_page = ceil($max_item / (int)$ls_screen_options['numberOfSliders']);
$max_page = $max_page ? $max_page : 1;

$custom_capability = $custom_role = get_option('layerslider_custom_capability', 'manage_options');
$default_capabilities = array('manage_network', 'manage_options', 'publish_pages', 'publish_posts', 'edit_posts');

if (in_array($custom_capability, $default_capabilities))
	$custom_capability = '';
else
	$custom_role = 'custom';

$general_info = $related_news = '';
$support_ticket_url = $support_us_url = '';

if (!class_exists('phpQuery'))
{
	libxml_use_internal_errors(true);
	include LS_ROOT_PATH.'/helpers/phpQuery.php';
}
require_once LS_ROOT_PATH.'helpers/admin.ui.tools.php';
$hook = array(
	'value' => '',
	'keys' => 'hook',
	'options' => ls_get_hooks(),
	'attrs' => array(
		'class' => 'ls-hook',
		'name' => ''
	)
);
$modpos = array();
$modules = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'layerslider_module');
foreach ($modules as &$m)
	$modpos[$m['id_slider']] = &$m;

$google_fonts = get_option('ls-google-fonts', array());

$ls_adv_settings_toggle = false;
$ls_google_fonts_toggle = false;

$notifications = array(
	'removeSelectError' => __('No sliders were selected to remove.', 'LayerSlider'),
	'removeSuccess' => __('The selected sliders were removed.', 'LayerSlider'),
	'deleteSelectError' => __('No sliders were selected.', 'LayerSlider'),
	'deleteSuccess' => __('The selected sliders were deleted permanently.', 'LayerSlider'),
	'mergeSelectError' => __('You need to select at least 2 sliders to merge them.', 'LayerSlider'),
	'mergeSuccess' => __('The selected items were merged together as a new slider.', 'LayerSlider'),
	'restoreSelectError' => __('No sliders were selected.', 'LayerSlider'),
	'restoreSuccess' => __('The selected sliders were restored.', 'LayerSlider'),

	'exportSelectError' => __('No sliders were selected to export.', 'LayerSlider'),
	'exportZipError' => __('The PHP ZipArchive extension is required to import ZIPs.', 'LayerSlider'),

	'importSelectError' => __('Choose a file to import sliders.', 'LayerSlider'),
	'importFailed' => __('The import file seems to be invalid or corrupted.', 'LayerSlider'),
	'importSuccess' => __('Your slider has been imported.', 'LayerSlider'),
	'permissionError' => __('Your account does not have the necessary permission you chose, and your settings have not been saved to prevent locking yourself out of the plugin.', 'LayerSlider'),
	'permissionSuccess' => __('Permission changes has been updated.', 'LayerSlider'),
	'google_fontsUpdated' => __('Your Google Fonts library has been updated.', 'LayerSlider'),
	'generalUpdated' => __('Your settings has been updated.', 'LayerSlider')
);
?>
<div id="ls-screen-options" class="metabox-prefs hidden">
	<div id="screen-options-wrap" class="hidden">
		<form id="ls-screen-options-form" action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
			<h5><?php _e('Show on screen', 'LayerSlider') ?></h5>
			<label><input type="checkbox" name="showTooltips"<?php echo $ls_screen_options['showTooltips'] == 'true' ? ' checked="checked"' : ''?>> <?php _e('Tooltips', 'LayerSlider') ?></label>
			<label><input type="checkbox" name="showRemovedSliders" class="reload"<?php echo $ls_screen_options['showRemovedSliders'] == 'true' ? ' checked="checked"' : ''?>> <?php _e('Removed sliders', 'LayerSlider') ?></label><br>

			<input type="number" name="numberOfSliders" min="3" step="1" value="<?php echo $ls_screen_options['numberOfSliders'] ?>"> <?php _e('Sliders', 'LayerSlider') ?>
			<button class="button"><?php _e('Apply', 'LayerSlider') ?></button>
		</form>
	</div>
	<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
		<a href="#screen-options-wrap" id="show-settings-link" class="show-settings"><?php _e('Screen Options', 'LayerSlider') ?></a>
	</div>
</div>
<div class="wrap" id="ls-list-page">
	<h2>
		<?php _e('List of Sliders', 'LayerSlider') ?>
		<a href="#" id="ls-add-slider-button" class="add-new-h2"><?php _e('Add New', 'LayerSlider') ?></a>
		<a href="#" id="ls-import-samples-button" class="add-new-h2"><?php _e('Import sample sliders', 'LayerSlider') ?></a>
	</h2>

	<!-- Error messages -->
	<?php if (Tools::getIsset('message'))
	{?>
	<div class="ls-notification <?php echo Tools::getIsset('error') ? 'warning' : 'changed' ?>">
		<div><?php echo $notifications[Tools::getValue('message')] ?></div>
	</div>
	<?php
	}?>
	<!-- End of error messages -->

	<!-- Version number -->
	<?php if (strpos(LS_PLUGIN_VERSION, 'b') !== false)
	{?>
	<div class="ls-version-number">
		<?php _e('Using beta version', 'LayerSlider') ?> (<?php echo LS_PLUGIN_VERSION ?>)
		<a href="mailto:support@kreaturamedia.com?subject=LayerSlider WP Beta Feedback"><?php _e('Send feedback', 'LayerSlider') ?></a>
	</div>
	<?php
	}?>
	<!-- End of version number -->

	<!-- Add slider template -->
	<form action="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=addNewSlider" method="post" id="ls-add-slider-template" class="ls-pointer ls-box">
		<?php wp_nonce_field('add-slider'); ?>
		<input type="hidden" name="ls-add-new-slider" value="1">
		<span class="ls-mce-arrow"></span>
		<h3 class="header"><?php _e('Give a name for your new slider', 'LayerSlider') ?></h3>
		<div class="inner">
			<input type="text" name="title" placeholder="<?php _e('e.g. Homepage slider', 'LayerSlider') ?>">
			<button class="button"><?php _e('Add slider', 'LayerSlider') ?></button>
		</div>
	</form>
	<!-- End of Add slider template -->

	<!-- Import sample sliders template -->
	<div id="ls-import-samples-template" class="ls-pointer ls-box">
		<span class="ls-mce-arrow"></span>
		<h3 class="header"><?php _e('Choose a demo slider to import', 'LayerSlider') ?></h3>
		<ul class="inner">
			<li>
				<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=importSample&slider=v5.zip">
					<div class="preview"><img src="<?php echo __PS_BASE_URI__.'modules/layerslider/views/img/base/demos/v5.jpg' ?>"></div>
					<div class="title">LayerSlider 5 responsive demo slider</div>
				</a>
			</li>
			<li>
				<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=importSample&slider=fullwidth.zip">
					<div class="preview"><img src="<?php echo __PS_BASE_URI__.'modules/layerslider/views/img/base/demos/fullwidth.jpg' ?>"></div>
					<div class="title">Full width demo slider</div>
				</a>
			</li>
			<li>
				<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=importSample&slider=carousel.zip">
					<div class="preview"><img src="<?php echo __PS_BASE_URI__.'modules/layerslider/views/img/base/demos/carousel.jpg' ?>"></div>
					<div class="title">Carousel demo</div>
				</a>
			</li>
		</ul>
		<ul class="inner sep">
			<li>
				<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=importSample&slider=all">
					Import all demo sliders (might be slow)
				</a>
			</li>
		</ul>
	</div>
	<!-- End of Import sample sliders template -->

	<form action="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=manageSliders" method="post">
		<input type="hidden" name="ls-bulk-action" value="1">
		<?php wp_nonce_field('bulk-action'); ?>
		<div class="ls-box ls-sliders-list">
			<table>
				<thead class="header">
					<tr>
						<td></td>
						<td><?php _e('ID', 'LayerSlider') ?></td>
						<td class="preview"><?php _e('Slider preview', 'LayerSlider') ?></td>
						<td><?php _e('Name', 'LayerSlider') ?></td>
						<td><?php _e('Module Position', 'LayerSlider') ?></td>
						<td><?php _e('Slides', 'LayerSlider') ?></td>
						<td><?php _e('Created', 'LayerSlider') ?></td>
						<td><?php _e('Modified', 'LayerSlider') ?></td>
						<td></td>
					</tr>
				</thead>
				<tbody>
				<?php if (!empty($sliders))
				{?>
					<?php foreach ($sliders as $key => $item)
					{?>
					<?php $class = ($item['flag_deleted'] == '1') ? ' class="faded"' : '' ?>
					<tr<?php echo $class ?>>
						<td><input type="checkbox" name="id[]" value="<?php echo $item['id'] ?>"></td>
						<td><?php echo $item['id'] ?></td>
						<td class="preview">
							<div>
								<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSliderEdit') ?>&id=<?php echo $item['id'] ?>">
									<img src="<?php echo apply_filters('ls_get_preview_for_slider', $item ) ?>" alt="Slider preview">
								</a>
							</div>
						</td>
						<td class="name">
							<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSliderEdit') ?>&id=<?php echo $item['id'] ?>">
								<?php echo apply_filters('ls_slider_title', $item['name'], 40) ?>
							</a>
						</td>
						<td>
							<?php lsGetSelect($hook, array('hook' => @$modpos[$item['id']]['hook']), array('data-id' => $item['id'])) ?>
							<a href="javascript:;" class="ls-hook-update" style="visibility:hidden">
								<?php if (version_compare(_PS_VERSION_, '1.6.0', '<'))
								{?>
								<span class="dashicons dashicons-update" data-help="<?php _e('Update module position', 'LayerSlider') ?>"></span>
								<?php
								}
								else
								{?>
								<i class="icon-save" style="font-size:17px" data-help="<?php _e('Save module position', 'LayerSlider') ?>"></i>
								<?php
								}?>
							</a>
						</td>
						<td><?php echo count($item['data']['layers']) ?></td>
						<td><?php echo date('d/m/y', $item['date_c']) ?></td>
						<td><?php echo human_time_diff($item['date_m']) ?> <?php _e('ago', 'LayerSlider') ?></td>
						<td>
							<?php if (!$item['flag_deleted'])
							{?>
							<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider').'&action=duplicateSlider&id='.$item['id'] ?>">
								<span class="dashicons dashicons-admin-page" data-help="<?php _e('Duplicate this slider', 'LayerSlider') ?>"></span>
							</a>
							<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider').'&action=manageSliders&task=remove&id='.$item['id'] ?>">
								<span class="dashicons dashicons-post-trash" data-help="<?php _e('Remove this slider', 'LayerSlider') ?>"></span>
							</a>
							<?php
							}
							else
							{?>
							<a href="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider').'&action=manageSliders&task=restore&id='.$item['id'] ?>">
								<span class="dashicons dashicons-backup" data-help="<?php _e('Restore removed slider', 'LayerSlider') ?>"></span>
							</a>
							<?php
							}?>
						</td>
					</tr>
					<?php
					}?>
				<?php
				}?>
				<?php if (empty($sliders))
				{?>
				<tr>
					<td colspan="9"><?php _e('You haven\'t created any a slider yet. Click on the "Add New" button above to add one.', 'LayerSlider') ?></td>
				</tr>
				<?php
				}?>
				</tbody>
			</table>
			<div class="ls-bulk-actions">
			<select name="task">
				<option value="0"><?php _e('Choose an action', 'LayerSlider') ?></option>
				<option value="remove"><?php _e('Remove selected', 'LayerSlider') ?></option>
				<option value="delete"><?php _e('Delete permanently', 'LayerSlider') ?></option>
				<?php if ($ls_screen_options['showRemovedSliders'] == 'true')
				{?>
				<option value="restore"><?php _e('Restore removed', 'LayerSlider') ?></option>
				<?php
				}?>
				<option value="merge"><?php _e('Merge selected as new', 'LayerSlider') ?></option>
			</select>
			<button class="button"><?php _e('Apply', 'LayerSlider') ?></button>
		</div>
		</div>
	</form>
	<div class="ls-pagination tablenav bottom">
		<div class="tablenav-pages">
			<span class="displaying-num"><?php echo $max_item ?> <?php _e('items', 'LayerSlider') ?></span>
			<span class="pagination-links">
				<a class="first-page<?php echo ($cur_page <= 1) ? ' disabled' : ''; ?>" title="Go to the first page" href="admin.php?page=layerslider">«</a>
				<a class="prev-page <?php echo ($cur_page <= 1) ? ' disabled' : ''; ?>" title="Go to the previous page" href="admin.php?page=layerslider&amp;paged=<?php echo ($cur_page - 1) ?>">‹</a>
				<form action="admin.php" method="get" class="paging-input">
					<input type="hidden" name="page" value="layerslider">
					<input class="current-page" title="Current page" type="text" name="paged" value="<?php echo $cur_page ?>" size="1"> of
					<span class="total-pages"><?php echo $max_page ?></span>
				</form>
				<a class="next-page <?php echo ($cur_page >= $max_page) ? ' disabled' : ''; ?>" title="Go to the next page" href="admin.php?page=layerslider&amp;paged=<?php echo ($cur_page + 1) ?>">›</a>
				<a class="last-page <?php echo ($cur_page >= $max_page) ? ' disabled' : ''; ?>" title="Go to the last page" href="admin.php?page=layerslider&amp;paged=<?php echo $max_page ?>">»</a>
			</span>
		</div>
	</div>

	<div class="ls-export-wrapper columns clearfix">
		<div class="half">
			<div class="ls-import-export-box ls-box">
				<h3 class="header medium"><?php _e('Import & Export Sliders', 'LayerSlider') ?></h3>
				<form action="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=importSlider" method="post" enctype="multipart/form-data" class="ls-import-box">
					<?php wp_nonce_field('import-sliders'); ?>
					<input type="hidden" name="ls-import" value="1">
					<table data-help="<?php _e('Choose a LayerSlider export file downloaded previously to import your sliders. To import from outdated versions, you need to create a file and paste the export code into it. The file needs to have a .json extension.', 'LayerSlider') ?>">
						<tbody>
							<tr>
								<td><?php  _e('Import Sliders', 'LayerSlider') ?></td>
								<td><input type="file" name="import_file"></td>
								<td><button class="button"><?php _e('Import', 'LayerSlider') ?></button></td>
							</tr>
						</tbody>
					</table>
				</form>
				<form action="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=exportSlider" method="post" class="ls-export-form">
					<?php wp_nonce_field('export-sliders'); ?>
					<input type="hidden" name="ls-export" value="1">
					<table>
						<tbody>
							<tr>
								<td valign="top"><?php _e('Export Sliders', 'LayerSlider') ?></td>
								<td>
									<select name="sliders[]" multiple="multiple" data-help="<?php _e('Downloads an export file that contains your selected sliders to import on your new site. You can select multiple sliders by holding the Ctrl/Cmd button while clicking.', 'LayerSlider') ?>">
										<option value="-1" selected> <?php _e('All Sliders', 'LayerSlider') ?></option>
										<?php foreach ($sliders as $slider)
										{?>
										<option value="<?php echo $slider['id'] ?>">
											#<?php echo str_replace(' ', '&nbsp;', str_pad($slider['id'], 3, ' ')) ?> -
											<?php echo $slider['name'] ?>
										</option>
										<?php
										}?>
									</select>

									<label>
										<input type="checkbox"  class="checkbox" name="exportWithImages" checked> Export with images
									</label>
									<button class="button"><?php _e('Export', 'LayerSlider') ?></button>
								</td>
							</tr>
						</tbody>
						<tfoot>
							<tr data-help="The PHP ZipArchive extension is needed for exporting/importing images. The plugin will only copy your slider settings if it's not available. In that case please contact with your hosting provider.">
								<td>Status</td>
								<td colspan="2" class="<?php echo class_exists('ZipArchive') ? 'available' : 'notavailable' ?>">
									<?php echo class_exists('ZipArchive') ?
										'ZipArchive is available to import/export images' :
										'ZipArchive isn\'t avilable'
									?>
								</td>
							</tr>
						</tfoot>
					</table>
				</form>
			</div>
		</div>

		<div class="half">
			<form action="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=saveAdvancedSettings" method="post" class="ls-box ls-global-settings<?php echo $ls_adv_settings_toggle ? ' collapsed' : '' ?>">
				<?php wp_nonce_field('save-advanced-settings'); ?>
				<input type="hidden" name="ls-save-advanced-settings">
				<h2 class="header medium">
					<?php _e('Advanced Settings', 'LayerSlider') ?>
					<!--span id="ls-advanced-settings-toggle" class="dashicons dashicons-arrow-<?php echo $ls_adv_settings_toggle ? 'right' : 'down' ?> ls-ficon ls-box-toggle"></span-->
				</h2>
				<div>
					<table>
						<tr>
							<td><?php _e('Load jQuery on frontend', 'LayerSlider') ?></td>
							<td><input type="checkbox" name="load_jquery" <?php echo get_option('load_jquery', false) ? 'checked="checked"' : '' ?>></td>
							<td class="desc"><?php _e('Switch this option off if jQuery is already loaded on your site.', 'LayerSlider') ?></td>
						</tr>
					</table>
					<div class="footer">
						<button type="submit" class="button"><?php _e('Save changes', 'LayerSlider') ?></button>
					</div>
				</div>
			</form>
		</div>

	</div>

	<form action="<?php echo Context::getContext()->link->getAdminLink('AdminLayerSlider') ?>&action=saveGoogleFonts" method="post" class="ls-box ls-google-fonts<?php echo $ls_google_fonts_toggle ? ' collapsed' : '' ?>">
		<?php wp_nonce_field('save-google-fonts'); ?>
		<input type="hidden" name="ls-save-google-fonts" value="1">

		<!-- Google Fonts Header -->
		<h2 class="header medium">
			<?php _e('Load Google Fonts', 'LayerSlider') ?>
			<!--span id="ls-google-fonts-toggle" class="dashicons dashicons-arrow-<?php echo $ls_google_fonts_toggle ? 'right' : 'down' ?> ls-ficon ls-box-toggle"></span-->
		</h2>

		<!-- Google Fonts list -->
		<div class="inner">
			<ul class="ls-font-list">
				<li class="ls-hidden">
					<a href="#" class="remove" title="Remove this font">x</a>
					<input type="text" name="url_params[]" readonly="readonly">
					<input type="checkbox" name="only_on_admin[]">
					<?php _e('Load only on admin interface', 'LayerSlider') ?>
				</li>
				<?php if (is_array($google_fonts) && !empty($google_fonts))
				{?>
				<?php foreach ($google_fonts as $key => $item)
				{?>
				<li>
					<a href="#" class="remove" title="Remove this font">x</a>
					<input type="text" name="url_params[<?php echo $key ?>]" value="<?php echo $item['param'] ?>" readonly="readonly">
					<input type="checkbox" name="only_on_admin[<?php echo $key ?>]" <?php echo $item['admin'] ? ' checked="checked"' : '' ?>>
					<?php _e('Load only on admin interface', 'LayerSlider') ?>
				</li>
				<?php
				}
				}
				else
				{?>
				<li class="ls-notice">
					<?php _e('You didn\'t add any Google font to your library yet.', 'LayerSlider') ?>
				</li>
				<?php
				}?>
			</ul>
		</div>

		<!-- Google Fonts search bar -->
		<div class="inner ls-font-search footer">
			<button type="submit" class="button"><?php _e('Save changes', 'LayerSlider') ?></button>

			<div class="right">
				<?php _e('Add font:', 'LayerSlider') ?>
				<input type="text" placeholder="Search Google Fonts library">
				<button class="button"><?php _e('Search', 'LayerSlider') ?></button>
			</div>

			<!-- Google Fonts search pointer -->
			<div class="ls-box ls-pointer">
				<h3 class="header"><?php _e('Choose a font family', 'LayerSlider') ?></h3>
				<div class="fonts">
					<ul class="inner"></ul>
				</div>
				<div class="variants">
					<ul class="inner"></ul>
					<div class="inner">
						<button class="button add-font"><?php _e('Add font', 'LayerSlider') ?></button>
						<button class="button right"><?php _e('Back to results', 'LayerSlider') ?></button>
					</div>
				</div>
			</div>
		</div>
	</form>

</div>

<script type="text/javascript">
	var lsScreenOptions = <?php echo Tools::jsonEncode($ls_screen_options) ?>;
</script>
