Monthly Archives: April 2013

column and row wise total calculation with array in php or joomla custom component with jQuery

IN Html section

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&#8221; type=”text/javascript” charset=”utf-8″></script>
<script>

$(document).ready(function() {

$(“input”).click(function(event) {

var id = $(this).closest(‘td’).attr(‘id’);
// alert(id);
var menuid = id.replace(“menu_”,””);
updateTotal(menuid);
});

//    multiplyer
$(“input[name=’multiplyer[]’]”).blur(function(event) {
var value = $(this).val();
//alert(value);
var textid = $(this).attr(‘id’);
var multiplyerid = textid.replace(“multiplyer_”,””);
var parentpriece =  $(‘#parentprice_’+multiplyerid).val();
var ttto = parentpriece*value;
var id = $(this).closest(‘td’).attr(‘id’);
// alert(id);
var menuid = id.replace(“menu_”,””);
//$(‘#totalprice’+menuid).val(ttto.toFixed(2));
$(‘#docfile’+multiplyerid).val(multiplyerid+’_’+ttto+’_’+value);
$(“#”+textid).click();
});

$(“input[name=’multiplyer[]’]”).click(function(event) {
var value = $(this).val();
//alert(value);
var textid = $(this).attr(‘id’);
var multiplyerid = textid.replace(“multiplyer_”,””);
var parentpriece =  $(‘#parentprice_’+multiplyerid).val();
var ttto = parentpriece*value;
var id = $(this).closest(‘td’).attr(‘id’);
// alert(id);
var menuid = id.replace(“menu_”,””);
//$(‘#totalprice’+menuid).val(ttto.toFixed(2));
$(‘#docfile’+multiplyerid).val(multiplyerid+’_’+ttto+’_’+value);
$(‘#multi_’+multiplyerid).text(ttto);
//select_price(multiplyerid,value);
$(“#”+textid).focus();
});

});

function updateTotal(id) {
//alert(id);
var total = 0;
var url = ”;
var multi = ”;
var nnn= 0;
$(“#menu_”+id+” input:checked”).each(function() {
var mainval = this.value;
var priceval = mainval.split(“_”);;
//alert(priceval[2]*priceval[1]);
//alert(priceval[1]);
total += parseFloat(priceval[1]);
url = url + ‘&’ + priceval[0];
multi = multi + ‘&’ + priceval[2];
// var mtot = parseFloat(priceval[1] * priceval[2]);
//alert(mtot);
//nnn = nnn + ‘&’ +( priceval[2]*priceval[1]);
});

//url string
$(‘#docdetailid’+id).val(url);
//total
$(‘#totalprice’+id).val(total.toFixed(2));
// multiplyer
$(‘#docmultiprice’+id).val(multi);
//indivisual total
//$(‘#indprice’+id).val(nnn.toFixed(2));
}

$(document).ready(function () {
$(‘#myLink’).click(function () {
$(“input[id^=’priceid’]”).attr(‘checked’, $(‘#myLink’).is(‘:checked’));
});
});

$(document).ready(function () {
$(‘#sendinvoice’).click(function () {
if (!$(‘input[name=”priceid[]”]’).is(‘:checked’)) {
$(“#invoiceerror”).fadeIn().text(“You must check at least one option.”);
return false;
}

});

});

</script>

<form name=”docf” id=”docf” method=”post” action=”<?php echo JRoute::_(‘index.php?option=com_support&task=file.savaprice’); ?>”>

<table width=”100%” border=”1″ cellspacing=”2″ cellpadding=”2″>

<tr>

<td><input type=”checkbox” id=”myLink”  /></td>

<td><strong>Tax File No </strong></td>

<td>files</td>

<td>Price</td>

</tr>

<?php foreach ($this->items as $i => $item) :?>

<tr>

<td><input type=”checkbox” name=”priceid[]” value=”<?php print $item->id?>” id=”priceid” /></td>

<td><a href=”<?php echo JRoute::_(‘index.php?option=com_support&view=file&id=’ . (int)$item->id); ?>”><b><?php echo $item->wintaxno; ?></b></a>

<input type=”hidden”  value=”<?php echo $item->wintaxno; ?>” name=”wintaxno[]”   />

<input type=”hidden”  value=”<?php echo $taxyear; ?>” name=”taxyear[]”   />

</td>

<td id=”menu_<?php print $item->id?>”>

<?php

$db =& JFactory::getDBO();

$sql = “SELECT * FROM #__support_docdetail where parent_id=0 order by id,parent_id asc”;

//print $sql;

$db->setQuery($sql);

$db->query();

$docdetail = $db->loadObjectList();

foreach($docdetail as $doc):

if($doc->is_parent==”N”):

?>

<input name=”docfile[]” type=”checkbox” value=”<?php print $doc->id ?>_<?php print $doc->price ?>_1″ />

<?php print $doc->doclabel ?>&nbsp;&nbsp;$(<?php print $doc->price ?>)<br />

<?php else:?>

<input name=”docfile[]” type=”checkbox” disabled=”disabled” checked=”checked” value=”<?php print $doc->id ?>_<?php print $doc->price ?>_1″ />

<?php print $doc->doclabel ?><br />

<?php

$db =& JFactory::getDBO();

$sql = “SELECT * FROM #__support_docdetail where parent_id=”.$doc->id;

//print $sql;

$db->setQuery($sql);

$db->query();

$docdetailparent = $db->loadObjectList();

foreach($docdetailparent as $docparent):

?>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name=”docfile[]” type=”checkbox” value=”<?php print $docparent->id ?>_<?php print $docparent->price ?>_0″ id=”docfile<?php print $docparent->id ?>” />

<?php print $docparent->doclabel ?>&nbsp;&nbsp;$(<?php print $docparent->price ?>)&nbsp;&nbsp;x&nbsp;&nbsp;

<input type=”hidden” name=”parent_price[]” id=”parentprice_<?php print $docparent->id ?>” value=”<?php print $docparent->price ?>” />

<input type=”text” name=”multiplyer[]” id=”multiplyer_<?php print $docparent->id ?>” size=”5″ value=”1″ style=”width:30px; text-align:right” /> = <span id=”multi_<?php print $docparent->id ?>”><?php print $docparent->price ?></span><br />

<?php  endforeach; ?>

<?php endif; ?>

<?php endforeach; ?>

<input type=”hidden”  value=”” name=”docdetailid[]” id=”docdetailid<?php print $item->id?>”  />

<input type=”hidden”  value=”” name=”docmultiprice[]” id=”docmultiprice<?php print $item->id?>”  />

<input type=”text”  value=”” name=”indprice[]” id=”indprice<?php print $item->id?>”  />

</td>

<td><input type=”text” readonly=”readonly” value=”” name=”totalprice[]” id=”totalprice<?php print $item->id?>” size=”10″ style=”width:50px;” /></td>

</tr>

<?php endforeach; ?>

<tr><td colspan=”4″ align=”right”><input type=”submit” id=”sendinvoice” value=”Send Invoice” name=”submit” /></td></tr>

</table>

<input type=”hidden” name=”option” value=”com_support” />

<input type=”hidden” name=”task” value=”file.savaprice” />

<?php echo JHtml::_(‘form.token’); ?>

</form>

IN php with save record

public function savaprice()

{
JSession::checkToken() or jexit(JText::_(‘JINVALID_TOKEN’));
//print_r($_REQUEST);

foreach ($_POST[‘doc_id’] as $row=>$id)
{
$id = $id;
$totalprice = $_POST[‘totalprice’][$row];
$multiplyer = $_POST[‘multiplyer’][$row];

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert(‘#__support_docprice’);
$query->set(“file_id='”.$id.”‘, docfile='”.$docfile.”‘,price='”.$totalprice.”‘,multiplyer='”.$multiplyer.”‘,wintaxno='”.$_REQUEST[‘wintaxno’].”‘,taxyear='”.$_REQUEST[‘taxyear’].”‘,federalposition='”.$_REQUEST[‘federalposition’].”‘,stateposition='”.$_REQUEST[‘stateposition’].”‘,taxtotal='”.$_REQUEST[‘taxtotal’].”‘,sut='”.$_REQUEST[‘sut’].”‘,pt='”.$_REQUEST[‘pt’].”‘,mat='”.$_REQUEST[‘mat’].”‘,withfederalposition='”.$_REQUEST[‘withfederalposition’].”‘,withstateposition='”.$_REQUEST[‘withstateposition’].”‘,cityposition='”.$_REQUEST[‘cityposition’].”‘,withcityposition='”.$_REQUEST[‘withcityposition’].”‘ “);
//print $query;
$db->setQuery($query);
$db->query();
}$this->setMessage(JText::_(‘Item saved successfully’));

$this->setRedirect(JRoute::_(‘index.php?com_support&view=files&layout=userlist’, false));

}

 

array value insert table in php with mysql

<form name=’frm’ method=”post” action=’#’>

<input type=”text” name=”id[]” value=””  />

<input type=”text” name=”name[]” value=””  />

<input type=”submit” id=”submit” value=”submit” name=”submit” />

</from>

in php code

foreach ($_POST[‘id’] as $row=>$id)
{

$id = $id;

$name = $_POST[‘name’][$row];

print ‘insert into table name value(‘.$id.’,”‘.$name.'”)’;

}

Joomla dispatcher.php and event.php Fix Errors

There are a few plugins that aren’t compatible with PHP 5.3+ and Joomla 1.5x, and they may show up like the error messages below:

PHP worning for onpreparecontent() for event.php on line 67

PHP worning for plgContentLoadModule() or plgContentEmailCloak() or plgContentPagebreak() for dispatcher.php on line 136

example like :

PHP Warning: Parameter 2 to plgContentJwts::onPrepareContent()expected to be a reference, value given in /libraries/joomla/event/event.php on line 67

PHP Warning: Parameter 2 to plgContentLoadModule() expected to be a reference, value given in /libraries/joomla/event/dispatcher.php on line 136

look for line 136 in dispatcher.php and line 67 in event.php and add this one single line;

$args[1]   = & $args[1];

So your final code (for dispatcher.php) will look like this:

if (function_exists($observer[‘handler’]))
{
$args[1]   = & $args[1];
$result[] = call_user_func_array($observer[‘handler’], $args);
}

and for event.php:

if (method_exists($this, $event)) {
$args[1] = & $args[1];
return call_user_func_array ( array($this, $event), $args );
} else {

Hope this helps!

To solve- Warning: Parameter 1 to modMainMenuHelper::buildXML()

To solve- Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /libraries/joomla/cache/handler/callback.php on line 99

or your joomla top menu is missing

If Your currently site runs on Joomla 1.5. The previous server run PHP 5.2.9 while the new server ran a later version of PHP, 5.3.0. This error is thrown because of the reference type used in the helper file.
Locate modules/mod_mainmenu/helper.php, open the file and change the following line from
function buildXML(&$params)
to
function buildXML($params)

Get last record using php or php with mysql

For example: In this example explode commas and make a linkable every word.

<?php
$ash = ‘1,2,3,4’;
$ashval = explode(‘,’,$ash);

foreach($ashval as $val)
{
print “<a href=”>”.$val.”</a>”;
if($val!=end($ashval))
{
print ‘,’;
}
else
{
print ”;
}

}
?>

OR you can use another method:

<?php
$ash = ‘1,2,3,4’;
$ashval = explode(‘,’,$ash);
$checkval=count($ashval);

foreach($ashval as $val)
{

if($checkval!=$val)
{
$te=”,”;
}
else
{
$te=””;
}
print “<a href=”>”. $val.”</a>”.$te;

}
?>

Custome Joomla administrator Component Ordering and Positions Rows in Model-View-Controller(MVC)

When creating a custom component in Joomla administrator area it is somewhat frequent that one wants the ability to order items based on an order value associated with each row.

The following are the necessary code snippets that allow you to make this possible.

I hope to add a little more explanation.

Please go step by step it’s more help.

sterp 1: in component_name/view/view_name/tmpl/default.php

add following line:
<th width=”8%” align=”left”>
<?php echo JHTML::_(‘grid.sort’,  JText::_(‘Order’), ‘c.ordering’, @$this->lists[‘order_Dir’], @$this->lists[‘order’] ); ?>
<?php echo JHTML::_(‘grid.order’,  $this->items ); ?>
</th>

and
<td>
<span><?php echo $this->pagination->orderUpIcon( $i, ($i > 0), ‘orderup’, ‘Move Up’); ?></span>
<span><?php echo $this->pagination->orderDownIcon( $i, $n, ($i < $n ), ‘orderdown’, ‘Move Down’); ?></span>
<input type=”text” name=”order[]” size=”5″ value=”<?php echo $row->ordering; ?>” style=”text-align: center” />
</td>

Step 2: in component_name/controllers/yourviewcontroller.php

function saveorder( )
{
// Check for request forgeries
$cid        = JRequest::getVar( ‘cid’, array(), ‘post’, ‘array’ );

$model      = $this->getModel(‘yourmodelname’);

if( $model->saveOrder($cid)){
$msg     = JText::_( ‘Ordering save Successfully’ );
$type = ‘message’;

}else{
$msg     = JText::_( ‘Ordering not save’ );
$type = ‘notice’;
}

$link = ‘index.php?option=component_name&view=viewname’;
$this->setRedirect( $link, $msg, $type );
}

function orderup()
{
$cid = JRequest::getVar( ‘cid’, array(0), ‘post’, ‘array’ );
$id = $cid[0];
$model = $this->getModel(‘yourmodelname’);
$model->orderproducts($id,-1);

$msg     = JText::_( ‘Ordering up Successfully’ );

$link = ‘index.php?option=component_name&view=viewname’;
$this->setRedirect( $link, $msg );
}

function orderdown()
{
$cid = JRequest::getVar( ‘cid’, array(0), ‘post’, ‘array’ );
$id = $cid[0];
$model = $this->getModel(‘yourmodelname’);
$model->orderproducts($id,1);
$msg     = JText::_( ‘Ordering down Successfully’ );

$link = ‘index.php?option=component_name&view=viewname’;
$this->setRedirect( $link, $msg );
}

Step 3 : component_name/models/yourviewmodel.php

function saveOrder($cid)
{
JArrayHelper::toInteger($cid);
$total        = count( $cid );
$order        = JRequest::getVar( ‘order’, array(0), ‘post’, ‘array’ );

JArrayHelper::toInteger($order, array(0));
$row  =& $this->getTable(”);
// update ordering values
for( $i=0; $i < $total; $i++ )
{
$row->load( (int) $cid[$i] );
if ($row->ordering != $order[$i])
{
$row->ordering = $order[$i];
if (!$row->store())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
}
}

return true;
}

function orderProducts( $id, $inc )
{
$row  =& $this->getTable(”);
$row->load( $id );
$row->move($inc);
}

Cheers, your Ordering and Positions Rows in component work now!.

ATM Machine logic in PHP.

Q. Consider a hypothetical ATM machine which gives you notes of 10, 20, 50, 100, 500 & 1000 in denomination. If I enter 5,550 Rs. It should give me 5 notes of 1000, 1 note of 500 and 1 note of 50. ATM machines cannot store coins. So, if input amount is something like 1978 then machine should print “Invalid Amount”.

A .

<?php

$amount=$_REQUEST[‘amount’];
$rupees = array(1000,500,100,50,20,10);
$count = array(0,0,0,0,0);

for($i=0;$i<count($rupees);$i++):
if($rupees[$i]<$amount || $rupees[$i]==$amount):
$count[$i]=floor($amount/$rupees[$i]);
$amount=$amount%$rupees[$i];
endif;
endfor;
print ‘<b>Input=</b>’.$_REQUEST[‘amount’].'<br>’;

if($amount==0):
for($i=0;$i<count($count);$i++):

if($count[$i]!=0):

echo ($rupees[$i].’ * ‘.+$count[$i] .’=’. ($rupees[$i]*$count[$i])).'<br>’;
$tot += $rupees[$i]*$count[$i];
endif;
endfor;
print ‘<b>Total=</b>’.$tot;
else:
print ‘<b>Invalid Amount ‘.$_REQUEST[‘amount’].'</b>’;
endif;

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>AIM MACHINE</title>
</head>

<body>
<form name=”frm” method=”post” action=”#”>
Enter value:<input type=”text” name=”amount” value=”” />
<input type=”submit” name=”submit” value=”submit” />
</form>
</body>
</html>