<?php
     error_reporting(E_ALL);
	include_once (CHEMIN_ABS.CHEMIN_DU_SITE.'lib_partage/lib.image.php');
	include_once ('include/lib/lib.xmedia.php');
	$get_src= ( (isset($_GET['src']))AND (file_exists($_GET['src'])) ) ? $_GET['src'] : null ;
	$current_dir= (isset($_GET['dir'])) ? $_GET['dir'] : REP_IMG ; //'../img' ;
	$env= (isset($_GET['env'])) ? $_GET['env'] : '' ;
	$mode= (isset($_GET['mode'])) ? $_GET['mode'] : '' ;
	$thumb='';
	$le_get_file_original=(isset($_GET['file']))? $_GET['file'] : '';
	$reduction= (isset($_POST['reduc']))? $_POST['reduc']: 'perso' ;
	$lefile=eregi_replace("(.*/)*|".REP_IMG."",'',$le_get_file_original);
	$ledir=eregi_replace('\.\./|'.REP_IMG.'|mini/|thumb/|'.$lefile,'',$le_get_file_original);
	$get_file=str_replace('../','',$le_get_file_original);
	$alignment=(isset($_POST['alignment'])) ? $alignment : '';

	/* Gestion taille image affiaché  */

	if (!isset($_POST['reduc'])){
	/* Original */
		$rel_path_img_apercu=(!eregi("^\.\./",$le_get_file_original)) ?'../'.$le_get_file_original :$le_get_file_original ;
		$mode_reduc='reel';
	}elseif ( (isset($_POST['reduc']))){
		if ($_POST['reduc'] =='reel'){
		/* Original */
			@unlink(ADD_PATH_ADMIN.REP_IMG.'thumb/'.md5(REP_IMG.$ledir.$lefile).'.jpg');
			$rel_path_img_apercu=(!eregi("^\.\./",$le_get_file_original)) ?'../'.$le_get_file_original :$le_get_file_original ;
			$mode_reduc='reel';
		}elseif ($_POST['reduc'] =='mini'){
		/* Appel element mini defini par new image via user*/
			@unlink(ADD_PATH_ADMIN.REP_IMG.'thumb/'.md5(REP_IMG.$ledir.$lefile).'.jpg');
			$rel_path_img_apercu=(!eregi("^\.\./",$le_get_file_original)) ?'../'.$le_get_file_original :$le_get_file_original ;
			$mode_reduc='mini';
			$thumb='mini/';
		}elseif ($_POST['reduc'] =='perso'){
		/* Taille defini , perso */
// 			$rel_path_img_apercu=(!eregi("^\.\./",$_GET['file'])) ?'../'.$_GET['file'] :$_GET['file'] ;
			$mode_reduc='perso';
			$thumb='thumb/';
			if (!isset($_POST['width'])||empty($_POST['width'])) { $_POST['width']='100'; $_POST['height']='100'; }
			$rel_path_img_apercu=$get_src=creat_img_mini($ledir, $lefile, '', $_POST['width'], $_POST['height']);
			sleep(2);
		}elseif  ($_POST['reduc'] =='100'||$_POST['reduc'] =='300') {
			$mode_reduc=$_POST['reduc'];
			$thumb='thumb/';
			$rel_path_img_apercu=$get_src=creat_img_mini($ledir, $lefile, '', $_POST['reduc'], $_POST['reduc']);
			sleep(2);
		}
	}

	$get_image=str_replace('../','',$rel_path_img_apercu);

	/* Retoru de la taille de l'image */
	eregi ("(.*".REP_IMG.$thumb.")([a-z0-9/_-]*)([a-z0-9_-]*\.[a-z0-9]{3,4})",$rel_path_img_apercu,$regs);
	$siz=size_img(true,false,REP_IMG.$thumb.$regs[2],$regs[3],true);
	$get_width=$siz[0];
	$get_height=$siz[1];

	/*  Option  da'garndissmeent dans l'espace publics par default :lightwindow (present dans sythem) si actif sinon pas agrandissement */
	if (!isset($_POST['lightetc'])) {
		$aff_box_view=$light_view='';
	}else {
		if ($_POST['lightetc']=='lightbox')  $light_view = ' rel="lightbox" ';
		elseif ($_POST['lightetc']=='lightwindow') $light_view = ' class="lightwindow" ';
		else $light_view = ' class="'.$_POST['lightetc'].'" ';

		$aff_box_view=$_POST['lightetc'];
	}
	?>
<script language="JavaScript" type="text/javascript">

function verif (leform) {
if (document.getElementById('') !='') document.leform.submit();
else {
	alert ('le champs text alternatif est obligatoire');
	return false;
}
}


