<?php

if (!function_exists('makethumb')) {
function makethumb($settings) { 


if (array_key_exists('file_name', $settings)) {
   $file=$settings['file_name'];
   }
if (array_key_exists('uploaded_tmp', $settings)) {
   $uploaded_path=$settings['uploaded_tmp'];
   }
if (array_key_exists('site_name_prefix', $settings)) {
   $sitename=$settings['site_name_prefix'];
   }
if (array_key_exists('thumbs_folder', $settings)) {
   $thumb_folder=$settings['thumbs_folder'];
   }
if (array_key_exists('record_id', $settings)) {
   $record_id=$settings['record_id'];
   }
if (array_key_exists('slip_no', $settings)) {
   $slipno=$settings['slip_no'];
   }
if (array_key_exists('table', $settings)) {
   $table=$settings['table'];
   }
if (array_key_exists('img_col', $settings)) {
   $img_col=$settings['img_col'];
   }
if (array_key_exists('id_col', $settings)) {
   $record_id_col=$settings['id_col'];
   }
if (array_key_exists('upload_dir', $settings)) {
   $path=$settings['upload_dir'];
   }
if (array_key_exists('upload_dir', $settings)) {
   $base_path=$settings['upload_dir'];
   }
if (array_key_exists('og_dir', $settings)) {
   $og_path=$settings['og_dir'];
   }
if (array_key_exists('create_icons', $settings)) {
   $icons01=$settings['create_icons'];
   }
if (array_key_exists('original', $settings)) {
   $original=$settings['original'];
   }
if (array_key_exists('thumbs_req', $settings)) {
   $thumbs_req=$settings['thumbs_req'];
   }
if (array_key_exists('redirect', $settings)) {
   $redirect=$settings['redirect'];
   }
//echo dirname(__FILE__);

   

$gd1="../assets/plugins/gd/Thumbnail.class.php";
$gd2="../assets/plugins/gd/ThumbLib.inc.php";


include_once($gd1);
include_once($gd2);

$mysqli_user=uplink();    
	

	$product_image_name2=strtolower($file);
	$uploaded_file_path2 = $uploaded_path;
	

	
	if($product_image_name2 != ""){
		$filetype2 = substr($product_image_name2, -3);
		//$site_name2 = $sitename.$slipno.$thumb_folder.$record_id;
		$site_name2 = $sitename.$record_id;
		if($filetype2=="jpg" || "JPG" || "JPEG" || "jpeg" || "gif" || "png")
		{
			$product_image_name_new2 = $site_name2 . "." . $filetype2;
			$query2 = "UPDATE $table SET $img_col = '$product_image_name_new2' WHERE $record_id_col = '$record_id'";
			$query_up=$mysqli_user->query($query2);
			//Move uploaded file to temp folder
			if (move_uploaded_file($uploaded_file_path2, $path.$product_image_name_new2))
			{
				$msg2="yes";
			}else{
				//if upload fails
				$msg2="no";
				die("Error uploading photo - Check File path - Connection Slow");
	//			exit();
			}
			if($thumbs_req!=0){
			if($icons01!=0){
			
			$thumb2 = PhpThumbFactory::create($base_path.$product_image_name_new2."");
			if($thumb2->resize(333, 333)){

				if(!$thumb2->save($og_path.$product_image_name_new2)){
					print "<br>Failed to Create Thumb, The required file might be moved, removed or the image is too small";
				}
			}
			}
				
			}
			if($original!=0){
			if (copy($base_path.$product_image_name_new2, $base_path.$product_image_name_new2)){
			unlink($base_path.$product_image_name_new2);
			}
else{
//echo $base_path."original/".$product_image_name_new2."<br />".$base_path.$product_image_name_new2;
//exit();	
}
			}
			else{
			unlink($base_path.$product_image_name_new2);
			}
		}
	}
	else{
			//$product_image_name_new2 = 'default_image.png';
			//$query2 = "UPDATE $table SET $img_col = '$product_image_name_new2' WHERE $record_id_col = '$record_id'";
			//mysql_query($query2);
			//$mysqli_user->query($query2);
	}

	

	
} 
}

//////////////////////////////////////////////////////////////////////////

