<?php // utf-8 check: äöü

if (!defined('CMSIMPLE_VERSION') || preg_match('#plugins/multimediaslider/admin.php#i', $_SERVER['SCRIPT_NAME']))
{
	die('no direct access');
}

/*
============================================================
CMSimple Plugin MultiMediaSlider
============================================================
Version:    MultiMediaSlider 1.2
Released:   2022-04
Copyright:  Gert Ebersbach
Internet:   www.ge-webdesign.de
Credit:     jQuery Plugin Fotorama - fotorama.io
============================================================ 
License: Commercial License (for commercial websites only)
see http://www.ge-webdesign.de/cmsimpleplugins/?Nutzungsbedingungen
============================================================ 
*/

initvar('multimediaslider');

if($multimediaslider)
{
	if(!defined('CMSIMPLE_VERSION'))
	{
		$o.= '<p>This plugin requires <b>CMSimple 4.2</b> or higher.</p><p><a href="http://www.cmsimple.org/">CMSimple Download & Updates &raquo;</a></p>';
		return;
	}
	
	if(defined('XH_ADM'))
	{
		$o.= '<div style="font-size: 15px; font-family: arial, sans-serif; letter-spacing: 0;">
<h4><a href="?multimediaslider">Plugin Info &raquo;</a></h4>
<p style="line-height: 1.6em;"><b>MultiMediaSlider</b>&nbsp;by&nbsp;<a href="http://www.ge-webdesign.de/cmsimpleplugins/"><u>ge-webdesign.de&nbsp;&raquo;</u></a> &nbsp; 
for&nbsp;<b>CMSimple&nbsp;4.0</b>&nbsp;or&nbsp;higher&nbsp;from&nbsp;<a href="http://www.cmsimple.org/"><u>cmsimple.org&nbsp;&raquo;</u></a></p>
</div>';
	}
	else
	{
		$o.= '<div style="font-size: 15px; font-family: arial, sans-serif; letter-spacing: 0; padding: 0 0 6px 0;">
<b><a href="?multimediaslider">Plugin Info &raquo;</a></b>
</div>
';
	}
	
	$plugin = 'multimediaslider';
	$o.= print_plugin_admin('on');
	
	if($admin=='')
	{
		$o.='
		<h4>Plugin MultiMediaSlider</h4>';
		
		$o .= '
		<div style="font-family: arial, sans-serif; font-size: 15px; letter-spacing: 0; border: 4px double; padding: 6px 16px; margin: 2px 0 8px 0;">
		<p style="text-align: center;">This Plugin is made for <a href="http://www.cmsimple.org/"><span style="font-weight: 700; padding: 0 6px; ">CMSimple 4.2 &raquo;</span></a> or higher.</p>
		<p style="text-align: center;">Optimized for <span style="font-weight: 700; padding: 0 6px; ">CMSimple 4.4</span> or higher.</p>
		<p style="text-align: center;">Recommended is the current version of CMSimple from <a href="http://www.cmsimple.org/">cmsimple.org&nbsp;&raquo;</a></p>
		</div>
		';
		
		$o.='<ul>
		<li>Version: MultiMediaSlider 1.2</li>
		<li>Released: 2022-04</li>
		<li>Copyright: Gert Ebersbach</li>
		<li>Credit: jQuery Plugin Fotorama - <a href="http://fotorama.io/">fotorama.io</a></li>
		<li>Lizenz: <a href="http://www.ge-webdesign.de/cmsimpleplugins/?Nutzungsbedingungen">Commercial License</a> for commercial websites</li>
		<li>Internet: <a href="http://www.ge-webdesign.de/cmsimpleplugins/?Eigene_Plugins">www.ge-webdesign.de</a></li>
		</ul>
		';
	}
	
	if($admin=='plugin_main')
	{
		if(file_exists($pth['folder']['templates'].'__cmsimple_backend__/template.htm'))
		{
			$pth['folder']['template'] = $pth['folder']['templates'].'__cmsimple_backend__/';
			$pth['file']['template'] = $pth['folder']['template'].'template.htm';
			$pth['file']['stylesheet'] = $pth['folder']['template'].'stylesheet.css';
			$pth['folder']['menubuttons'] = $pth['folder']['template'].'menu/';
			$pth['folder']['templateimages'] = $pth['folder']['template'].'images/';
			$cf['meta']['robots'] = 'noindex, nofollow';
		}

		$mmslDataPath = './' . $plugin_cf['multimediaslider']['path_sliders'];

		if(!is_writeable($mmslDataPath))
		{
			$o.= '<br><p style="color: #930; font-weight: 700;">Data path folder not exists.</p>
'; 
			return;
		}

		// create sliders array
		if($mmslSlidersHandle = opendir($mmslDataPath))
		{
			while($mmslSlider = readdir($mmslSlidersHandle))
			{
				if(preg_match('/\.txt/i',$mmslSlider))
				{
					$mmslSliders[] = str_replace('.txt','',$mmslSlider);
					natcasesort($mmslSliders);
				}
			}
		} 
		
		if(isset($_POST['mmslSelectedSlider']) && $_POST['mmslSelectedSlider'] != '')
		{
			unset($_SESSION['mmsl_active_slider']);
			$_SESSION['mmsl_active_slider'] = $_POST['mmslSelectedSlider'];
		}
		
		if(isset($_POST['mmslSelectedSlider']) && $_POST['mmslSelectedSlider'] == $plugin_tx['multimediaslider']['text_select_slider'])
		{
			unset($_SESSION['mmsl_active_slider']);
		}
		
		$o.='<p><b>MultiMediaSlider - ' . $plugin_tx['multimediaslider']['menu_main'] . '</b></p>';

		
/* 
#####################################
        begin backend output
##################################### 
*/

		if(!isset($_POST['mmslNewSliderFilename']) && !isset($_GET['mmslDeleteSlider']))
		{
			// slider selectbox
			if(!isset($_SESSION['mmsl_active_slider']))
			{
				$o.='<p>' . $plugin_tx['multimediaslider']['text_newslider_hint'] . '</p>' . "\n";
			}
			
			$o.='<form method="post" action="?multimediaslider&admin=plugin_main&action=plugin_text&amp;mmslSelectedSlider">' . "\n";
			$o.='<select name="mmslSelectedSlider" onchange="this.form.submit()" style="border: 2px solid #999; padding: 2px;">' . "\n";
			$o.='<option style="padding: 0 6px;">' . $plugin_tx['multimediaslider']['text_select_slider'] . '</option>' . "\n";
			
			foreach ($mmslSliders as $mmslSelectedSlider)
			{
				if(isset($_SESSION['mmsl_active_slider']) && $mmslSelectedSlider == $_SESSION['mmsl_active_slider'])
				{
					$o.='<option selected="selected" style="padding: 0 6px;" value="' . $mmslSelectedSlider . '">' . $mmslSelectedSlider . '</option>' . "\n";
				}
				else
				{
					$o.='<option style="padding: 0 6px;" value="' . $mmslSelectedSlider . '">' . $mmslSelectedSlider . '</option>' . "\n";
				}
			}
			$o.='</select>' . "\n";
			$o.='</form>' . "\n";


			// message selected slider
			if
			(
				!isset($_SESSION['mmsl_active_slider']) || 
				(isset($_POST['mmslSelectedSlider']) && $_POST['mmslSelectedSlider'] == $plugin_tx['multimediaslider']['text_select_slider']) || 
				$_SESSION['mmsl_active_slider'] == $plugin_tx['multimediaslider']['text_select_slider']
			)
			{
				$o .='<p class="mmsl_admin_no_slider_selected">' . $plugin_tx['multimediaslider']['text_noslider'] . '</p>' . "\n";
			}
			else
			{
				$o .='<p class="mmsl_admin_selected_slider">' . $plugin_tx['multimediaslider']['message_active_slider1'] . '<span style="font-size: 20px;">&nbsp;&nbsp;' . $_SESSION['mmsl_active_slider'] . '&nbsp;&nbsp;</span>' . $plugin_tx['multimediaslider']['message_active_slider2'] . '</p>' . "\n";
			}
		}
		
		$o .='<br style="clear: both;">';
		
		
		if(isset($_SESSION['mmsl_active_slider']))
		{
			if(!isset($_POST['mmslNewSliderFilename']) && !isset($_GET['mmslDeleteSlider']) && !isset($_GET['mmsl_write_data']))
			{
				// form create new gallery
				$o.= '<h4>' . $plugin_tx['multimediaslider']['headline_create_new_slider'] . '</h4>
	<p>' . $plugin_tx['multimediaslider']['text_create_new_slider'] . '</p>
	<form method="post" action="' . $sn . '?multimediaslider&admin=plugin_main&action=plugin_text&mmsl_create_slider=done">
	<p>' . $plugin_tx['multimediaslider']['text_slider_filename'] . '</p>
	<input type="text" name="mmslNewSliderFilename" style="float: left; width: 200px; font-family: arial, sans-serif; border: 1px solid #999; padding: 3px 6px;" />
	<input type="submit" class="submit" value="' . $plugin_tx['multimediaslider']['button_create_slider'] . '" />
	</form>';
			
			
				// link to delete gallery
				if($plugin_cf['multimediaslider']['allow_delete_sliders'] == 'true')
				{
					$o.= '<h4>' . $plugin_tx['multimediaslider']['headline_delete_slider'] . '</h4>
<p><a href="./?multimediaslider&admin=plugin_main&action=plugin_text&mmslDeleteSlider" onClick="return confirm(\'' . $plugin_tx['multimediaslider']['text_confirm_delete_slider1'] . ' &nbsp; &quot;' . $_SESSION['mmsl_active_slider'] . '&quot; &nbsp; ' . $plugin_tx['multimediaslider']['text_confirm_delete_slider2'] . '\')">' . $plugin_tx['multimediaslider']['text_delete_slider1'] . ' <b>"' . $_SESSION['mmsl_active_slider'] . '"</b> ' . $plugin_tx['multimediaslider']['text_delete_slider2'] . ' &raquo;</a></p>
';
				}
			}
			
			// textarea data file
			if(!isset($_REQUEST['mmsl_write_data']) && !isset($_REQUEST['mmsl_create_slider'])  && !isset($_REQUEST['mmslDeleteSlider']))
			{
				$o .='
	<hr>
	<h4>' . $plugin_tx['multimediaslider']['headline_edit_slider'] . '</h4>
	<form method="post" action="' . $sn . '?multimediaslider&admin=plugin_main&action=plugin_text&mmsl_write_data=done">' . "\n" . '
	<input type="submit" class="submit" style="margin-bottom: 12px;" value="' . $plugin_tx['multimediaslider']['button_save'] . '" /><br>
	<textarea type="text" class="mmslBackendDatafile" name="mmslActiveSlider" />' . file_get_contents('./' . $plugin_cf['multimediaslider']['path_sliders'] . $_SESSION['mmsl_active_slider'] . '.txt') . '</textarea><br>' . "\n" . '
	<input type="submit" class="submit" value="' . $plugin_tx['multimediaslider']['button_save'] . '" />
	</form>' . "\n";
			}
		}
		
		
		// link to fotorama website
		if(!isset($_REQUEST['mmsl_write_data']) && !isset($_REQUEST['mmsl_create_slider'])  && !isset($_REQUEST['mmslDeleteSlider']) && isset($_SESSION['mmsl_active_slider']))
		{
			$o .='
<p>' . $plugin_tx['multimediaslider']['text_help'] . '</p>
<p id="mmslChooseFolder"><a href="http://fotorama.io/customize/" target="_blank"><b>Fotorama Website &raquo;</b></a></p>
<hr>';





		// show active slider
			$o .='
<div style="width: 40%; min-width: 360px; float: left; padding-right: 36px;">
' . mmslider($_SESSION['mmsl_active_slider']) . '
</div>
';


		// set images folder by session

		if(is_writeable('./' . $plugin_cf['multimediaslider']['path_images']))
		{
			$dataPathPre = './';
		}
		else
		{
			$dataPathPre = $pth['folder']['base'];
		}
		
		if(!isset($_GET['mmslImagesSubfolder']))$_SESSION['mmsl_imagesFolder'] = $dataPathPre . $plugin_cf['multimediaslider']['path_images'];
		if(isset($_GET['mmslImagesSubfolder']))$_SESSION['mmsl_imagesFolder'] = $dataPathPre . $plugin_cf['multimediaslider']['path_images'] . $_GET['mmslImagesSubfolder'] . '/';

		if(isset($_GET['mmslBack'])) $_SESSION['mmsl_imagesFolder'] = $dataPathPre . $plugin_cf['multimediaslider']['path_images'];

		$mmsl_imagesFolder = $_SESSION['mmsl_imagesFolder'];

		if(substr($mmsl_imagesFolder, -1) == '/')
		{
			$mmslSlash = '';
		}
		else
		{
			$mmslSlash = '/';
		}

		$mmsl_imagesFolder = $mmsl_imagesFolder . $mmslSlash;

		if(!is_writeable($dataPathPre . $plugin_cf['multimediaslider']['path_images']))
		{
			$o.= '<br><p style="color: #930; font-size: 18px; font-weight: 700;">Images folder not exists.</p>
'; 
			return;
		}


			// create images array
			if($mmslImagesHandle = opendir($mmsl_imagesFolder))
			{
				while($mmslImage = readdir($mmslImagesHandle))
				{
					if($mmslImage != '.' && $mmslImage != '..' && strstr($mmslImage,'.') && preg_match('/\.jpg|\.jpeg|\.png|\.gif/i',$mmslImage))
					{
						$mmslImages[] = $mmslImage;
					}
				}
			}
			closedir($mmslImagesHandle);
			if(isset($mmslImages) && is_array($mmslImages) && count($mmslImages) > 0)natcasesort($mmslImages);


			// create images subfolders array
			if(!isset($_GET['mmslImagesSubfolder']))
			{
				$mmslImagesSubfolders = array();
				if($mmslImagesSubfoldersHandle = opendir($mmsl_imagesFolder))
				{
					while($mmslImagesSubfolder = readdir($mmslImagesSubfoldersHandle))
					{
						if(!strstr($mmslImagesSubfolder,'.'))
						{
							$mmslImagesSubfolders[] = $mmslImagesSubfolder;
						}
					}
				}
				closedir($mmslImagesSubfoldersHandle);
				if(isset($mmslImagesSubfolders) && is_array($mmslImagesSubfolders) && count($mmslImagesSubfolders) > 0)natcasesort($mmslImagesSubfolders);
			}

			$o.='
<div id="chooseFolder" style="width: 49%; min-width: 360px; float: left; margin: 9px 0 36px 0">
<h4>' . $plugin_tx['multimediaslider']['text_define_images_folder'] . '</h4>
';

			$o.= '<p><b>' . $plugin_tx['multimediaslider']['text_youarehere'] . '</b></p>
<p style="font-family: courier new, monospace; font-size: 16px;">' . $mmsl_imagesFolder . '</p>';

			if(isset($mmslImagesSubfolders) && is_array($mmslImagesSubfolders) && count($mmslImagesSubfolders) > 0)
			{
				$o.= '<p><b>' . $plugin_tx['multimediaslider']['text_available_subfolders'] . '</b></p>
<ul style="font-weight: 700;">';

				foreach($mmslImagesSubfolders as $mmslImagesSubfolder)
				{
					$o.= '<li><a href="?multimediaslider&admin=plugin_main&action=plugin_text&mmslImagesSubfolder=' . $mmslImagesSubfolder . '#mmslChooseFolder">' . $mmslImagesSubfolder . '/</a></li>';
				}
				$o.= '</ul>
';
			}

			// backlink to main folder
			if($_SESSION['mmsl_imagesFolder'] != $dataPathPre . $plugin_cf['multimediaslider']['path_images'])
			{
				$o.= '<p><a href="?multimediaslider&admin=plugin_main&action=plugin_text&mmslBack=mmslBack#mmslChooseFolder"><b>&laquo; ' . $plugin_tx['multimediaslider']['text_backto_mainfolder'] . '</b></a></p>';
			}

			if(isset($mmslImages) && is_array($mmslImages) && count($mmslImages) > 0)
			{
				$o.='
<p style="font-weight: 700;">' . $plugin_tx['multimediaslider']['text_available_images'] . '</p>
<p>' . $plugin_tx['multimediaslider']['text_copy_code'] . '</p>
';
			}

			$o.= '<table>';

			if(isset($mmslImages) && is_array($mmslImages) && count($mmslImages) > 0)
			{
				foreach($mmslImages as $mmslImage)
				{
					$o.= '<tr>
<td style="vertical-align: top;"><img src="' . $mmsl_imagesFolder . $mmslImage . '" style="max-width: 90px; max-height: 90px; float: left; border: 3px solid #fff;"></td>
<td style="background: #fff; font-family: courier new, monospace; border: 1px solid #ccc; padding: 6px 9px; vertical-align: top;">&lt;img src="' . $mmsl_imagesFolder . $mmslImage . '" data-caption="delete or edit" alt=""&gt;</td>
</tr>
	';
				}
			}
			else
			{
				$o.= '<tr><td style="color: #930; font-weight: 700;">' . $plugin_tx['multimediaslider']['text_no_images'] . '</td></tr>';
			}
			$o.='</table>';

			// backlink to main folder
			if($_SESSION['mmsl_imagesFolder'] != $dataPathPre . $plugin_cf['multimediaslider']['path_images'])
			{
				$o.= '<p><a href="?multimediaslider&admin=plugin_main&action=plugin_text&mmslBack=mmslBack#mmslChooseFolder"><b>&laquo; ' . $plugin_tx['multimediaslider']['text_backto_mainfolder'] . '</b></a></p>';
			}
			
			$o.='</div>
';


			// copy all images
			
			if(isset($mmslImages) && is_array($mmslImages) && count($mmslImages) > 0)
			{
				$o.= '
<p style="clear: both; font-weight: 700;">' . $plugin_tx['multimediaslider']['text_copy_code_all_images'] . '</p>
<div style="clear: both; background: #fff; font-family: courier new, monospace; border: 1px solid #ccc; padding: 20px 20px 6px 20px;">
';

			
			
				foreach($mmslImages as $mmslImage)
				{
					$o.= '
&lt;img src="' . $mmsl_imagesFolder . $mmslImage . '" data-caption="delete or edit" alt=""&gt;
<br>
<br>
';
				}
			
			
				$o.= '</div>';
			}
		}
/* 
#####################################
          write data file
##################################### 
*/

		if(isset($_POST['mmslActiveSlider']))
		{
			if(!is_writeable($mmslDataPath . $_SESSION['mmsl_active_slider'] . '.txt'))
			{
				die('<p>The file</p><p style="font-family: courier new, monospace; font-weight: 700;">' . $mmslDataPath . $_SESSION['mmsl_active_slider'] . '.txt' . '</p><p>is not writeable, please check the writing permissions of the file.</p>');
			}
			else
			{
				$mmslDataFile = fopen($mmslDataPath . $_SESSION['mmsl_active_slider'] . '.txt', 'w+');
				ftruncate($mmslDataFile, 0);
				$mmslDatafileContent=$_POST['mmslActiveSlider'];
				fwrite($mmslDataFile, $mmslDatafileContent);
				fclose($mmslDataFile);
			}
		}
		
		
/* 
#####################################
     create and delete sliders
##################################### 
*/
		
		if(isset($_GET['mmsl_create_slider']) && isset($_POST['mmslNewSliderFilename']) && $_POST['mmslNewSliderFilename'] != '')
		{
			copy($mmslDataPath . $_SESSION['mmsl_active_slider'] . '.txt',$mmslDataPath . $_POST['mmslNewSliderFilename'] . '.txt');
			chmod($mmslDataPath . $_POST['mmslNewSliderFilename'] . '.txt', 0666);
		}
		
		if(isset($_GET['mmslDeleteSlider']))
		{
			unlink($mmslDataPath . $_SESSION['mmsl_active_slider'] . '.txt');
			unset($_SESSION['mmsl_active_slider']);
		}
		
		
/* 
#####################################
     success messages
##################################### 
*/

		// success message updated data
		if(isset($_REQUEST['mmsl_write_data']) && $_REQUEST['mmsl_write_data'] == 'done')
		{
			$o.= '<p class="cmsimplecore_warning" style="text-align: center; font-weight: 700; line-height: 2em;">' . $plugin_tx['multimediaslider']['message_updated'] . '</p><br />';
			$o.= '<p style="text-align: center;">
<a href="./?multimediaslider&admin=plugin_main&action=plugin_text">' . $plugin_tx['multimediaslider']['message_back_mainfuncs'] . '</a></p>
<p style="text-align: center;">
';
		}
		
		// success message created slider
		if(isset($_REQUEST['mmsl_create_slider']) && $_REQUEST['mmsl_create_slider'] == 'done')
		{
			if(isset($_POST['mmslNewSliderFilename']) && $_POST['mmslNewSliderFilename'] != '')
			{
				$o.= '<p class="cmsimplecore_warning" style="text-align: center; font-weight: 700; line-height: 2em;">' . $plugin_tx['multimediaslider']['message_slider_created'] . '</p><br />';
				$o.= '<p style="text-align: center;">
<a href="./?multimediaslider&admin=plugin_main&action=plugin_text">' . $plugin_tx['multimediaslider']['message_back_mainfuncs'] . '</a></p>
<p style="text-align: center;">
';
			$_SESSION['mmsl_active_slider'] = $_POST['mmslNewSliderFilename'];
			}
			else
			{
				$o.= '<p class="cmsimplecore_warning" style="text-align: center; font-weight: 700; line-height: 2em;">' . $plugin_tx['multimediaslider']['message_no_slider_created'] . '</p><br />';
				$o.= '<p style="text-align: center;">
<a href="./?multimediaslider&admin=plugin_main&action=plugin_text">' . $plugin_tx['multimediaslider']['message_back_mainfuncs'] . '</a></p>
<p style="text-align: center;">
';
			}
		}
		
		// success message dleted slider
		if(isset($_REQUEST['mmslDeleteSlider']))
		{
			$o.= '<p class="cmsimplecore_warning" style="text-align: center; font-weight: 700; line-height: 2em;">' . $plugin_tx['multimediaslider']['message_slider_deleted'] . '</p><br />';
			$o.= '<p style="text-align: center;">
<a href="./?multimediaslider&admin=plugin_main&action=plugin_text">' . $plugin_tx['multimediaslider']['message_back_mainfuncs'] . '</a></p>
<p style="text-align: center;">
';
		}
	}

	if ($admin <> 'plugin_main') 
	{
		$hint=array();
		$hint['mode_donotshowvarnames'] = false;
		$o.=plugin_admin_common($action, $admin, $plugin, $hint);
	}
}

?>