var qsParm = new Array();


/* ---------------------------------------------------------------------- *\
  Function    : retrieveWYSIWYG()
  Description : Retrieves the textarea ID for which the image will be inserted into.
\* ---------------------------------------------------------------------- */
function retrieveWYSIWYG() {
  var query = window.location.search.substring(1);
  var parms = query.split('&');
  for (var i=0; i<parms.length; i++) {
    var pos = parms[i].indexOf('=');
    if (pos > 0) {
       var key = parms[i].substring(0,pos);
       var val = parms[i].substring(pos+1);
       qsParm[key] = val;
    }
  }
}


/* ---------------------------------------------------------------------- *\
  Function    : insertImage()
  Description : Inserts image into the WYSIWYG.
\* ---------------------------------------------------------------------- */
function insertImage() {
<?php if (!empty($light_view)): ?>
  	var image = '<a href="<?php print URL_DU_SITE ?>' + document.getElementById('imageurl').value + '" <?php print $light_view ?>><img src="<?php print URL_DU_SITE ?>' + document.getElementById('imageurl1').value + '"  alt="' + document.getElementById('alt').value + '" align="<?php echo $alignment ?>" border="' + escape(document.getElementById('borderThickness').value) + '" hspace="' + document.getElementById('width').value + '" vspace="' + document.getElementById('height').value + '" style="width:' + document.getElementById('width').value + '; height:' + document.getElementById('height').value + '; margin:5px;"></img></a>';
<?php else: ?>
	content=document.getElementById('imageurl1').value
	var motif_div_d = /.+\./gi ;
	content = content.replace(motif_div_d,"");
	if (content=='zip') {
  		var image = '<a href="<?php print URL_DU_SITE ?>' + document.getElementById('imageurl1').value + '" style=" text-align: <?php echo $alignment ?>; ">';

		if (document.getElementById('icone').value !='') image = image + '<img src="'+document.getElementById('icone').value+'" alt="icon zip" align="<?php echo $alignment ?>"  style=" margin:5px;"></img>';
		image = image + document.getElementById('alt').value + '</a>';

	}
	else if (content=='pdf') {
		url_p=document.getElementById('imageurl1').value
		var motif_div_d = /\.\.\/|img\//gi ;
		url_p = url_p.replace(motif_div_d,"");

	  	var image = '<a href="' + url_p + '" style=" text-align: <?php echo $alignment ?>; ">';

		if (document.getElementById('icone').value !='') image = image + '<img src="'+document.getElementById('icone').value+'" alt="icon pdf" align="<?php echo $alignment ?>"  style=" margin:5px;"></img>' ;
		image = image + document.getElementById('alt').value + '</a>';

	} else {
		var image = '<img src="<?php print URL_DU_SITE ?>' + document.getElementById('imageurl1').value + '" <?php print $light_view ?> alt="' + document.getElementById('alt').value + '" align="<?php echo $alignment ?>" border="' + document.getElementById('borderThickness').value + '" hspace="' + document.getElementById('width').value + '" vspace="' + document.getElementById('height').value + '" style="width:' + document.getElementById('width').value + '; height:' + document.getElementById('height').value + '; margin:5px;"></img>';
	}

<?php endif; ?>


  //   window.opener.insertHTML(image, qsParm['wysiwyg']);
  window.parent.insertHTML(image, 'message');
}

