Friday 5 October 2018

Javascript - refresh parent window when closing child window

var win = window.open("URL", '_blank');
var timer = setInterval(function () {
if (win.closed) {
 clearInterval(timer);
window.location.reload();
// Refresh the parent page
 }
 }, 1000);
 }

Wednesday 22 August 2018

Ckeditor add force download option in dialog

CKEDITOR.on( 'dialogDefinition', function( evt ) {
   var dialog = evt.data;

   if ( dialog.name == 'link' ) {
       // Get dialog definition.
       var def = evt.data.definition;         
       // Add some stuff to definition.
       
       
       
       var infoTab = def.getContents( 'info' );
       
       infoTab.add( {
type: 'checkbox',
id: 'download',
requiredContent: 'a[download]',
label: "Force Download",
setup: function( data ) {
if ( data.download !== undefined )
this.setValue( 'checked', 'checked' );
},
commit: function( data ) {
if ( this.getValue() ) {
data.download = this.getValue();
}
}
});

   }
} );

CKEDITOR.replace( 'editor' );

Easypaginate integration


<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="jquery.easyPaginate.js"></script>
<link href="http://localhost/es/bootstrap.css" rel="stylesheet" />

<style type="text/css">
/* Cosmetic only */
#easyPaginate {width:300px;}
#easyPaginate div {display:block;margin-bottom:10px;}
.easyPaginateNav a {padding:5px;}
.easyPaginateNav a.current {font-weight:bold;text-decoration:underline;}
</style>
<a href="http://192.168.1.66/temp.php"><h1>Home</h1></a><br><br><br><hr>
<div id="easyPaginate">
<?php
for($i=1;$i<=100;$i++)
{
?>
<div class='cool' style='border:1px solid red;width:100%;height:20px;'>
<div style='color: #FFF;background: green;width: 40%;float: left;height:auto;'>
<strong><?=$i?></strong>
</div>
<div style='color: #000;background:  yellow;width: 40%;float: right;height:auto;'>
<strong><?=$i?></strong>
</div>
</div>
<?php
} ?> 
</div>
<div class="easyPaginate1" style='border:1px solid red;width:100%;height:20px;'>
</div>

<script type='text/javascript'>
// input array contain some elements.
var array = ['10', '20', '30', '40', '50'];
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = array.indexOf("10");
// Printing desired values.
console.log(a);



$(function() {
$('#easyPaginate').easyPaginate({
paginateElement: 'div.cool',
elementsPerPage: 2,
firstButtonText : '',
lastButtonText: '',
prevButtonText:'',
nextButtonText : '→',
items:100,
edges:2,
});
var nav  = $('.easyPaginateNav').clone(true,true);
$(".easyPaginateNav").remove();
nav.prependTo('div.easyPaginate1');

});
</script>

JS cookie handling

<script type='text/javascript'>
function setCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return false;
}
function eraseCookie(name) { 
    document.cookie = name+'=; Max-Age=-99999999;'; 
}
setCookie('TEST','Goal',7);
alert(getCookie('TEST'));
eraseCookie('TEST');
alert(getCookie('TEST'));
</script>

Wednesday 25 July 2018

Cake php 64bit encrypt and decrypt

/*
 * Encrypt and base64 encode
 */
$encryptKey = "TESDEMO";
$secret = Security::cipher('1', $encryptKey);
$secret64Enc = base64_encode($secret);

// Decrypt your text
$secret64Dec = base64_decode($secret64Enc);
$nosecret = Security::cipher($secret64Dec,$encryptKey);
echo "$secret64Enc--------------$nosecret" ;
echo "<br>";

Friday 8 June 2018

Import Large size of databse facing errors ERROR 1118 (42000) , ERROR 2006 (HY000) & ERROR 1118 (42000)

Your  path xampp\mysql\bin\my.ini 

# ERROR 2006 (HY000) at line 1995: MySQL server has gone away

max_allowed_packet = 256M

# ERROR 1118 (42000) at line 1995: The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size.

innodb_log_file_size = 256M

# ERROR 1118 (42000) at line 1807: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline

max_allowed_packet=1G
innodb_file_per_table=1
innodb_file_format=Barracuda

Once values changed restart you xampp & Mysql servers

Thursday 31 May 2018

Image Resize and save by using GD function and Percentage based

