Category Archives: Joomla

Logout link for Joomla 1.5, 2.5

Joomla 1.5 Logout Link

<?php
$returnURL = base64_encode(JURI::root() . “”);
$user =& JFactory::getUser();
echo ‘Hi,’.$user->username;
?>

<a href=”index.php?option=com_user&task=logout&return=<?php echo $returnURL; ?>”>
<input  type=”button” name=”Submit” value=”Logout”></a>

Joomla 2.5 Logout Link

<a href=”index.php?option=com_users&task=user.logout&<?php echo JUtility::getToken(); ?>=1″>
<input  type=”button” name=”Submit” value=”Logout”>
</a>

 

Edit profile link for joomla 2.5

<a href=”<?php echo JRoute::_(‘index.php?option=com_users&view=profile&layout=edit’)?>” title=”My Profile”>Edit Profile</a>

 

Advertisements

how to access Joomla 2.5!: Classes for Accessing Database for mysql

For select Query:

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('field1,fieldn');
$query->from('#__tablename');
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results){
    foreach($results as $result) 
    {
        //$result->field1
        //$result->fieldn;
    }
}
 
For insert Query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert('#__tablename');
$query->set("field1='value1', fieldn='valuen'");
$db->setQuery($query);
$db->query();
To get the last insert id, use:
$db->insertid();


For udate Query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update('#__tablename');
$query->set("field1='value1', fieldn='valuen'");
$query->where("fieldx='valuex'");
$db->setQuery($query);
$db->query();
 
For simple query: 
$db = JFactory::getDbo();
$query = "<YOUR QUERY>";
$db->setQuery($query);
$db->query();

For fetch multiple row:

Your Query goes here
$items = $db->loadObjectList();


For fetch Single row:

Your Query goes here
$book_item = $db->loadObject();


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));

}

 

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)

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!.

joomla store value Using the JTable Class

The first step is to extend the JTable class with your new table class in table folder:

class TableRestaurant extends JTable 
   { 
   var $id = null; 
   var $name = null; 
   var $address = null; 
   var $comments = null; 
   var $comment_date = null;
   var $published = null; 
   function __construct(&$db) 
      {
      parent::__construct( '#__restaurant', 'id', $db );
      } 
   }

To include the file, place this line in your extension's source code (use com_nameofyourcomponent in place of com_restaurant):
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_restaurant'.DS.'tables');
To get an instance of the object, use this code:
$row =& JTable::getInstance('restaurant', 'Table');

In a model class (extends JModel) you can also use:

$row =& $this->getTable('restaurant');

Updating is as simple as setting the row values in this manner.

$row->name = 'ashwin';
$row->address = 'test address';
$row->comments = 'Open Source Developer';
// Save results
$row->store();

Notice that the $row object of type TableRestaurant has all the columns we defined above.  When we call the store() method these rows are automatically stored in the database.  Our code above assumes that the id field will be auto-incremented on store(), so we are not providing a value for this field (as well as comment_date and published).  So this code will store a new value for this restaurant (essentially running and 'INSERT' query for us).  If we had provided value for the id field, the store() method would have instead 'UPDATE' query.

How can show tree list (recursive) in joomla for custome component?

1. First in Your component module class with function

function getTotal()
{
if (empty($this->_total))
{
$query = $this->_buildQuery();
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}

replace with function
function getData()
{
if (empty($this->_data))
{
$query = $this->_buildQuery();
$this->_data = $this->_getList($query);
$children = array ();
// first pass – collect children
foreach ( $this->_data as $v ) {
$pt = $v->parent_id;
$list = @$children [$pt] ? $children [$pt] : array ();
array_push ( $list, $v );
$children [$pt] = $list;
}
// second pass – get an indent list of the items
$list = JHTML::_ ( ‘menu.treerecurse’, 0, ”, array (), $children, 9999, 0, 0 );
$this->_data = array_slice ( $list, $this->getState(‘limitstart’), $this->getState(‘limit’));
}
return $this->_data;
}

2. In View (folder) Your default view listing
for ($i=0, $n=count( $this->items ); $i items[$i];
//category name print like
treename ; ?>
}

3. In Your Form view

add code for recursive function like for example

$value)
{
$stateslist1[] = JHTML::_(‘select.option’, $key, $value, ‘id’, ‘title’ );
}
$stateslist2 = array_merge( $stateslist,$stateslist1 );
$lists[‘id’] = JHTML::_(‘select.genericlist’, $stateslist2, ‘parent_id’, ‘class=”inputbox” size=”1″ style=”width:200px;”‘,’id’, ‘title’, $this->category->parent_id );

echo $lists[‘id’];

function getTree($id=0)
{
static $cates = array();
static $times = 0;
$times++;
$db =& JFactory::getDBO();
$query = ‘SELECT * FROM #__dir_categories where parent_id=’.$id;
$db->setQuery( $query );
$rowdata = $db->loadObjectList();
foreach($rowdata as $val)
{
$cates[$val->id] = str_repeat(“… “,$times-1).$val->title;
getTree($val->id);
}
$times=$times-1;
return $cates;
}
?>

How can write insert, update and delete query in joomla

for insert

$db            = & JFactory::getDBO();

$ins = new stdClass();
$ins->id = NULL;  // here id is auto increment id and primary key

$ins->table_field =$post[‘table_field’]; // table field name

…………………..

……………………..

if($db->insertObject(“jos_tablename”, $ins, ‘id’)){
unset($db);
}else{
echo $db->stderr();
}

for update

$ins->id = NULL;  // here id is  post/get retrieve value

$ins->table_field =$post[‘table_field’]; // table field name

…………………..

……………………..

if($db->updateObject(“jos_tablename”, $ins, ‘id’)){
unset($db);
}else{
echo $db->stderr();
}

foe delete

$db       =& JFactory::getDBO();
$query = ‘DELETE FROM jos_tablename’;
$db->setQuery( $query );
$db->query();