<?php include("links/top.php");

$action=$_GET['action'];

$pid=$_GET['pid'];

?>

<?php 

if($action=='delete'){

$id=$_GET['id'];

$pid=$_GET['pid'];

$del="delete from speakers_titles where id='$id'";

$DB->executeQuery($del);

header('Location:speakers_titles.php?action=list&pid='.$pid);

}

?>

	<?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('title' 		=> addslashes($title),'pid' 		=> addslashes($pid),'year' 		=> addslashes($year),'keynote' 		=> addslashes($keynote)); 

		$DB->insert('speakers_titles',$arr);

		$id=getRecordId();							

	}

	if($action=='edit'){

		$arr=array( 'title' 		=> addslashes($title),'pid' 		=> addslashes($pid),'year' 		=> addslashes($year),'keynote' 		=> addslashes($keynote));

		$DB->update('speakers_titles',$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.$id.$code.$extension;



		move_uploaded_file($_FILES['file']['tmp_name'],'../'.$image);



		$arr=array( 'image' 	=> $image);



		$DB->update('speakers_titles',$arr,"id='$id'");



		}}

		

	

header('Location: speakers_titles.php?action=list&pid='.$pid);

	}

	}

	?>	

		<div id="content">

			<div class="container">

				<div class="page-header">

					<div class="page-title">

						<h3>Speakers Titles List</h3>

					</div>

				</div>

				<div class="row">

               

					<div class="col-md-12">

                    <?php if($action=='list'){?> <a href="speakers_titles.php?action=addnew&pid=<?php echo $pid;?>"><button class="btn btn-sm btn-info">Add Speakers Titles</button></a> <?php } ?>                    <a href="speakers.php?action=list"><input class="btn btn-sm btn-info" type="submit" style="float:right;" name="submit" value="Back to Speakers" /></a> 

						<div class="widget box">

                        <div class="widget-header">

						<?php if($action=='list'){?>

                            <h4>Speakers Titles List</h4>

                            <?php }else if($action=='addnew'){ ?>

                            <h4>Add Speakers Titles</h4>

                            <?php }?>					

							</div>

                        <div class="widget-content">

                             <?php if($action=='list'){

								 $sno=1;

								$sel=executeQuery("select * from speakers_titles where pid='$pid'");

								?>							

							

								<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>Home</th>-->
                                <th>Title</th>
                                 <th>Year</th>
                                 <!--<th>Image</th>-->

                                 <th>Status</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>
                                 

                              <?php /*    <td class="checkbox-column"><input type="checkbox" onclick="checkhome('speakers_titles','<?php echo $rec['id'];?>','home')" class="uniform" value="1" id="home<?php echo $rec['id'];?>" <?php if($rec['home']==1){echo 'checked="checked"';}?>></td> */ ?>
                            	 
                            	 <td><?php echo $rec['title'];?></td>
                            	  <td><?php echo getRecord('id','speakers_year',$rec['year'],'title');?></td>
                                   <?php /* <td><img src="<?php if($rec['image']!=''){echo '../'.$rec['image'];}else{echo 'assets/img/no-image.gif';}?>" style="height:40px;" /></td> */ ?> 

                                 

                                 <td><a href="javascript:void(0)" id="status<?php echo $rec['id'];?>" onclick="return status(<?php echo $rec['id'];?>,'speakers_titles')"><?php if($rec['status']==1){echo 'Active';}else{echo 'Inactive';}?></a></td>

											<td>

                                             <a href="speakers_titles.php?action=edit&&pid=<?php echo $pid;?>&id=<?php echo $rec['id'];?>" title="Edit"><i class="icol-pencil"></i></a> &nbsp;&nbsp;

										 <a href="speakers_titles.php?action=delete&&pid=<?php echo $pid;?>&id=<?php echo $rec['id'];?>" onClick="return confirm('Are you sure you want to delete ?')" title="Delete"><i class="icol-cross"></i></a>

                                            </td>

										</tr>

                                        <?php $sno++;}?>

									</tbody>

								</table>

							

                            <?php }else if($action=='addnew' || $action=='edit'){?>

					

							<?php if($action=='edit'){

                            $id=$_GET['id'];

                            $e="select * from speakers_titles 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">Title Name <span class="required">*</span></label>
										<div class="col-md-4">
											<input type="text" name="title" class="form-control required" value="<?php if($action=='edit'){echo $edi['title'];}?>">
										</div>
									</div>
									
									 <div class="form-group">

										<label class="col-md-2 control-label">Year <span class="required">*</span></label>

										<div class="col-md-4 clearfix">

                                        <select name="year" class="form-control required">

												<option value=""></option>

												<?php 

													$ca=executeQuery("select * from speakers_year");

													while($cat=getAssoc($ca)){

													?>

								   <option <?php if($action=='edit'){if($edi['year']==$cat['id']){echo 'selected="selected"';}}?> value="<?php echo $cat['id'];?>"><?php echo $cat['title'];?></option>

													 <?php } ?>

											</select>

											<label for="dd1" generated="true" class="has-error help-block" style="display:none;"></label>

										</div>

									</div>
                                    
									
									<div class="form-group">
										<label class="col-md-2 control-label">Keynote </label>
										<div class="col-md-4">
											<input type="text" name="keynote" class="form-control" value="<?php if($action=='edit'){echo $edi['keynote'];}?>">
										</div>
									</div>
                                   
                                    <?php /*
                                    <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 />

                                                

                                                 <span style="color:#F00;"> Image Size[1280 X 720];</span>



                                                <a href="#" class="btn fileupload-exists" style="padding:4px 7px!important;" data-dismiss="fileupload">Remove</a>



                                            </div>



                                        </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");?>

	<script>



function checkhome(tab,iid,str)



{



var val=document.getElementById(str+''+iid).checked;



$.ajax({



   type: "POST",



   url: "checkhome.php",



   data: "val="+val+"&iid="+iid+"&str="+str+"&tab="+tab,



   success: function(msg){}



 });



}





</script>