</script>
<form name="edit_form" method="post" action="<?php print $_SERVER['PHP_SELF']."?nav=xmedia_edit&amp;file=".$get_file."&amp;src=".$get_src."&amp;width=".$get_width."&amp;height=".$get_height."&amp;dir=".$current_dir."" ?>" >
<div id="structure">
	<div id='header'></div>
	<div='ssheader'><?php if ($px_gd_version==0) print "<p class='erreur'>".LIB_GD_ABSENTE."</p>"; ?></div>
	<div id="main_pop">
		<div id="content">
		<br /><br />
		<?php

		echo "<h1> ".FILE_IMAGES_MEDIA." </h1>\n\n";
		if(!isset($_GET['file'])) {
			echo '<p class="info">'.NO_MEDIA_DELECT.'</p>';
		}

		$ext=eregi_replace("^.*\.",'',@$_GET['file']);
		if ($ext=='pdf'): ?>
			<table class="option_reglable">
			  <tr><th colspan='2'><?php print  'Fichier Pdf' ?></th></tr>
			 <tr>
			  <td width="80"><?php print INSERT_URL; ?></td>
				<td width="300"><input style="width:50%;" type="text" name="imageurl" id="imageurl" value="<?php print $le_get_file_original; ?>"  ><input type="hidden" name="imageurl1" id="imageurl1" value="<?php print str_replace('../','',$get_image); ?>"  ></td>
			 </tr>
			 <tr>
			  <td><?php print /*INSERT_ALT*/'Titre au survol '; ?></td>
				<td><input style="width:50%;" type="text" name="alt" id="alt" value="<?php if (tep_not_null(@$_POST['alt'])) print $_POST['alt']; else print 'pdf'; ?>"  ></td>
			 </tr>
	<!--		  <tr>
			  <td><?php //print 'Forcer le lien en téléchargement'; ?></td>
				<td><input type="checkbox" name="download" id="download" value="download"  ></td>
			 </tr>-->
			   <tr>
			  <td><?php print 'Ajouter icone (url) sinon laisser vide'; ?></td>
				<td><input style="width:50%;" type="text" name="icone" id="icone" value="" onclick="this.value='<?php echo URL_DU_SITE."template/".NOM_DU_THEME."/img/icon_pdf.png" ?>'"  ></td>
			 </tr>
			</table>

		<?php elseif($ext=='zip'): ?>

		<?php else: ?>

		<table class="option_reglable">
		  <tr><th colspan='2'><?php print  TAILLE_IMG ?></th></tr>
		 <tr>
		  <td width="80"><?php print INSERT_URL; ?></td>
			<td width="300"><input type="text" name="imageurl" id="imageurl" value="<?php print $le_get_file_original; ?>"  ><input type="hidden" name="imageurl1" id="imageurl1" value="<?php print str_replace('../','',$get_image); ?>"  ></td>
		 </tr>
		 <tr>
		  <td><?php print INSERT_ALT; ?></td>
			<td><input type="text" name="alt" id="alt" value="<?php if (tep_not_null(@$_POST['alt'])) print $_POST['alt']; else print 'image'; ?>"  ></td>
		 </tr>
		</table>
		<table class="option_reglable">
		 <tr><th colspan='2'><?php print  DEF_IMG_DEFAULT ?></th></tr>
		 <tr>
		  <td width="80" colspan='2'>	<?php
			     $t=array("x100"=>"100","x300"=>"300",/*"minitature"=>"mini",*/"original"=>"reel","personnalisé"=>"perso");
			     $f="  %3\$s <input class=\"radio\"  type='radio' name='reduc' value='%1\$s' %4\$s  %2\$s  style=\"font-size: 10px; width: 95%;\"/> &nbsp;&nbsp; ";
			     while ($r=each($t))
			     		if ($r['value']==$mode_reduc)printf($f,$r['value']," checked ",$r['key'],'');
					else printf($f,$r['value'],'',$r['key']," Onclick='document.edit_form.submit()' ");
			     ?></td>
		 </tr>
		</table>
		<table class="option_reglable">
		  <tr><th colspan='2'><?php print  DEF_IMG_AGRANDISSEMENT?></th></tr>
		 <tr>
		  <td width="80" colspan='2'>
				<select name="lightetc" Onchange="document.edit_form.submit()" style="font-size: 10px; width: 95%;">
					<option value="aucun"><?php print AGRANDISS_LIGHT ?></option>
 			  <?php
				if (defined('PX_CONFIG_MODULE_LIGHTWINDOW')){
					if ($aff_box_view=='lightwindow') print ' <option value="lightwindow" selected>lightwindow </option> ';
					else  print ' <option value="lightwindow" >lightwindow </option> ';
					}
				 if (defined('PX_CONFIG_MODULE_LIGHTBOX')){
				 	if ($aff_box_view=='lightbox') print ' <option value="lightbox" selected>lightbox </option> ';
					else  print ' <option value="lightbox" >lightbox </option> ';
					}
					?>
			  </select>
		  </td>
		 </tr>
		</table>
		<table class="option_reglable_dbl">
			 <tr><th colspan='2'><?php print LAYOUT; ?></th></tr>
		 <tr>
		  <td width="60"><?php print ALIGNMENT; ?></td>
			<td  >
			<select name="alignment" id="alignment" style="font-family: arial, verdana, helvetica; font-size: 11px; width: 95%;"  Onchange="document.edit_form.submit()">
			 <option value="" <?php if ($alignment=='') echo 'selected'?> ><?php print ALIGNMENT_NULL ?></option>
			 <option value="left" <?php if ($alignment=='left') echo 'selected'?> ><?php print ALIGNMENT_LEFT ?></option>
			 <option value="right" <?php if ($alignment=='right') echo 'selected'?> ><?php print ALIGNMENT_RIGHT ?></option>
			 <option value="bottom" <?php if ($alignment=='bottom') echo 'selected'?> ><?php print ALIGNMENT_BOTTOM ?></option>
			</select>
			</td>
		 </tr>
		 <tr>
		  <td ><?php print BORDURE; ?></td>
			<td ><input type="text" name="borderThickness" id="borderThickness" value="<?php echo @$_POST['borderThickness'] ?>"   Onblur='document.edit_form.submit()'></td>
		 </tr>
		</table>
		<table class="option_reglable_dbl" style="<?php if ($mode_reduc=='perso') echo 'border:2px solid #de7d0f;'?>" >
		 <tr><th colspan='2'><?php print TAILLE_IMG; ?></th></tr>
		 <tr>
		  <td  width="60"><?php print HORIZONTAL; ?></td>
			<td  ><input type="text" name="width" id="width" value="<?php print $get_width; ?>"   <?php if ($mode_reduc!='perso') echo 'disabled'?>></td>
		 </tr>
		 <tr>
		  <td ><?php print VERTICAL; ?></td>
			<td ><input type="text" name="height" id="height" value="<?php print $get_height; ?>"   <?php if ($mode_reduc!='perso') echo 'disabled'?> ></td>
		 </tr>
		 <tr>
		  <td colspan='2'><input type="button"  value="Changer la taille"  Onclick='document.edit_form.submit()' style="<?php if ($mode_reduc!='perso') echo 'display:none' ?>" ></td>
		 </tr>
		</table>

		<?php endif;?>

		<div class="nav"><input class="bouton" id="insert_img" type="submit" value="<?php print INSERT_IMAGE_IN_DOC; ?>" onClick="insertImage();" class="lightwindow_action" rel="deactivate" style="font-size: 12px;" ></div>
		<div id="apercu_img" >
			<h3><?php print APERCU ;  ?> <a id="view_t" href="#js" onclick="cache('view_t');cache('sstexte');montre('texte');montre('view_sst');" >Avec texte</a> <a id="view_sst" href="#js" onclick="cache('view_sst');cache('texte');montre('view_t');montre('sstexte')" style="display:none;">Sans texte</a></h3>