<?php
$filename = 'test.jpg';
$percent = .5;
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$ourFileName = "newtest.jpg";
imagejpeg($thumb, $ourFileName);
imagedestroy($thumb);
?>

Wednesday 23 May 2018

How to create custom log in cakephp?

1. Add bootstrap for this in below

CakeLog::config('customlog', array('engine' => 'File'));

2. Create log message in custom logfile

CakeLog::write('customlog', 'myArray');

Check now you log directory once created

Friday 18 May 2018

Mysql dump in terminal mode

For taking Dump : mysqldump -u username -p test> test>

Then Enter Password if prompts for password


For Restoring Dump :  mysql -u username -p test> < test>

Then Enter Password if prompts for password

Now I have restored the dump. So no need to take dump and restore.

scp -r <username>@<domainname/ip address>:/<file path>  <destination path>


For Windows
mysql.exe -uroot -p dbname < dump
you need to do this in xampp/mysql/bin/ path

Compress & Extract Linux commands

tar -zcvf archive.tar.gz directory/    => compressing folder
tar -zxvf archive.tar.gz                   => extracting the compressed file

PNG to Jpeg in PHP using GD library


<?php
function png2jpg($originalFile, $outputFile, $quality) {
    $image = imagecreatefrompng($originalFile);
    imagejpeg($image, $outputFile, $quality);
    imagedestroy($image);
}
png2jpg("img/test.png", "img/".time().".jpg", 100);
if ($handle = opendir('img/')) {
	$i=0;
   while (false !== ($entry = readdir($handle))) {
      if ($entry != "." && $entry != "..") {
         echo "<img src='img/$entry' width=150 height=100>    ";
			if($i%10==0 && $i!=0){
				echo "<br>";
			}
			$i++;
      }
   }
   closedir($handle);
}
?>

Multple checkbox selected or not

<script type="text/javascript" src='jquery.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$('#extend_auto_expired').click(function(){
$("input[type=checkbox]:checked").each(function() {
alert( $(this).val() );
});
});
});
</script>
<center>
<form name='ck'>
<?php
for($r=0; $r<10;$r++){
echo "<input type='checkbox' name='t[]' value='$r'>$r<br>";
}
?>
<input type="button" id="extend_auto_expired" value="Extend auto expired" class="buttongreen" name="Submit">
</form>
<center>

How to find disk space in PHP?

<?php
$bytes = disk_total_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
//echo $bytes . '<br />';
$total = sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class];

$bytes = disk_free_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
//echo $bytes . '<br />';
$free = sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class];

   $used = (float)$total-(float)$free;
echo "Total Space : $total <br/> Available Space : $free <br/> Used Space : $used ".$si_prefix[$class];
?>

Difference between two dates in PHP

<?php
$date1 = "2015-01-23 00:20";
$date2 = "2015-01-23 05:30";
$seconds = strtotime($date2) - strtotime($date1);
$days    = floor($seconds / 86400);
$hours   = floor(($seconds - ($days * 86400)) / 3600);
$minutes = floor(($seconds - ($days * 86400) - ($hours * 3600))/60);
$seconds = floor(($seconds - ($days * 86400) - ($hours * 3600) - ($minutes*60)));
echo "$days Days, $hours Hrs $minutes mins $seconds sec";
?>

Difference between two dates in Javascript with demo


Enter values in mm/dd/yy hh:mm:ss format
First date and time
Second date and time
Result
In (decimal) hours
In (decimal) minutes
In seconds

