Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Developers' Forum

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #11  
Old 16th September 2010, 15:13
bruno_floyd bruno_floyd is offline
Member
 
Join Date: Aug 2010
Posts: 73
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Oh I see...

Both echo or print_f doesn't work. How can I print values on the screen? That would be much easier for me here...

Reply With Quote
Sponsored Links
  #12  
Old 23rd September 2010, 19:41
bruno_floyd bruno_floyd is offline
Member
 
Join Date: Aug 2010
Posts: 73
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Any ideia till?

i'm trying to get a SUM(field) from my DB and show it on my indicacao_list.htm using this:

<td class="tbl_col_valor_contrato"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="valor_comissao"}</a></td>
<td class="tbl_col_total_valor_comissionado"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="total_valor_comissionado"}</a></td>

How can I simply get this calculated value and show there? Where do I have to write de SQL sentence? on my indicacao.tform.php?

Thanks a lot!!!
Reply With Quote
  #13  
Old 23rd September 2010, 21:36
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,995
Thanks: 840
Thanked 5,648 Times in 4,458 Posts
Default

The tform files are only for the edit forms and not the lists. The lists are defined in the .list.php files, but this file contains only the definition and not the the actual list generation.

If you want to create custom list colums, you have to extend a function in the list library. For an example see e.g. the mail_user_list.php file in the mail module. As you want to calculate a specific value in every row, you will have to extend the prepareDataRow($rec) function of the listform_actions.inc.php class.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #14  
Old 24th September 2010, 16:07
bruno_floyd bruno_floyd is offline
Member
 
Join Date: Aug 2010
Posts: 73
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Am I getting right?

This is on my indicacao_list.php:

class list_action extends listform_actions {

public function prepareDataRow($rec) {

global $app, $sql_comissao, $sql_nao_comissao;

$sql_comissao = "SELECT SUM(valor_comissao) FROM indicacao WHERE status = '0' AND indicou_id = ".$_SESSION['s']['user']['userid'];
$sql_nao_comissao = "SELECT SUM(valor_comissao) FROM indicacao WHERE status = '1' AND indicou_id = ".$_SESSION['s']['user']['userid'];

$soma = $app->db->queryOneRecord($sql_comissao);
$soma_nao = $app->db->queryOneRecord($sql_nao_comissao);

$app->tpl->setVar('total_valor_comissionado', $soma);
$app->tpl->setVar('total_valor_nao_comissionado', $soma_nao);

}
}

But it didnt worked out yet.
Reply With Quote
  #15  
Old 24th September 2010, 16:49
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,995
Thanks: 840
Thanked 5,648 Times in 4,458 Posts
Default

Looks good. But you missed to call the parent function to add the data that gets normally added. Try to add a call to parent:repareDataRow($rec); at the end of the function:

Code:
class list_action extends listform_actions {

public function prepareDataRow($rec) {

global $app, $sql_comissao, $sql_nao_comissao;

$sql_comissao = "SELECT SUM(valor_comissao) FROM indicacao WHERE status = '0' AND indicou_id = ".$_SESSION['s']['user']['userid'];
$sql_nao_comissao = "SELECT SUM(valor_comissao) FROM indicacao WHERE status = '1' AND indicou_id = ".$_SESSION['s']['user']['userid'];

$soma = $app->db->queryOneRecord($sql_comissao);
$soma_nao = $app->db->queryOneRecord($sql_nao_comissao);

$app->tpl->setVar('total_valor_comissionado', $soma);
$app->tpl->setVar('total_valor_nao_comissionado', $soma_nao);

parent::prepareDataRow($rec);

}
}
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #16  
Old 24th September 2010, 17:10
bruno_floyd bruno_floyd is offline
Member
 
Join Date: Aug 2010
Posts: 73
Thanks: 1
Thanked 2 Times in 2 Posts
Default

Well I added and i still can't get a value...

my whole indicacao_list.php its like this:
Code:
<?php

require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');

//* Path to the list definition file
$list_def_file = "list/indicacao.list.php";

//* Check permissions for module
$app->auth->check_module_permissions('indicacao');

//* Loading the class
$app->uses('listform_actions');

class list_action extends listform_actions {

