<?php include("links/top.php");
$action=$_GET['action'];
?>
<?php 
if($action=='delete'){
$id=$_GET['id'];
$del="delete from mail_templet where id='$id'";
$DB->executeQuery($del);
header('Location:mail_templet.php?action=list');
}
?>
	<?php 
	if($action=='addnew' || $action== 'edit'){
	if($action=='edit'){
	$id=$_GET['id'];
	}
	if(isset($_POST['submit']) || isset($_POST['update'])){
	
	extract($_POST);
	
	if($action=='addnew'){
		$arr=array('name' 	=> addslashes($name),'femail' 	=> addslashes($femail),'description' 	=> addslashes($description),'unlink' 	=> addslashes($unlink),'alink' 	=> addslashes($alink),'blink' 	=> addslashes($blink),'rlink' 	=> addslashes($rlink),'wlink' 	=> addslashes($wlink),'mail' 	=> addslashes($mail)); 
		$DB->insert('mail_templet',$arr);	
		$id=getRecordId();						
	}
	if($action=='edit'){
		$arr=array('name' 	=> addslashes($name),'femail' 	=> addslashes($femail),'description' 	=> addslashes($description),'unlink' 	=> addslashes($unlink),'alink' 	=> addslashes($alink),'blink' 	=> addslashes($blink),'rlink' 	=> addslashes($rlink),'wlink' 	=> addslashes($wlink),'mail' 	=> addslashes($mail));
		$DB->update('mail_templet',$arr,"id='$id'");
	}
	if($_FILES['file']['name']!='')
		{
		//$code=time();
		$filepath="uploads/images/";
		$extension = strtolower(strrchr($_FILES['file']['name'], '.'));
		if($extension=='.jpg' || $extension=='.jpeg' || $extension=='.png' || $extension=='.gif' || $extension=='.JPG' || $extension=='.JPEG' || $extension=='.PNG' || $extension=='.GIF' || $extension=='.bmp' || $extension=='.BMP'){
		$image = $filepath.$_FILES['file']['name'];
		move_uploaded_file($_FILES['file']['tmp_name'],'../'.$image);
		$arr=array( 'image' 	=> $image);
		$DB->update('mail_templet',$arr,"id='$id'");
		}}
header('Location: mail_templet.php?action=list');
	}
	}
	?>	
		<div id="content">
			<div class="container">
				<div class="page-header">
					<div class="page-title">
						<h3>Mail Templet Management</h3>
					</div>
				</div>
				<div class="row">
               
					<div class="col-md-12">
                    <?php /*?><?php if($action=='list'){?> <a href="mail_templet.php?action=addnew"><button class="btn btn-sm btn-info">Add Page</button></a> <?php } ?><?php */?>                   
						<div class="widget box">
                        <div class="widget-header">
						<?php if($action=='list'){?>
                            <h4>Mail Templet List</h4>
                            <?php }else if($action=='addnew'){ ?>
                            <h4>Add Mail Templet</h4>
                            <?php }?>					
							</div>
                        <div class="widget-content">
                             <?php if($action=='list'){
								 $sno=1;
								$sel=executeQuery("select * from mail_templet");
								?>							
							
								<table class="table table-striped table-bordered table-hover table-checkable datatable">
									<thead>
										<tr>
											<!-- <th class="checkbox-column"><input type="checkbox" class="uniform"></th> -->
                                            <th>S.No</th>
											<th>From Name</th>
                                            <th>Image</th>
                                            
											<th>Action</th>
										</tr>
									</thead>
									<tbody>
                                    <?php
								  $sno=1;
								 while($rec=getAssoc($sel)){?>
										<tr>
											<!--<td class="checkbox-column"><input type="checkbox" class="uniform"></td>-->
                                             <td><?php echo $sno;?></td>
											<td><?php echo $rec['name'];?></td>
                                            <td><img src="<?php if($rec['image']!=''){echo '../'.$rec['image'];}else{echo 'assets/img/no-image.gif';}?>" style="height:40px;" /></td>
											<td>
                                             <a href="mail_templet.php?action=edit&id=<?php echo $rec['id'];?>" title="Edit"><i class="icol-pencil"></i></a> &nbsp;&nbsp;
										 <?php /*?><a href="mail_templet.php?action=delete&id=<?php echo $rec['id'];?>" onClick="return confirm('Are you sure you want to delete ?')" title="Delete"><i class="icol-cross"></i></a><?php */?>
                                            </td>
										</tr>
                                        <?php $sno++;}?>
									</tbody>
								</table>
							<p>Mailing Portal URL :<a href="https://agingcongress.com/aging-mail-templet.php" target="_blank">https://agingcongress.com/aging-mail-templet.php</a>
                            <?php }else if($action=='addnew' || $action=='edit'){?>
					
							<?php if($action=='edit'){
                            $id=$_GET['id'];
                            $e="select * from mail_templet where id='$id'";
                            $ed=$DB->executeQuery($e);
                            $edi=$DB->getAssoc($ed);
                            }?>
														
								<form class="form-horizontal" id="validate-1" method="post" novalidate="novalidate" enctype="multipart/form-data">
									<div class="form-group">
										<label class="col-md-2 control-label">From Name <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="name" class="form-control required" value="<?php if($action=='edit'){echo $edi['name'];}?>">
										</div>
									</div>
                                    
                                   
                                    
                                   <div class="form-group">
										<label class="col-md-2 control-label">From Email <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="femail" class="form-control required" value="<?php if($action=='edit'){echo $edi['femail'];}?>">
										</div>
									</div>
                                   
								<div class="form-group">
                                    <label class="col-md-2 control-label">Image <span class="required">*</span></label>
                                    <div class="col-md-2 fileupload fileupload-new" data-provides="fileupload">
                                            <div class="fileupload-new thumbnail" style="width: 180px;">
                                           <img src="<?php if($action=='edit'){if($edi['image']!=''){ echo '../'.$edi['image'];}else{echo 'assets/img/no-image.gif';}}else{echo 'assets/img/no-image.gif';}?>" style="width:170px;" />
                                            </div>
                                            <div class="fileupload-preview fileupload-exists thumbnail"></div>
                                            <div>
                                                <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists" style="padding:6px;">Change</span><input type="file" name='file' <?php if($action=='edit'){if($edi['image']==''){echo 'class="required"';}}else{echo 'class="required"';}?> accept="image/*"  /></span><br />
                                              
                                                <a href="#" class="btn fileupload-exists" style="padding:4px 7px!important;" data-dismiss="fileupload">Remove</a>
                                            </div>
                                        </div>
                                        </div>
                                        
                                        <div class="form-group">
										<label class="col-md-2 control-label">Abstract Link <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="alink" class="form-control required" value="<?php if($action=='edit'){echo $edi['alink'];}?>">
										</div>
									</div>
                                    
                                    <div class="form-group">
										<label class="col-md-2 control-label">Brochure Link<span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="blink" class="form-control required" value="<?php if($action=='edit'){echo $edi['blink'];}?>">
										</div>
									</div>
                                    
                                    <div class="form-group">
										<label class="col-md-2 control-label">Registration Link<span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="rlink" class="form-control required" value="<?php if($action=='edit'){echo $edi['rlink'];}?>">
										</div>
									</div>
                                    
                                    <div class="form-group">
										<label class="col-md-2 control-label">Website Link<span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="wlink" class="form-control required" value="<?php if($action=='edit'){echo $edi['wlink'];}?>">
										</div>
									</div>
                                    
                                    <div class="form-group">
										<label class="col-md-2 control-label">Unsubscribe Link <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="unlink" class="form-control required" value="<?php if($action=='edit'){echo $edi['unlink'];}?>">
										</div>
									</div>
                                       
                                       <div class="form-group">
										<label class="col-md-2 control-label">Mail Us <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="mail" class="form-control required" value="<?php if($action=='edit'){echo $edi['mail'];}?>">
										</div>
									</div>
                                  
                                    
                                    <div class="form-group">
										<label class="col-md-2 control-label">Description</label>
										<div class="col-md-12 clearfix" style="clear:both; margin-top:40px;">
											<textarea id="description" name="description" class="ckeditor"><?php if($action=='edit'){echo $edi['description'];}?></textarea>
										</div>
									</div>
                                    
                                   
									<div class="form-actions">
                                    <label class="col-md-2">&nbsp;</label>
                                    <?php if($action=='addnew'){?>
									<input class="btn btn-info pull-left" type="submit" name="submit" value="Submit" />
									<?php }else if($action=='edit'){?>
									<input class="btn btn-info pull-left" type="submit" name="update" value="Update" />
									<?php }?>
									</div>
								</form>
						<?php }?>
                        </div>
                    </div>				
                </div>
            </div>
        </div>
	<?php include("links/bottom.php");?>