Code:
<script type='text/javascript'>
function p (i){
return Math.floor(i / 10) + "" + i % 10;
}
function trunc (i){
var j = Math.round(i * 100);
return Math.floor(j / 100) + (j % 100 > 0 ? "." + p(j % 100) : "");
}
function calculate (form){
var date1 = new Date(form.date1.value);
alert(form.date1.value+"\n\n"+date1)
var date2 = new Date(form.date2.value);
var sec = date2.getTime() - date1.getTime();
if (isNaN(sec)){
alert("Input data is incorrect!");
return;
}
if (sec < 0){
alert("The second date ocurred earlier than the first one!");
return;
}
var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;
form.result_h.value = trunc(sec / hour);
form.result_m.value = trunc(sec / minute);
form.result_s.value = trunc(sec / second);
var days = Math.floor(sec / day);
sec -= days * day;
var hours = Math.floor(sec / hour);
sec -= hours * hour;
var minutes = Math.floor(sec / minute);
sec -= minutes * minute;
var seconds = Math.floor(sec / second);
form.result.value = days + " day" + (days != 1 ? "s" : "") + ", " + hours + " hour" + (hours != 1 ? "s" : "") + ", " + minutes + " minute" + (minutes != 1 ? "s" : "") + ", " + seconds + " second" + (seconds != 1 ? "s" : "");
}
</script>
<form id="form">
<table cellpadding="3">
<tr>
<td colspan="2" align="center">Enter values in <font color="#800000">mm/dd/yy hh:mm:ss</font> format</td>
</tr>
<tr>
<td>First date and time</td>
<td><input type="text" name="date1" /></td>
</tr>
<tr>
<td>Second date and time</td>
<td><input type="text" name="date2" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" name="submit" value="Calculate" onclick="calculate(this.form)" /></td>
</tr>
<tr>
<td>Result</td>
<td colspan="2"><input type="text" name="result" readonly="readonly" size="40" /></td>
</tr>
<tr>
<td>In (decimal) hours</td>
<td colspan="2"><input type="text" name="result_h" readonly="readonly" /></td>
</tr>
<tr>
<td>In (decimal) minutes</td>
<td colspan="2"><input type="text" name="result_m" readonly="readonly" /></td>
</tr>
<tr>
<td>In seconds</td>
<td colspan="2"><input type="text" name="result_s" readonly="readonly" /></td>
</tr>
</table>

Difference between in Mysql & Mango DB


Cut - copy - paste


<script type='text/javascript' src='http://code.jquery.com/jquery-1.11.3.min.js'></script>
<script type='text/javascript'>
$(document).ready(function(){	
   $('#test').bind("cut copy paste",function(e) {	
       e.preventDefault();	
   });	
});	
</script>
<input type="text" id='test' placeholder="Hello Text"/>

Calculate Number of days Between two dates except saturday & sunday or week off in PHP script


<?php
$strt_date = date_create('2015-m-1');
$end_date = date_create(date('Y-m-d'));
date_sub($strt_date, date_interval_create_from_date_string('1 day'));
$interval = date_diff($strt_date, $end_date);
$num=$interval->format('%a');
$x=1;
for($i=0;$i<$num;$i++){
  date_add($strt_date, date_interval_create_from_date_string('1 day'));
  $next_day=date_format($strt_date, 'd-m-Y');
  echo "<br>";
  $new_date = new DateTime($next_day);
  $weeknum=$new_date->format('w');
  if(($weeknum!=0)&&($weeknum!=6)){
	 echo "$x. not a holiday :$weeknum  $next_day ";
	 $x++;
  }
}
?>

Friday 23 March 2018

API for Item Adjustments in Zoho Inventory


API for Item Adjustments in Zoho Inventory :

1. Inventory Adjustment Creation
	Method: POST
	Link : https://inventory.zoho.com/api/v1/inventoryadjustments
	Parameters required: authtoken, organization_id
	JSONString:
		{
			"line_items": [
				{
					"item_id": "{item_id}",
					"name": "Black",
					"description": "",
					"quantity_adjusted": "6",
					"unit": "pcs",
					"adjustment_account_id": "{adjustment_account_id}",
					"warehouse_id": "{warehouse_id}"
				}
			],
			"date": "2017-01-09",
			"reason": "Inventory    Revaluation",
			"reference_number": "",
			"adjustment_type": "quantity"
		}
	{adjustment_account_id} is taken from the purchase_account_id node of item details.
	item_id is the unique identifier of the item to be adjusted.

2. Fetching list of Inventory Adjustments
	Method: GET
	Link : https://inventory.zoho.com/api/v1/inventoryadjustments
	Parameters required: authtoken, organization_id
3. Fetching details of an Inventory Adjustment 
	Method: GET
	Link : https://inventory.zoho.com/api/v1/inventoryadjustments/{inventory_adjustment_id}
	Parameters required: authtoken, organization_id
4. Inventory Adjustment Deletion
	Method: DELETE
	Link : https://inventory.zoho.com/api/v1/inventoryadjustments/{inventory_adjustment_id}
	Parameters required: authtoken, organization_id
	Replace {inventory_adjustment_id} with the ID created for inventory adjustment

Masters API GET method :

https://inventory.zoho.com/api/v1/inventoryadjustments/editpage?organization_id={organization_id}&authtoken={authtoken}