<?php
// Set flag that this is a parent file
	defined('_FEXEC') or die();
//mode 1 === edit,delete,test
//mode 4=== edit,delete,send
//mode 2 ==send
//mode 5 == edit,delete

 function tep_get_message_details($message_array,$message_type_array,$fields_type,$display_type,$type_id)
{
	global $mes_array,$format_array,$fields_details,$submit_pagename,$alert_message;
	switch($display_type)
	{
		case "P": //products
		case "EM": //email messages
		case "W": //wallet
			$sql_query="SELECT message_id,message_reply_to,message_type,message_send,message_subject,message_text,message_format from " . TABLE_EMAIL_MESSAGES . " where 1=1 ";
			break;
		case "E": //events
			$sql_query="SELECT events_message_id as message_id,message_reply_to,message_type,message_send,message_subject,message_text from " . TABLE_EVENTS_MESSAGES . " where events_id='" . $type_id ."'";
			break;
		case "SE": //sms events
			$sql_query="SELECT events_sms_message_id as message_id,message_type,message_send,message_subject,message_text from " . TABLE_EVENTS_SMS_MESSAGES . " where events_id='" .  $type_id ."'";
			break;
		case "S": //subscriptions
			$sql_query="SELECT subscription_message_id as message_id,message_type,message_send,message_send1,message_subject,message_reply_to,message_text,message_format from " . TABLE_SUBSCRIPTION_MESSAGES . " where subscription_id='" . $type_id . "'";
			break;
		case "SS": //sms subscription
			$sql_query="SELECT subscription_sms_message_id as message_id,message_type,message_send,message_subject,message_text from " . TABLE_SUBSCRIPTION_SMS_MESSAGES . " where subscription_id='" . $type_id . "'";
			break;
		case "V": //services
			$sql_query="SELECT services_message_id as message_id,message_type,message_send,message_send1,message_subject,message_reply_to,message_text,message_format from " . TABLE_SERVICES_MESSAGES . " where service_id='" . $type_id . "'";
			break;
		case "SV": //sms services
			$sql_query="SELECT services_sms_message_id as message_id,message_type,message_send,message_send1,message_subject,message_text from " . TABLE_SERVICES_SMS_MESSAGES . " where service_id='" . $type_id . "'";
			break;
	}
	$message_type_query=tep_db_query($sql_query . " and message_type='" . $message_array['id'] . "'");
	$result_cnt=tep_db_num_rows($message_type_query);
	$result=tep_db_fetch_array($message_type_query);
	if ($result_cnt>0){
		$mesInfo=new objectInfo($result);
		if($display_type=="V" || $display_type=="SV")
		{
			$symbol_date='';
			$symbol_time='';
			if(tep_not_null($result['message_send'])){
				$symbol_date=substr($result['message_send'],0,1);
			}	
			if(tep_not_null($result['message_send1'])){
				$symbol_time=substr($result['message_send1'],0,1);	
			}	
			if($symbol_date=="-")
				$send_email_date="B";
			elseif($symbol_date=="+")
				$send_email_date="A";
			if($symbol_time=="-")
				$send_email_time="B";
			elseif($symbol_time=="+")
				$send_email_time="A";
		}
		$new_action="update_message";	
	} else{
		$mesInfo=new objectInfo($mes_array);
		$mesInfo->message_type=$message_array['id'];
		$mesInfo->message_id='';
		$new_action="insert_message";
	}
	if($result_cnt<=0)
		echo "new_message{}";
	else
		echo "edit_message{}";
		echo $message_array['mode'];?>
	<Table width="100%" cellpadding="0" border="0" cellspacing="0" class="openContent">
	<tr><td ><Table width=100% align="center" border="0" cellpadding="0" cellspacing="0">
	<?php if($alert_message!=""){?>
		<tr><td class="smallText" style="color:#003399" ><?php echo tep_image('images/icons/success.gif') . ' ' . $alert_message;?></td></tr>
		<tr><td height="10"></td></tr>
	<?php }
	
	if ($message_array['mode']==1 || $message_array['mode']==4 || $message_array['mode']==5 ){
		if ($result_cnt<=0){?>
		  <tr class="contentTitle" >
			<td  colspan="2" class="smallText" style="color:#000000;margin-left:10px;"><?php echo $message_array['text']; ?></td>
			<td align="center" colspan="2">
			  <?php //echo '<a href="javascript:show_edit();">' . tep_image('images/icons/message_blue.gif',IMAGE_ADD_MESSAGE) . "</a>";?>
			  <?php /*  echo'
					<table border="0" cellpadding="0" cellspacing="0" style="width:100;height:20;display:inline;position:relative;top:0px;">
						<tr>
							<td width="10" class="cell_bg_popm_left">&nbsp;</td>
							<td width="70" align="center" style="background:#DEE4F5;"><a href="javascript:show_edit();" MouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);">' . tep_image('images/icons/message_blue.gif',IMAGE_ADD_MESSAGE) . '</a>
							</td>
							<td width="10" class="cell_bg_popm_right">&nbsp;</td>
						</tr>
					</table>
					';*/ ?>
			</td>
			<td id="show_edit" <?php if ($result_cnt>=1){?>style="display:none"<?php }?>>
			<?php
				echo '<a href="javascript:do_submit(\'' . $new_action  . '\',\'' . $mesInfo->message_id . '\',\''  . $type_id . '\')">' . tep_image('images/icons/edit_green.gif','Save') . "</a>&nbsp;";
				echo '&nbsp;<a href="javascript:close_edit();">' . tep_image('images/icons/cancel.gif','Close') . "</a>";
			?>
			</td>
		  </tr>
		<?php }else{?>
		<tr class="contentTitle" >
			<td width="350" class="inner_title" ><?php echo $message_array['text'];?></td>
			<td align="center" nowrap="nowrap">
			<?php  echo ' 
		<table border="0" cellpadding="0" cellspacing="0" style="cursor:pointer;width:100;height:30;display:inline;position:relative;top:5px;">
			<tr id="img_ids">
				<td width="15" class="cell_bg_popm_left">&nbsp;</td>
				<td align="center" style="background:#DEE4F5;">';
			//echo '<a href="javascript:show_edit();">' . tep_image('images/icons/edit_blue.gif',IMAGE_MODIFY_MESSAGE) . "</a>&nbsp;&nbsp;&nbsp;";
			echo '<td style="background:#DEE4F5;" width="15" OnClick="javascript:do_hover_change(this,1);show_edit();" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);">' . tep_image(DIR_WS_IMAGES.'template/img_edit.gif',IMAGE_MODIFY_MESSAGE) . "</td>";
			echo '<td style="background:#DEE4F5;" width="15" OnClick="javascript:do_hover_change(this,1);do_delete(\'' . $result['message_id'] . '\',\'' . $type_id . '\',\''. $result["message_type"] . '\');" onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,3);">' . tep_image(DIR_WS_IMAGES.'template/img_trash.gif',IMAGE_DELETE_MESSAGE) . "</td>";
			if ($message_array['mode']==4 && $display_type=='P')
			{
				echo '<td style="background:#DEE4F5;" width="15"><a href="javascript:send_message(\'' .  $message_array['id'] . '\');">' . tep_image('images/icons/unread.gif',IMAGE_SEND_ALL_CUSTOMERS) . "</a></td>";
			}
			  if ($message_array['mode']==1){
				echo '<td style="background:#DEE4F5;" width="15"><a  href="javascript:do_test_send(\'' . $message_array['id'] . '\',\'' . $type_id .'\');">' . tep_image('images/icons/mail.gif',IMAGE_TEST_MAIL) . "</a>";
					echo '  </td>';

			  }
			echo '  <td width="15" class="cell_bg_popm_right">&nbsp;</td> <td>&nbsp;';
							if(is_array($message_type_array))
				{
					echo tep_draw_form('message_type',$submit_pagename);
					echo tep_draw_hidden_field('id',$result['message_id']);
					echo tep_draw_hidden_field('msg_type',$result['message_type']);
					echo tep_draw_pull_down_menu('message_send',$message_type_array,$result['message_send'],' onchange="javascript:do_change_send(\'' . $type_id . '\');"');
					if ($message_array['id']=='RSR' && ($display_type=='SE' || $display_type=='SV') ) echo '&nbsp;' . TEXT_INFO_START_REMINDER;
					echo '</form>';
					
				}

					echo '</td>	</tr></table>';?>
			</td>
			<td width="250" align="right"><span id="show_edit" style="visibility:hidden">
			<?php
				echo '<a href="javascript:do_submit(\'' . $new_action  . '\',\'' . $mesInfo->message_id . '\',\''  . $type_id . '\')">' . tep_image('images/icons/edit_green.gif','Save') . "</a>&nbsp;";
				echo '&nbsp;<a href="javascript:close_edit();">' . tep_image('images/icons/cancel.gif','Close') . "</a>";
			?></span>
			</td>
		 </tr>
		 <div style="display:none" class="main" id="edit_message"></div>
		 <div style="display:none" class="main" id="delete_message"></div>
		<tr  id="show_read_only">
				<Td colspan="3">
					<table width="100%" border="0">
					<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
					<tr>
						<td>
							<table border="0" width="100%" cellspacing="0" cellpadding="2">
								<tr>
									<td class="smallText"><?php echo tep_db_prepare_input(sprintf(TEXT_MAIL_FROM,STORE_OWNER,STORE_OWNER_EMAIL_ADDRESS)); ?></td>
								</tr>
								<tr>
									<td class="smallText"><?php echo tep_db_prepare_input(sprintf(TEXT_MAIL_TO,TEST_MAIL_FN . ' ' . TEST_MAIL_LN,EVENTS_TEST_EMAIL_ADDRESS)); ?></td>
								</tr>
								<?php if($display_type!='SV' && $display_type!='SS' && $display_type!='SE'){?>
								<tr>
									<td class="smallText"><?php echo tep_db_prepare_input(sprintf(TEXT_MAIL_REPLY_TO,$result['message_reply_to'])); ?></td>
								</tr>
								<tr>
									<td class="smallText"><?php echo tep_db_prepare_input(sprintf(TEXT_MAIL_SUBJECT,$result['message_subject'])); ?></td>
								</tr>
								<?php }?>
								<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
								<tr>
									<td class="smallText">
									<?php 
										if($display_type!='P' && $display_type!='EM')
										{
											if ($result['message_format']=='T'){
												$message_content=strip_tags(tep_db_prepare_input($result['message_text']),'<br>');
												}
											else
											{
												$message_content=tep_db_prepare_input($result['message_text']);
												}
												//echo 'Content:'.$message_content;
												//exit;
												
										?>
											<div  style="width:100%;height:100px;overflow:auto"><?php echo tep_replace_test_mail_content($message_content);?></div>						
									<?php }else{
											$details=array();
											if ($result['message_format']=='T')
												$details['html_text']=strip_tags(tep_db_prepare_input($result['message_text']),'<br>');						
											else
												$details['html_text']=tep_db_prepare_input($result['message_text']);
											// get display fields;

											$replace_array=array();
											tep_merge_details($replace_array,"test_default");
											//print_r ($replace_array);
											tep_replace_template($details,$replace_array);
											//print_r($details);
										?>
											<div  style="width:100%;height:100px;overflow:auto"><?php echo $details['html_text'];?></div>

									<?php }?>
									</td>
								</tr>
							</table>
							</td>
						</tr>
					</table>
				</Td>
			</tr>
		<?php } ?>
		 <tr>		 	
			<td colspan="3">
			  <div id="show_edit_screen" <?php if ($result_cnt>=1){?>style="display:none"<?php }?>>
			  <?php echo tep_draw_form('insert_message',$submit_pagename);?>			   			    			 
				  <table>				  
					<?php
						$list_add=explode("_",$fields_type);
						$array_result=array();
						for ($icnt=0;$icnt<sizeof($list_add);$icnt++){
							$array_result=array_merge($array_result,$fields_details[$list_add[$icnt]]);
						}
						$type_array=array(array('id'=>'D','text'=>TEXT_DAYS),array('id'=>'H','text'=>TEXT_HOURS));
						$register_array=array(array('id'=>'B','text'=>TEXT_BEFORE_REGISTER),array('id'=>'A','text'=>TEXT_AFTER_REGISTER));
						$mes_send_string='<span class="smallText" id="send_days_hours">'.tep_draw_input_field('message_send',substr($mesInfo->message_send,1),"size=5").'</span><span style="display:none" class="smallText" id="send_days_hours1">'.tep_draw_input_field('message_send1',substr($mesInfo->message_send1,1),"size=5") .'</span>&nbsp;'.tep_draw_pull_down_menu('type_send',$type_array,'','onchange="javascript:do_action();"').'<span id="send_type" class="smallText"> '. tep_draw_pull_down_menu('send_email_date',$register_array,$send_email_date).'</span><span id="send_type1" style="display:none"  class="smallText">&nbsp;' .tep_draw_pull_down_menu('send_email_time',$register_array,$send_email_time). '</span>';
						?>
						<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
						<tr>
							<td>													
							<table width=100% border="0" cellspacing="5" cellpadding="2">
							<?php echo tep_draw_hidden_field('message_type',$mesInfo->message_type); 
								echo tep_draw_hidden_field('action_type','');
								if($display_type!="SE" && $display_type!="SV" && $display_type!="SS")
								{
									if($mesInfo->message_type=='MIV'){?>
										<tr>
											<td class="smallText"><?php echo TEXT_INVOICE_TITLE; ?>
											<td class="smallText"><?php echo tep_draw_input_field('message_subject',$mesInfo->message_subject,'size=40'); ?></td>
										</tr>
										<tr>
											<td class="smallText" valign=top><?php echo TEXT_INVOICE_TEXT; 
											echo tep_draw_hidden_field('message_reply_to','invoice');
									  } else if($mesInfo->message_type=="CON"){ ?>
										<tr>
											<td class="smallText"><?php echo ($mesInfo->message_type=="CON"?TEXT_CONTACT_US_TITLE:TEXT_LETTER_TITLE); ?>
											<td class="smallText"><?php echo tep_draw_input_field('message_subject',$mesInfo->message_subject,'size=40'); ?></td>
										</tr>
										<tr>
											<td class="smallText" valign=top><?php echo ($mesInfo->message_type=="CON"?TEXT_CONTACT_US_TEXT:TEXT_LETTER_TEXT); 
											echo tep_draw_hidden_field('message_reply_to','contactus');
									 }
									 else if($mesInfo->message_type=='TEM' || $mesInfo->message_type=='PSP')
									 {?>
										<tr>
											<td class="smallText"><?php echo ($mesInfo->message_type=="PSP"?TEXT_PACKING_SLIP_TITLE:TEXT_LETTER_TITLE); ?>
											<td class="smallText"><?php echo tep_draw_input_field('message_subject',$mesInfo->message_subject,'size=40'); ?></td>
										</tr>
										<tr>
											<td class="smallText" valign=top><?php echo ($mesInfo->message_type=="PSP"?TEXT_PACKING_SLIP_TEXT:TEXT_LETTER_TEXT); 
											echo tep_draw_hidden_field('message_reply_to','packing_slip');
									}else{?>
										<tr>
											<td class="smallText" nowrap><?php echo TEXT_MESSAGE_SUBJECT; ?>
											<td class="smallText"><?php echo tep_draw_input_field('message_subject',$mesInfo->message_subject,'size=40',true); ?></td>
										</tr>
										<tr>
											<td class="smallText" nowrap><?php echo TEXT_MESSAGE_REPLY_TO; ?>
											<td class="smallText"><?php echo tep_draw_input_field('message_reply_to',$mesInfo->message_reply_to,'size=40',true); ?></td>
										</tr>
										<tr><td class="smallText" valign=top nowrap><?php echo TEXT_MESSAGE_TEXT .'</td>'; 
									} 
							}
							else
							{							
								$display_count_text='<font color="#FF0000"><div id="strcount"></div></font><b>' . TEXT_MESSAGE_TEXT . '</b>' . INFO_MESSAGE_TEXT .  '<br>';
								$text_params='onkeyup="countkeywords(this)"';
							}?>
							<td class="smallText" colspan="2">														
							<table border=0 cellspacing=0	 cellpadding="0" valign=top>
								<tr>
									<td valign=top class="smallText">
										<?php
											//print_r($mesInfo);
											echo $display_count_text;
											echo tep_draw_textarea_field('message_text','soft','80','24',$mesInfo->message_text,'id="message_text" ' .$text_params) . "</span>"; 
										?>
											
									</td>
									<td style="background:ButtonFace;" valign="bottom" align="center">
										<?php 
										echo "<div class='main'><b>" . TEXT_MERGE_FIELDS . '</b></div><br>';
										echo tep_draw_pull_down_menu('fields',$array_result,'','style="height:' .((strpos($_SERVER['HTTP_USER_AGENT'],"MSIE")>0)?'225':'241').'" size=15 ondblClick="AddField()"');
										?>
									</td>									
								</tr>
							</table>													
							</td>
							<?php  if(($mesInfo->message_type!='MIV' && $mesInfo->message_type!='TEM' && $mesInfo->message_type!='PSP' && $mesInfo->message_type!='CON') && ($display_type!='SE' && $display_type!='SV' && $display_type!='SS')){ ?>
							<tr>
								<td class="smallText"><?php echo TEXT_MESSAGE_FORMAT; ?>
								<td class="smallText"><?php echo tep_draw_pull_down_menu('message_format',$format_array,$mesInfo->message_format); ?></td>
							</tr>
							<?php }
							if($display_type=="V" || $display_type=="SV")
							{
								switch($mesInfo->message_type){
								case 'RCF': ?>
									<tr>
									<td class="smallText"><?php echo TEXT_REGISTRATION_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo  $mes_send_string;?></td>
									</tr>
							<?php break;?>
							<?php case "RN1": 	
									$register_array=array(array('id'=>'B','text'=>TEXT_BEFORE_BOOKING),array('id'=>'A','text'=>TEXT_AFTER_BOOKING));
							?>		<tr>
								 	<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo $mes_send_string?></td>
									</tr>
							<?php break;?>
							<?php case "RN2": 	
									$register_array=array(array('id'=>'B','text'=>TEXT_BEFORE_BOOKING),array('id'=>'A','text'=>TEXT_AFTER_BOOKING));
							?>		<tr>
									<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo $mes_send_string; ?></td>
								</tr>
							<?php break;?>
							<?php case "RN3": 	
									$register_array=array(array('id'=>'B','text'=>TEXT_BEFORE_BOOKING),array('id'=>'A','text'=>TEXT_AFTER_BOOKING));
								?><tr>
									<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo $mes_send_string?></td>
								</tr>
							<?php break;?>
							<?php case "RN4":  	
								$register_array=array(array('id'=>'B','text'=>TEXT_BEFORE_BOOKING),array('id'=>'A','text'=>TEXT_AFTER_BOOKING));
							?>	<tr>
									<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo  $mes_send_string;?></td>
								</tr>
							<?php break;?>
							<?php case "RN5": 	
								$register_array=array(array('id'=>'B','text'=>TEXT_BEFORE_BOOKING),array('id'=>'A','text'=>TEXT_AFTER_BOOKING));
							?>	<tr>
									<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo $mes_send_string; ?></td>
								</tr>
								<?php break;
							  }//end switch
							
							if ($message_type=="RS" || $message_type=="RE" )	
							{
						   	 	$renewal_start_array=array(array('id'=>'B','text'=>TEXT_RENEWAL_START_BEFORE),array('id'=>'A','text'=>TEXT_RENEWAL_START_AFTER));
						    	$renewal_end_array=array(array('id'=>'B','text'=>TEXT_RENEWAL_END_BEFORE),array('id'=>'A','text'=>TEXT_RENEWAL_END_AFTER));
								if ($message_type=="RS"){ 
							?>
								<tr>
									<td class="smallText"><?php echo TEXT_RESERVATION_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo $mes_send_string; ?></td> 
								</tr> 
							<?php	}
								elseif ($message_type=="RE"){	
								?>
								<tr>
									<td class="smallText"><?php echo TEXT_RESERVATION_EMAIL_SEND; ?></td>
									<td class="smallText"><?php echo $mes_send_string; ?></td>
								</tr>
								<?php } ?>
						<?php } 
					 } //for service if ?>
					 <?php 
						$message_type=substr($mesInfo->message_type,0,2);
						 if (substr($mesInfo->message_type,0,2)=="RN" && $display_type=='S'){ 
									$renewal_array=array(array('id'=>'B','text'=>TEXT_RENEWAL_BEFORE),array('id'=>'A','text'=>TEXT_RENEWAL_AFTER));
						?>
							<tr>
								<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_SEND; ?>
								<td class="smallText"><?php echo tep_draw_pull_down_menu('message_send',$renewal_array,$mesInfo->message_send); ?></td>
							</tr>
							<tr>
								<td class="smallText"><?php echo TEXT_RENEWAL_EMAIL_DAYS; ?>
								<td class="smallText"><?php echo tep_draw_input_field('message_send1',$mesInfo->message_send1) . '&nbsp;' . TEXT_DAYS; ?></td>
							</tr>
						<?php } ?>				
						</table>												
						</td>
					</tr>
				   <tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>
				   </table>				 
				  </form>
				</div>							  
			  </td>			
		  </tr>		 
<?php }else if ($message_array['mode']==2){?>
	<tr><td colspan="2" class="smallText"><?php echo tep_image('images/icons/arrow.gif',IMAGE_ADD_MESSAGE) .'&nbsp;&nbsp;' . $message_array['text']; ?>
	</td>
	<td align="center">
 <?php echo'
		<table border="0" cellpadding="0" cellspacing="0" style="width:100;height:30;display:inline;position:relative;top:0px;">
			<tr>
				<td width="10" class="cell_bg_popm_left">&nbsp;</td>
				<td align="center" style="background:#DEE4F5;">';
		if ($message_array['id']=='MSV')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SERVICES_EMAIL,'action=new_message&type=V&service_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_RESERVE);
		elseif ($message_array['id']=='MEV' && $display_type=='E')
			echo '<a href="' . tep_href_link(FILENAME_SEND_EMAIL,'action=new_message&type=R&events_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_RESERVE);
		elseif ($message_array['id']=='MEW' && $display_type=='E')
			echo '<a href="' . tep_href_link(FILENAME_SEND_EMAIL,'action=new_message&type=W&events_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_RESERVE);
		elseif ($message_array['id']=='MEV' && $display_type=='S')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SUBSCRIPTION_EMAIL,'action=new_message&subscription_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_SUBSCRIBE);
		elseif($display_type=="EM")
			echo '<a href="' . tep_href_link(FILENAME_MAIL,'selected_box=tools&customer=***') . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_CUSTOMERS) . "</a>";
		elseif($message_array['id']=='MEV' && $display_type=='SE')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SMS_EMAIL,'action=new_message&type=R&events_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_RESERVE);
		elseif($display_type=='SE')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SMS_EMAIL,'action=new_message&type=W&events_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_WAITLIST);
		elseif($display_Type=='SV')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SERVICE_SMS_EMAIL,'action=new_message&type=R&service_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_WAITLIST);
		elseif ($message_array['id']=='MEV' && $display_type=='SS')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SUBSCRIPTION_SMS_EMAIL,'action=new_message&type=R&subscription_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_RESERVE);
		elseif ($message_array['id']=='PMEV' && $display_type=='SS')
			echo '<a href="' . tep_href_link(FILENAME_SEND_SUBSCRIPTION_SMS_EMAIL,'action=new_message&type=P&subscription_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_WAITLIST);
		elseif($display_type=='SS') 
			echo '<a href="' . tep_href_link(FILENAME_SEND_SUBSCRIPTION_SMS_EMAIL,'action=new_message&type=C&subscription_id=' . $type_id) . '">' . tep_image('images/icons/mail.gif',IMAGE_SEND_ALL_WAITLIST);
		echo '  </td>
							<td width="10" class="cell_bg_popm_right">&nbsp;</td>
						</tr>
					</table>
					';
	}?>
	</td></tr>
</Table></td></tr>
<?php if ($message_array['mode']!=2)
{?>
<tr id="show_edit_bottom" <?php if ($result_cnt>=1){?>style="display:none"<?php }?>>
	<td align="right" colspan="3">&nbsp;
		<?php
			//echo '<a href="javascript:do_submit(\'' . $new_action  . '\',\'' . $mesInfo->message_id . '\',\''  . $type_id . '\')">' . tep_image('images/icons/edit_green.gif') . "</a>&nbsp;";
			//echo '<a href="javascript:close_edit();">' . tep_image('images/icons/cancel.gif') . "</a>";
		?>
	</td>
</tr>
<?php }?>
</table>
<?php }?>
<?php function tep_get_message_list($message_array,$message_type_array,$fields_type,$display_type,$type_id)
{  ?>
	<Table width="100%" cellpadding="5" cellspacing="0" border="0">
	<tr>
		<td class="pageHeading"><?php 
			switch($display_type)
			{
				case "P":	//products
				case "EM":	//email messages
				case "W":	//wallet
					//$sql_query="SELECT message_id,message_type,message_send,message_subject from " . TABLE_EMAIL_MESSAGES . " where 1=1 ";
					echo TEXT_HEADING_TITLE;
					break;
				case "E":	//events
					//$sql_query="SELECT events_message_id,message_type,message_send,message_subject from " . TABLE_EVENTS_MESSAGES . " where events_id='" . $type_id . "'";
					echo sprintf(TEXT_HEADING_TITLE,tep_get_events_name($type_id));
					$button_text= '<div style="padding-top:10px;"><a href="javascript: copy_message('.$type_id.',\'E\');">' . tep_image_button('button_copy_messages.gif',IMAGE_COPY_MESSAGES) . "</a></div>";
					break;
				case "SE":	//sms evente
					//$sql_query="SELECT events_sms_message_id,message_type,message_send,message_subject from " . TABLE_EVENTS_SMS_MESSAGES . " where events_id='" . $type_id . "'";
					echo sprintf(TEXT_HEADING_TITLE,tep_get_events_name($type_id));
					$button_text='<div style="padding-top:10px;"><a href="javascript: copy_message('.$type_id.',\'sm\');">' . tep_image_button('button_copy_messages.gif',IMAGE_COPY_MESSAGES) . "</a></div>";
					break;
				case "S":	//subscriptions
					//$sql_query="SELECT subscription_message_id,message_type,message_send,message_subject from " . TABLE_SUBSCRIPTION_MESSAGES . " where subscription_id='" . $type_id . "'";
					echo sprintf(TEXT_HEADING_TITLE,tep_get_subscription_name($type_id));
					$button_text='<div style="padding-top:10px;"><a href="javascript: copy_message('.$type_id.',\'S\');">' . tep_image_button('button_copy_messages.gif',IMAGE_COPY_MESSAGES) . "</a></div>";
					break;
				case "SS":	//sms subscriptions
					//$sql_query="SELECT subscription_sms_message_id,message_type,message_send,message_subject,message_text from " . TABLE_SUBSCRIPTION_SMS_MESSAGES . " where subscription_id='" . $type_id . "'";
					echo sprintf(TEXT_HEADING_TITLE,tep_get_subscription_name($type_id));
					$button_text='<div style="padding-top:10px"><a href="javascript: copy_message('.$type_id.',\'sm\');">' . tep_image_button('button_copy_messages.gif',IMAGE_COPY_MESSAGES) . "</a></div>";
					break;
				case "V":	//services
					//$sql_query="SELECT services_message_id,message_type,message_send,message_subject from " . TABLE_SERVICES_MESSAGES . " where service_id='" . $type_id . "'";
					echo sprintf(TEXT_HEADING_TITLE,tep_get_service_name($type_id));
					$button_text= '<div style="padding-top:10px;"><a href="javascript: copy_message('.$type_id.',\'V\');">' . tep_image_button('button_copy_messages.gif',IMAGE_COPY_MESSAGES) . "</a></div>";
					break;
				case "SV":	//sms services
					//$sql_query="SELECT services_sms_message_id,message_type,message_send,message_subject from " . TABLE_SERVICES_SMS_MESSAGES . " where service_id='" . $type_id . "'";
					echo sprintf(TEXT_HEADING_TITLE,tep_get_service_name($type_id));
					$button_text='<div style="padding-top:10px"><a href="javascript: copy_message('.$type_id.',\'sm\');">' . tep_image_button('button_copy_messages.gif',IMAGE_COPY_MESSAGES) . "</a></div>";
					break;
			}?></td>
	</tr>
	<tr class="dataTableHeadingRow"><td class="main"><?php echo TEXT_MESSAGE_TYPE ;?></td></tr>
	<?php for($icnt=0;$icnt<sizeof($message_array);$icnt++){   //echo $message_array[$icnt]['id'];
			$disp_class=($disp_class=="dataTableRowOdd")?"dataTableRowEven":"dataTableRowOdd";?>
			<tr id="<?php echo $message_array[$icnt]['id'];?>_row" height=25 onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" class="<?php echo $disp_class;?>" style="cursor:hand" onclick="javascript:fetch_details('<?php echo $type_id; ?>','<?php echo $message_array[$icnt]['id']; ?>');">
				<td class="dataTableContent"><?php echo $message_array[$icnt]['text']; ?></td>
			</tr>
			<tr  class="openContent">
				<td height=25  id="<?php echo $message_array[$icnt]['id']; ?>" style="display:none">
					<?php echo tep_image(DIR_WS_IMAGES . '24-1.gif') ;?>
				</td>
			</tr>
		<?php }  ?>
</table>
	<?php

	switch($display_type){
		case 'SE':
		case 'E' :
		case 'SS':
		case 'SV':
		case 'V' :
		case 'S' :
			echo $button_text;
			break;
	}

	 ?>
<?php }?>