//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////
// !updated with path option march 2021
if (!function_exists('makeform_img')) {
function makeform_img($settings,$image_settings) {
if (array_key_exists('table', $settings)) {
   $table=$settings['table'];
   }
if (array_key_exists('fields', $settings)) {
   $text=$settings['fields'];
   }
if (array_key_exists('lead_id', $settings)) {
   $lead_id=$settings['lead_id'];
   }
if (array_key_exists('encoding', $settings)) {
   $encoding=$settings['encoding'];
   }
if (array_key_exists('redirect', $settings)) {
   $redirect=$settings['redirect'];
   }
if (array_key_exists('heading', $settings)) {
   $heading=$settings['heading'];
   }
if (array_key_exists('suffix', $image_settings)) {
   $suffix=$image_settings['suffix'];
   }
if (array_key_exists('path', $image_settings)) {
   $path=$image_settings['path'];
   }
if (array_key_exists('add_new', $settings)) {
   $add_new=$settings['add_new'];
   }
   
if(isset($add_new) && $add_new!=0) {

$rt=add_record($settings['add_new_table'],$settings['add_new_ref']);

$lead_id=$rt;	
	
}   

?>
<script type="text/javascript">
  $(document).ready(function() {
$('.dropify').dropify({
    error: {
        'fileSize': 'The file size is too big ({{ value }} max).',
        'minWidth': 'The image width is too small ({{ value }}}px min).',
        'maxWidth': 'The image width is too big ({{ value }}}px max).',
        'minHeight': 'The image height is too small ({{ value }}}px min).',
        'maxHeight': 'The image height is too big ({{ value }}px max).',
        'imageFormat': 'The image format is not allowed ({{ value }} only).'
    },
messages: {
        'default': 'Drag and drop a file here or click',
        'replace': 'Drag and drop or click to replace',
        'remove':  'Remove',
        'error':   'Ooops, something wrong happended.'
    }	
});
	  
$("#subbtn").click(function(){
//$("#subbtn").text("Please Wait...");

	  });
  });
  </script>


  
<div id="page-right-content">

                    <div class="container">
    
<div class="row">
<div class="col-sm-12">
                                <h4 class="header-title m-t-0 m-b-20"><?php echo $settings['heading']; ?></h4>
                            </div>
							
</div>	


<script type="text/javascript">
  $(document).ready(function() {
	 
$("#subbtn").click(function(){
$("#locked").show();
$(".card").css("pointer-events","none");

	  });
	 });
  </script>
  
<p>&nbsp;</p>
                    
						<div class="row">
                <div class="col-md-12">


<form role="form" enctype="multipart/form-data" method="post">

<?php

if(isset($text)){
foreach ($text as $ty1 => $value){
$text1[] = $text[$ty1]['field'];
$db[] = $text[$ty1]['field'];

$heading=$text[$ty1]['heading'];
$rt=$text[$ty1]['field'];

$list=array(id_col,status,ref,$text[$ty1]['field']);

$db_settings4=array(
'table'=>$table,
'id_col'=>id_col,
'where_col'=>id_col,
'where_value'=>$lead_id,
'fields_array'=>$list,
'ref_value'=>routine_entry_alias,
'type'=>'wherecol_ref_status',
'echo'=>'0',
'to_find'=>$text[$ty1]['field']
);

$photo1=db_fetch($db_settings4);

foreach($photo1 as $photoitem){
$photo=$photoitem[$rt];
}

?>



              
			  
                 
				 <?php if (!isset($text[$ty1]['class'])) { ?>
				 <div class="col-md-6">
				 <?php } 
				 else{ ?>
				<div class="<?php echo $text[$ty1]['class']; ?>">
				 <?php } ?>	 
<h4><?php echo $heading; ?></h4>                    
					 	<input type="file" data-max-file-size="3M" data-allowed-file-extensions="jpg png" 
						class="dropify" name="<?php echo $text[$ty1]['field']."_name"; ?>" id="upload_file_id" 
						<?php  
						if(isset($photo) && $photo!=""){
						?> 
						 data-default-file="<?php echo SITE_IMAGES.$path['photo_folder_absolute'].$photo; ?>" 
						<?php  
                    }
						?>
						/>
					
					


    	</div>	
		
		

<?php
	  
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

?>
<p>&nbsp;</p>
<div class="col-md-12 text-center gap-items-5">


                    <button type="reset" class="btn btn-lg btn-label btn-danger" onclick="history.go(-1);">Cancel
					<label><i class="ti-close"></i></label>
					</button>
                    
					<button class="btn btn-lg btn-label btn-success" type="submit" name="add_itembtn" id="subbtn">Insert
					<label><i class="ti-shift-right"></i></label>
					</button>
                    <input type="hidden" name="add_item" value="add_item">
                    <hr class="d-lg-none">
                    

					

				  	  
                
            
				  </div>
			
				  </div>
				  </div>
				 
				  <?php
///////////////////////////////////////////////////////////////////
if(isset($_POST['add_item'])){

$count=count($text1);
$i = 0;
$ret=array_combine($text1, $db);
foreach ($ret as $name => $col){
$i++;
//echo "here".$i;
	
$imgsettings=array(
'file_name'=>$_FILES[$name."_name"]['name'],
'uploaded_tmp'=>$_FILES[$name."_name"]['tmp_name'],
'site_name_prefix'=>$suffix.'-'.$name."-",
//'thumbs_folder'=>'photos',
'thumbs_folder'=>$path['thumbs_folder'],
'record_id'=>$lead_id,
'slip_no'=>$lead_id."-",
'table'=>$table,
'img_col'=>$col,
'id_col'=>id_col,
//'upload_dir'=>photo_folder,
'upload_dir'=>$path['upload_dir'],
//'og_dir'=>photo_folder_og,
'og_dir'=>$path['og_dir'],
'original'=>'1',
//'thumbs_req'=>'1',
'thumbs_req'=>$path['thumbs_req'],
//'redirect'=>'/view/deals/',
//'create_icons'=>'1'
'create_icons'=>$path['create_icons']
);	

makethumb($imgsettings);
}

app_redirect_adv($redirect);
}



?>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>

</div>

<?php
 
} 
}
/////////////////////////// function ends /////////////////////////////////
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////
// !updated with path option march 2021
if (!function_exists('makeform_img_new')) {
function makeform_img_new($settings,$image_settings) {
if (array_key_exists('table', $settings)) {
   $table=$settings['table'];
   }
if (array_key_exists('fields', $settings)) {
   $text=$settings['fields'];
   }
if (array_key_exists('caption_fields', $settings)) {
   $caption=$settings['caption_fields'];
   }
if (array_key_exists('lead_id', $settings)) {
   $lead_id=$settings['lead_id'];
   }
if (array_key_exists('encoding', $settings)) {
   $encoding=$settings['encoding'];
   }
if (array_key_exists('redirect', $settings)) {
   $redirect=$settings['redirect'];
   }
if (array_key_exists('heading', $settings)) {
   $heading=$settings['heading'];
   }
if (array_key_exists('suffix', $image_settings)) {
   $suffix=$image_settings['suffix'];
   }
if (array_key_exists('path', $image_settings)) {
   $path=$image_settings['path'];
   }
if (array_key_exists('add_new', $settings)) {
   $add_new=$settings['add_new'];
   }
   

?>
<script type="text/javascript">
  $(document).ready(function() {
$('.dropify').dropify({
    error: {
        'fileSize': 'The file size is too big ({{ value }} max).',
        'minWidth': 'The image width is too small ({{ value }}}px min).',
        'maxWidth': 'The image width is too big ({{ value }}}px max).',
        'minHeight': 'The image height is too small ({{ value }}}px min).',
        'maxHeight': 'The image height is too big ({{ value }}px max).',
        'imageFormat': 'The image format is not allowed ({{ value }} only).'
    },
messages: {
        'default': 'Drag and drop a file here or click',
        'replace': 'Drag and drop or click to replace',
        'remove':  'Remove',
        'error':   'Ooops, something wrong happended.'
    }	
});
	  
$("#subbtn").click(function(){
//$("#subbtn").text("Please Wait...");

	  });
  });
  </script>


  
<div id="page-right-content">

                    <div class="container">
    
<div class="row">
<div class="col-sm-12">
                                <h4 class="header-title m-t-0 m-b-20"><?php echo $settings['heading']; ?></h4>
                            </div>
							
</div>	


<script type="text/javascript">
  $(document).ready(function() {
	 
$("#subbtn").click(function(){
$("#locked").show();
$(".card").css("pointer-events","none");

	  });
	 });
  </script>
  
<p>&nbsp;</p>
                    
						<div class="row">
                <div class="col-md-12">


<form role="form" enctype="multipart/form-data" method="post">

<?php

if(isset($text)){
foreach ($text as $ty1 => $value){
$text1[] = $text[$ty1]['field'];
$db[] = $text[$ty1]['field'];

$heading=$text[$ty1]['heading'];
$rt=$text[$ty1]['field'];


//$photo1=db_fetch($db_settings4);

//foreach($photo1 as $photoitem){
//$photo=$photoitem[$rt];
//}

//}
//}

?>


              
			  
                 
				 <?php if (!isset($text[$ty1]['class'])) { ?>
				 <div class="col-md-6">
				 <?php } 
				 else{ ?>
				<div class="<?php echo $text[$ty1]['class']; ?>">
				 <?php } ?>	 
<h4><?php echo $heading; ?></h4>                    
					 	<input type="file" data-max-file-size="3M" data-allowed-file-extensions="jpg png" 
						class="dropify" name="<?php echo $text[$ty1]['field']."_name"; ?>" id="upload_file_id" 
						/>
					
					


    	</div>	
		
<?php } 

} ?>		

<?php 

if(isset($caption)){
foreach ($caption as $cap1 => $cvalue){
$caption1[] = $caption[$cap1]['field'];
$capdb[] = $caption[$cap1]['field'];

$label=$caption[$cap1]['label'];
$caprt=$caption[$cap1]['field'];


//$photo2=db_fetch($db_settings5);

//foreach($photo2 as $photoitem2){
//$photo2=$photoitem2[$caprt];
//}

?>

		
		
		<?php if (!isset($caption[$cap1]['class'])) { ?>
				 <div class="col-md-6">
				 <?php } 
				 else{ ?>
				<div class="<?php echo $caption[$cap1]['class']; ?>">
				 <?php } ?>
		<div class="form-group">
                        <label class="control-label"><h5><?php echo $caption[$cap1]['label']; ?></h5></label>
						<input type="text" class="form-control input-md" name="<?php echo $caption[$cap1]['field']."_name"; ?>" maxlength="300">
					    <small></small>
					    </div>
					  
					  
					  </div>
		

<?php
}
}	  
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

?>
<p>&nbsp;</p>
<div class="col-md-12 text-center gap-items-5">


                    <button type="reset" class="btn btn-lg btn-label btn-danger" onclick="history.go(-1);">Cancel
					<label><i class="ti-close"></i></label>
					</button>
                    
					<button class="btn btn-lg btn-label btn-success" type="submit" name="add_itembtn" id="subbtn">Insert
					<label><i class="ti-shift-right"></i></label>
					</button>
                    <input type="hidden" name="add_item" value="add_item">
                    <hr class="d-lg-none">
                    

					

				  	  
                
            
				  </div>
			
				  </div>
				  </div>
				 
				  <?php
///////////////////////////////////////////////////////////////////
if(isset($_POST['add_item'])){
	
if(isset($add_new) && $add_new!=0) {

$rt=add_record($settings['add_new_table'],$settings['add_new_ref']);

$lead_id=$rt;	
	
}   
	

$count=count($text1);
$i = 0;
$ret=array_combine($text1, $db);
foreach ($ret as $name => $col){
$i++;
//echo "here".$i;
	
$imgsettings=array(
'file_name'=>$_FILES[$name."_name"]['name'],
'uploaded_tmp'=>$_FILES[$name."_name"]['tmp_name'],
'site_name_prefix'=>$suffix.'-'.$name."-",
//'thumbs_folder'=>'photos',
'thumbs_folder'=>$path['thumbs_folder'],
'record_id'=>$lead_id,
'slip_no'=>$lead_id."-",
'table'=>$table,
'img_col'=>$col,
'id_col'=>id_col,
//'upload_dir'=>photo_folder,
'upload_dir'=>$path['upload_dir'],
//'og_dir'=>photo_folder_og,
'og_dir'=>$path['og_dir'],
'original'=>'1',
//'thumbs_req'=>'1',
'thumbs_req'=>$path['thumbs_req'],
//'redirect'=>'/view/deals/',
//'create_icons'=>'1'
'create_icons'=>$path['create_icons']
);	

makethumb($imgsettings);

$posted=$_POST[$caption[$cap1]['field']."_name"];
$posted=i2d_secured_input($posted);

$files=array(
$caption[$cap1]['field']=>$posted,
'Status'=>'Active'
);

$gf=db_editdata($table,id_col,$files,$lead_id);

}

app_redirect_adv($redirect);

}



?>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>

</div>

<?php
 
} 
}
/////////////////////////// function ends /////////////////////////////////
//////////////////////////// HTML FUNCTION ENDS (c) i2d Technologies ///////////////////////////////////////

























?>