    public function prepareDataRow($rec) {

        global $app, $sql_comissao, $sql_nao_comissao;

        $sql_comissao = "SELECT SUM(valor_comissao) FROM indicacao WHERE status = '0' AND indicou_id = " . $_SESSION['s']['user']['userid'];
        $sql_nao_comissao = "SELECT SUM(valor_comissao) FROM indicacao WHERE status = '1' AND indicou_id = " . $_SESSION['s']['user']['userid'];

        $soma = $app->db->queryOneRecord($sql_comissao);
        $soma_nao = $app->db->queryOneRecord($sql_nao_comissao);

        $app->tpl->setVar('total_valor_comissionado', $soma);
        $app->tpl->setVar('total_valor_nao_comissionado', $soma_nao);

        parent::prepareDataRow($rec);
    }

}

//* Optional limit
//$app->listform_actions->SQLExtWhere = "indicado_id = ".$_SESSION['s']['user']['userid'];
//* Start the form rendering and action ahndling
$app->listform_actions->onLoad();
?>
And I use the 2 variables I created, on my indicacao_list.htm as I showed you... {tmpl_var name="total_valor_comissionado"} , {tmpl_var name="total_valor_nao_comissionado"}

Is there anything missing?
Reply With Quote
  #17  
Old 24th September 2010, 18:17
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,995
Thanks: 840
Thanked 5,648 Times in 4,458 Posts
Default

1) Is the list shown and just these two values are missing?
2) Did you add these two values in the template within the loop or outside the loop?
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #18  
Old 24th September 2010, 18:24
bruno_floyd bruno_floyd is offline
Member
 
Join Date: Aug 2010
Posts: 73
Thanks: 1
Thanked 2 Times in 2 Posts
Default

- The list is shown, but only these values that I inserted with my form.

- I inserted inside the loop:

Code:
... 
<td class="tbl_col_total_valor_comissionado"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="total_valor_comissionado"}</a></td>
            <tmpl_if name="is_admin">
              <div class="buttons icons16">    
                <a class="icons16 icoDelete" href="javascript: del_record('indicacao/indicacao_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"><span>{tmpl_var name='delete_txt'}</span></a>
              </div>
            </tmpl_if>
            </td>
          </tr>
          </tmpl_loop>
Reply With Quote
  #19  
Old 24th September 2010, 19:27
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 36,995
Thanks: 840
Thanked 5,648 Times in 4,458 Posts
Default

Ok. I read trough the sources of the class again and it might be that we have to add the fields in the .lis.php file of that list too (the file where the list fields are defined). Add there this code:

Code:
$liste["item"][] = array(	'field'		=> "total_valor_comissionado",
							'datatype'	=> "VARCHAR",
							'formtype'	=> "TEXT",
							'op'		=> "like",
							'prefix'	=> "%",
							'suffix'	=> "%",
							'width'		=> "",
							'value'		=> "");

$liste["item"][] = array(	'field'		=> "total_valor_nao_comissionado",
							'datatype'	=> "VARCHAR",
							'formtype'	=> "TEXT",
							'op'		=> "like",
							'prefix'	=> "%",
							'suffix'	=> "%",
							'width'		=> "",
							'value'		=> "");
and then change in your code the lines:

$app->tpl->setVar('total_valor_comissionado', $soma);
$app->tpl->setVar('total_valor_nao_comissionado', $soma_nao);


with:

$rec['total_valor_comissionado'] = $soma;
$rec['total_valor_nao_comissionado'] = $soma_nao;
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #20  
Old 24th September 2010, 19:52
bruno_floyd bruno_floyd is offline
Member
 
Join Date: Aug 2010
Posts: 73
Thanks: 1
Thanked 2 Times in 2 Posts
 
Default

It didnt work till...

I added the 2 itens on my .list.php and changed to

$rec['total_valor_comissionado'] = $soma;
$rec['total_valor_nao_comissionado'] = $soma_nao;

but the value doesn't show.

I tested the SQL sentence and it's working... is there any way to print values of variables on the screen?

I'm really sorry to disturb you till, but this is really importante for me... thanks again!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freeradius and Mysql uvstudios HOWTO-Related Questions 4 19th February 2014 13:11
Proftpd + MySQL virtual users, can't connect geekman HOWTO-Related Questions 28 27th September 2010 19:03
FreeRadius + MySQL working, but I don't know how to customise SQL queries awe Installation/Configuration 4 5th April 2010 00:28
ffmpeg Video support for ubuntu 7.10 [suphp-ispconfig] amaurib Installation/Configuration 13 16th February 2010 18:26
Webmin docs missing namit Server Operation 11 5th January 2006 10:51


All times are GMT +2. The time now is 14:53.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.