<!-- 			Block avec text pour apercu -->
			<div id='texte' style="display:none;">milium. nam ex hoc quoque sexu peremptae sunt originis altae conplures, adulteriorum flagitiis obnoxiae vel stuprorum. inter quas notiores fuere Claritas et Flaviana, quarum altera cum duceretur ad mortem, indumento, quo vestita erat, abrepto, ne velemen quidem secreto membrorum sufficiens retinere permissa est. ideoque carnifex nefas admisisse convictus inmane, vivus exustus est.Verum ad istam omnem orationem brevis est defensio. Nam quoad aetas M. Caeli dare potuit isti suspicioni locum, fuit primum ipsius pudore, deinde etiam patris diligentia disciplinaque munita. Qui ut huic virilem togam <img src="<?php echo $rel_path_img_apercu ?>" alt="IMG" align="<?php echo @$alignment  ?>" style="<?php if (tep_not_null(@$_POST['borderThickness'])) echo 'border:'.@$_POST['borderThickness'] ;?>"/> deditšnihil dicam hoc loco de me; tantum sit, quantum vos existimatis; hoc dicam, hunc a patre continuo ad me esse deductum; nemo hunc M. Caelium in illo aetatis flore vidit nisi aut cum patre aut mecum aut in M. Crassi castissima domo, cum artibus honestissimis erudiretur.Erat autem diritatis eius hoc quoque indicium nec obscurum nec latens, quod ludicris cruentis delectabatur et in circo sex vel septem aliquotiens vetitis certaminibus pugilum vicissim se concidentium perfusorumque sanguine specie ut lucratus ingentia laetabatur.Nihil est enim virtute amabilius, nihil quod magis adliciat ad diligendum, quippe cum propter virtutem et</div>
<!-- 			Block sans texte -->
			<div id='sstexte' ><img src="<?php echo $rel_path_img_apercu ?>" alt="IMG" align="<?php echo $alignment ?>" style="<?php if (tep_not_null(@$_POST['borderThickness'])) echo 'border:'.@$_POST['borderThickness'] ;?>"/></div>
		</div>
		</div>
	</div>
</form>
		<div id="bulle"></div> <!--TOOLIP-->
	<div id="retour_ajax" style="display:none;">
		<p id='retour_ajax_txt'></p>
		<p id='retour_ajax_nav'></p>
		<p id='retour_ajax_help'>Cliquez dessus pour fermer</p>
	</div> <!-- RETOUR AJAX -->
	<script src="include/js/application.js" type="text/javascript"></script>
<!-- 	<script type='text/javascript'> -->
<!-- // 		window.onload=init; -->
<!-- 	</script> -->