How to creat widget wordpress from PHP code ?
-
I have an old website running with php. In such a calculation module loans. Now I want to move it through the widget wordpress, but I dont know how to do that ? Hope you can support me !
This code here:
<?php /** * @version $Id: block_quote.php 1 2011-05-27 15:42 H-Minh $ * @package vFramework.block.quote * @copyright (C) 2011. All rights reserved. * @license Commercial */ defined('V_LIFE') or die('v'); function blk_calculation($p = '') { global $tpl, $db, $alt, $cfg; if (isset($cfg['~ajax']) && $cfg['~ajax']) { vRequest::vars($x,array( 'price:string', 'ptram:int', 'month:int', 'pay:int' )); $x['price'] = str_replace(array('.',','),array('',''),$x['price']); block_calculation_result($x); die(); } $sel_price = array(0 => $tpl->l['CALCULAR_PREV_PRICE'],1 => '1,000,000 VND',2 => '5,000,000 VND',3 => '10,000,000 VND',4 => '15,000,000 VND',5 => '20,000,000 VND'); $sel_ptram = array(0 => $tpl->l['CALCULAR_PREV_PTRAM'],/*1 => '20%',*/ 2 => '30%',3 => '40%',4 => '50%',5 => '60%',6 => '70%'); //$sel_month = array(0 => $tpl->l['CALCULAR_PREV_THOIHAN'],1 => '9',2 => '12',3 => '15',4 => '18',5 => '24',6 => '36'); $sel_month = array(0 => $tpl->l['CALCULAR_PREV_THOIHAN'],1 => '24',2 => '36'); $sel_pay = array(0 => $tpl->l['CALCULAR_PAYMENT'],1 => $tpl->l['CALCULAR_TW'],2 => $tpl->l['CALCULAR_CD']); $html = '<div '.$tpl->css($p['prop']['css'], 'block').'>'. (($p['title']{0} == '~') ? '' : '<'.$p['prop']['tag'].' class="vf_btitle">'.$p['title'].'</'.$p['prop']['tag'].'>'); $html .= '<div class="preview">'.$tpl->l['CALCULAR_PREV'].'</div>'; $html .= '<div class="desc"> <form action="'.VAR_INDEX.'?'.(($cfg['langs'] > 1 && $alt['lang'] != $cfg['lang']) ? VAR_LANG.'='. $alt['lang'] .'&': '').VAR_PAGE.'=null&'.VAR_SECTION.'=calculation" name="calcularSearch" method="post" target="maillist" onSubmit="return check_popup_cal(\'\',\'maillist\', 600,350);"> <p style="color:#FFF;"><input type="text" name="price" id="price" value="'.$tpl->l['CALCULAR_TITLE2'].'" onKeyUp="this.value = FormatNumber(this.value);" onfocusout="ConvertPriceText(this.value)" onblur="ConvertPriceText(this.value)"></p> <p>'.vForm::select($sel_pay,'pay','','','','').'</p> <p><input type="submit" value="'.$tpl->l['CALCULAR_RESULT'].'" /></p> </form> <script language="javascript"> $(function(){ $("#price").blur(function(){if(!$(this).val()) $(this).val("'.$tpl->l['CALCULAR_TITLE2'].'")}); $("#price").focus(function(){ if($(this).val() == "'.$tpl->l['CALCULAR_TITLE2'].'") $(this).val("")}); }) function check_popup_cal(the_url, targetName, the_width, the_height){ var price = window.document.calcularSearch.price.value; if(parseInt(price)==0 || price==\''.$tpl->l['CALCULAR_TITLE2'].'\'){ alert(\''.$tpl->l['CALCULAR_ERROR2'].'\'); window.document.calcularSearch.price.focus(); return false; }else{ left_val = (the_width > 0) ? (screen.width - the_width)/2 : 0; top_val = (the_height > 0) ? (screen.height - the_height)/2 - 30 : 0; if (top_val < 0){ top_val = 0; } window.open(the_url, targetName, "menubar=no, toolbar=no, scrollbars=yes, resizable=yes, width="+ the_width +", height="+ the_height +", top="+ top_val +", left="+ left_val); } } </script> </div></div>'; $tpl->theme('block', '', $html); } function block_calculation_result($x){ global $tpl; $x['mode'] = $x['pay']==1 ? 2 : 1; $x['insurance'] = 0; if($x['mode']==1){ if(!$x['insurance']){ // STATUS NO // % $array[0] = array('0.2','9','12','15','18','24','36');//20% $array[1] = array('0.3','9','12','15','18','24','36');//30% $array[2] = array('0.4','9','12','15','18','24','36');//40% $array[3] = array('0.5','9','12','15','18','24','36');//50% $array[4] = array('0.6','9','12','15','18','24','36');//60% $array[5] = array('0.7','9','12','15','18','24','36');//70% }else{ // STATUS YES // % 6 9 12 15 18 24 36 $array[0] = array('0.2','0.1616','0.1168','0.0948','0.0819','0.0736','0.0638','0.0556');//20% $array[1] = array('0.3','0.1414','0.1022','0.0829','0.0717','0.0644','0.0558','0.0486');//30% $array[2] = array('0.4','0.1212','0.0876','0.0711','0.0614','0.0552','0.0478','0.0417');//40% $array[3] = array('0.5','0.1010','0.0730','0.0592','0.0512','0.0460','0.0399','0.0347');//50% $array[4] = array('0.6','0.0808','0.0584','0.0474','0.0409','0.0368','0.0319','0.0278');//60% $array[5] = array('0.7','0.0606','0.0438','0.0355','0.0307','0.0276','0.0239','0.0208');//70% } $col=7; }else{ //$array[0] = array('0.2','0.1146','0.0924','0.0793','0.0707','0.0603','');//6 $array[0] = array('0.3','9','12','15','18','24');//9 $array[1] = array('0.4','9','12','15','18','24');//12 $array[2] = array('0.5','9','12','15','18','24');//15 $array[3] = array('0.6','9','12','15','18','24');//18 $array[4] = array('0.7','9','12','15','18','24');//24 $col=6; } $htmlList = ''; for($i=0;$i<count($array);$i++){ $j=0; while($j<$col){ $htmlList .= '<tr><td align="center" class="detail" width="100" height="30px">'.($array[$i][0]*100).'%'.'</td>'; for($k=0;$k<$col;$k++){ if($j<$col){ if($j>0){ if($x['mode']==1){ $ptram = 0.694504113790012; $luythua = pow((1+$ptram/12),$array[$i][$j]); }else{ $ptram = 0.786241178451277; $luythua = pow((1+$ptram/12),$array[$i][$j]); } $resul_lt = ($luythua/($luythua-1)); $prices = (($x['price']-($x['price']*$array[$i][0]))*$ptram/12*$resul_lt); } $value = $j>0 ? number_format($prices) : number_format($x['price']*$array[$i][$j]); $htmlList .= '<td align="center" bgcolor="#FFFF99" class="mainText2">'.$value.'</td>'; } $j++; } $htmlList .= '</tr>'; } } $html ='<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <link rel="stylesheet" href="'.URL_THEME.'css/main.css" type="text/css" /> </head><body>'; $html .= '<div><table border="0" cellpadding="2" cellspacing="1" bgcolor="#E2E2E2" class="mainTexttt"> <tr><td width="61"><strong>'.$tpl->l['PROD_PRICE'].':</strong></td><td width="122" class="newsAuthor">'.number_format($x['price']).' VND</td></tr> </table></div> <table width="100%" cellpadding="3" cellspacing="0" class="recordTable" > <tr> <td colspan="2" align="left" class="detail"> </td> <td colspan="'.($x['mode']==1 ? 6 : 5).'" align="center" class="galleryOther"><strong>'.$tpl->l['CALCULAR_MONTH'].'</strong></td> </tr> <tr> <td colspan="2" align="center" class="detail"><strong>'.$tpl->l['CALCULAR_TT'].'</strong></td> <td align="center" class="paytime">9</td> <td align="center" class="paytime">12</td> <td align="center" class="paytime">15</td> <td align="center" class="paytime">18</td> <td align="center" class="paytime">24</td> '.($x['mode']==1 ? '<td align="center" class="paytime">36</td>': '').' </tr>'; $html .= $htmlList.'</table><br>'.$tpl->l['CALCULAR_NOTE2'].''; $html .= '<p class="closew">[<a href="javascript: window.close();">'.$tpl->l['CLOSE_WINDOW'].'</a>]</p></body></html>'; echo $html; die(); } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to creat widget wordpress from PHP code ?’ is closed to new replies.