<?php 
	require_once('Connections/conn_ama.php');

	if(!isset($_SESSION)){
        session_start();
    } 

 ?>

<!-- <div class="col-md-9 data-area"> -->
	<div class="data-area-wrap">
		<div class="form-wrapper">
			<form id="new-news-text" method="post">
			  	<fieldset>
			  	<legend>News Upload: <?php //print_r($_SESSION); ?></legend>
			  		<div class="form-group">
					    <label for="headline">Headline</label>
					    <input type="text" name="headline" class="form-control" id="headline" >
				  	</div>

				  	<div class="form-group">
					    <label for="gist">Gist</label>
					    <input type="text" name="gist" class="form-control" id="gist" >
				  	</div>

				  	<div class="form-group">
					    <label for="newsupload">News Content</label>
					  <textarea name="content" class="tinymce"  id="newsupload"></textarea>
				  	</div>
			  	</fieldset>
				<hr>
			  <button type="submit" id="news-text" class="btn btn-success">Submit</button>
			  <input type="hidden" name="MM_insert" value="save-news-text" />
			  <div class="error_msg"></div>
			</form>
		</div><!-- End .form-wrapper-->
	</div><!-- End .data-area-wrap-->	
<!-- </div>End .data-area -->



<script type="text/javascript" src="_/js/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="_/js/tinymce/jquery.tinymce.min.js"></script>
        
        
                
<!-- TinyMCE -->
        
            
	<script type="text/javascript">
		$(function(){
			tinymce.init({
			selector: 'textarea#newsupload',
			plugins: 'print preview paste importcss searchreplace autolink autosave save directionality code visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount imagetools textpattern noneditable help charmap quickbars emoticons',
				imagetools_cors_hosts: ['picsum.photos'],
				menubar: 'file edit view insert format tools table help',
				toolbar: 'undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent |  numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen  preview save print | insertfile image media template link anchor codesample | ltr rtl',
				toolbar_sticky: true,
				autosave_ask_before_unload: true,
				autosave_interval: "30s",
				autosave_prefix: "{path}{query}-{id}-",
				autosave_restore_when_empty: false,
				autosave_retention: "2m",
				image_advtab: true,
				content_css: '//www.tiny.cloud/css/codepen.min.css',
				link_list: [
					{ title: 'My page 1', value: 'http://www.tinymce.com' },
					{ title: 'My page 2', value: 'http://www.moxiecode.com' }
				],
				image_list: [
					{ title: 'My page 1', value: 'http://www.tinymce.com' },
					{ title: 'My page 2', value: 'http://www.moxiecode.com' }
				],
				image_class_list: [
					{ title: 'None', value: '' },
					{ title: 'Some class', value: 'class-name' }
				],
				importcss_append: true,
				file_picker_callback: function (callback, value, meta) {
					/* Provide file and text for the link dialog */
					if (meta.filetype === 'file') {
					callback('https://www.google.com/logos/google.jpg', { text: 'My text' });
					}

					/* Provide image and alt text for the image dialog */
					if (meta.filetype === 'image') {
					callback('https://www.google.com/logos/google.jpg', { alt: 'My alt text' });
					}

					/* Provide alternative source and posted for the media dialog */
					if (meta.filetype === 'media') {
					callback('movie.mp4', { source2: 'alt.ogg', poster: 'https://www.google.com/logos/google.jpg' });
					}
				},
				templates: [
						{ title: 'New Table', description: 'creates a new table', content: '<div class="mceTmpl"><table width="98%%"  border="0" cellspacing="0" cellpadding="0"><tr><th scope="col"> </th><th scope="col"> </th></tr><tr><td> </td><td> </td></tr></table></div>' },
					{ title: 'Starting my story', description: 'A cure for writers block', content: 'Once upon a time...' },
					{ title: 'New list with dates', description: 'New List with dates', content: '<div class="mceTmpl"><span class="cdate">cdate</span><br /><span class="mdate">mdate</span><h2>My List</h2><ul><li></li><li></li></ul></div>' }
				],
				template_cdate_format: '[Date Created (CDATE): %m/%d/%Y : %H:%M:%S]',
				template_mdate_format: '[Date Modified (MDATE): %m/%d/%Y : %H:%M:%S]',
				height: 600,
				image_caption: true,
				quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
				noneditable_noneditable_class: "mceNonEditable",
				toolbar_mode: 'sliding',
				contextmenu: "link image imagetools table"

			});
		});
	</script>
<!-- /TinyMCE -->

<script>
	$(document).on('click','.delete-btn',function(e){
		e.preventDefault();
				
		//alert("form");
		//$(this).parent('div').fadeOut();
		//$(this).parent('div').remove();
		$(this).parent('div').fadeOut(650,function(){
			$(this).remove();
		});
				
	});

	$(".fileUpload").on('change', function () {
		//alert("askfljsd");
		//Get count of selected files
		var countFiles = $(this)[0].files.length;

		var imgPath = $(this)[0].value;
		var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
		var image_holder = $("#image-holder");
		image_holder.empty();

		if (extn == "gif" || extn == "png" || extn == "jpg" || extn == "jpeg") {
			if (typeof (FileReader) != "undefined") {

				//loop for each file selected for uploaded.
				for (var i = 0; i < countFiles; i++) {

					var reader = new FileReader();
					reader.onload = function (e) {
						$("<img />", {
							"src": e.target.result,
								"class": "thumb-image img-fluid"
						}).appendTo(image_holder);
					}

					image_holder.show();
					reader.readAsDataURL($(this)[0].files[i]);
				}

			} else {
				alert("This browser does not support FileReader.");
			}
		} else {
			alert("Pls select only images");
		}
	});	
</script> 
