Problems on creating new module

Discussion in 'Developers' Forum' started by bruno_floyd, Aug 26, 2010.

  1. till

    till Super Moderator Staff Member ISPConfig Developer

    use "echo" or for arrays the print_r() command.
     
  2. bruno_floyd

    bruno_floyd New Member

    Ah, ok.. i tried once but i couldnt make it work, but now I know it works.

    Do you have any other idea to help me till?
    Is there another file to be modified?

    I'm kind of lost... =/
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    If you add a echo or print_r for your values in the prepareDataRow function, does they get displayed for every row that was processed?
     
  4. bruno_floyd

    bruno_floyd New Member

    I tried this:

    Code:
    ]
     public function prepareDataRow($rec) {
    
            global $app;
    
            $sql_comissao = "SELECT SUM(valor_contrato) FROM indicacao";
            $sql_nao_comissao = "SELECT SUM(valor_comissao) FROM indicacao";
    		
    		echo "TESTING";
    
            $soma = $app->db->queryOneRecord($sql_comissao);
            $soma_nao = $app->db->queryOneRecord($sql_nao_comissao);
    
           	$rec['total_valor_comissionado'] = $soma;
    		$rec['total_valor_nao_comissionado'] = $soma_nao; 
    		
    		print_r($rec);
    	
            parent::prepareDataRow($rec);
    	}
    
    but nothing is shown. Is it supposed to print?
    Is right to put the variable inside the loop? Cause this field I'm trying to get is a single SUM value from one field of my DB...

    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>
    
     
    Last edited: Sep 27, 2010
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    Ok. Now i see why the code does not get executed. Replace the line:

    $app->listform_actions->onLoad();

    with:

    $my_list = new list_action()
    $my_list->onLoad();
     
  6. bruno_floyd

    bruno_floyd New Member

    till,

    i get this error message:

    Warning: vlibTemplate Warning: Invalid loop structure passed to vlibTemplate::setLoop() (loop name: records). in /usr/local/ispconfig/interface/lib/classes/tpl_error.inc.php on line 83

    is it related to the modification you suggested?
     
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    No. This means that there is a error in the html template. most likely the template loop is not closed or opened correctly or the name does not match.
     
  8. bruno_floyd

    bruno_floyd New Member

    till, I took off my 2 new fields and let the html template as before... but the error continues.
    My new single value has to be inside this loop "records"? Cause its one value actually...

    Here's the loop with my new 2 fields in red:

    Code:
    <tmpl_loop name="records">
              <tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">    
                <td class="tbl_col_indicou_id"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="indicou_id"}</a></td>
                <td class="tbl_col_indicado_id"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="indicado_id"}</a></td>
                <td class="tbl_col_data_cadastro"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="data_cadastro"}</a></td>
                <td class="tbl_col_plano"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="plano"}</a></td>
                <td class="tbl_col_nome_dominio"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="nome_dominio"}</a></td>
                <td class="tbl_col_telefone"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="telefone"}</a></td>
                <td class="tbl_col_status"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="status"}</a></td>
                <td class="tbl_col_valor_comissao"><a href="#" onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="valor_contrato"}</a></td>
               <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'}');">[COLOR="Red"]{tmpl_var name="total_valor_comissionado"}[/COLOR]</a></td>
               <td class="tbl_col_total_valor_nao_comissionado"><a href="#"onClick="loadContent('indicacao/indicacao_edit.php?id={tmpl_var name='id'}');">[COLOR="Red"]{tmpl_var name="total_valor_nao_comissionado"}[/COLOR]</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>
    
    :)
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    As far as I can see, $soma and $soma_nao that you pass are arrays and not values, but you can set only values for a template variable. So the lines:

    $sql_comissao = "SELECT SUM(valor_contrato) FROM indicacao";
    $sql_nao_comissao = "SELECT SUM(valor_comissao) FROM indicacao";

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

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

    should be:

    $sql_comissao = "SELECT SUM(valor_contrato) as soma FROM indicacao";
    $sql_nao_comissao = "SELECT SUM(valor_comissao) as soma_nao FROM indicacao";

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

    $rec['total_valor_comissionado'] = $soma['soma'];
    $rec['total_valor_nao_comissionado'] = $soma_nao['soma_nao'];
     
  10. bruno_floyd

    bruno_floyd New Member

    Hey till... it worked! :)

    but I don't know why I had to put the whole prepareDataRow($rec) method inside the list_action class.

    Now if you allow me I have more 2 doubts... :p

    On the templates when I put my new 2 variables that is inside the <tmpl_loop name="records">
    it's shown, but shows the number of entries on the DB, not a single line... but the SUM value is okay, is there a way to show it outside the "tmpl_loop"?

    Secondly, I have an issue related to dates... here in Brazil we use the date format "d/m/Y"... when I add an entry into DB it goes on the "Y-m-d" format. How can I put my date conversion method when I show the entry on the screen?

    I could not work yesterday... sorry about the late!
    Thanks again!
     
  11. bruno_floyd

    bruno_floyd New Member

    I figured out a solution for the loop...

    i created 2 vars on my listform_actions.ini.php file with the variables I wanted:

    Code:
    $app->tpl->setVar('total_comissao', $valor);
    $app->tpl->setVar('total_nao_comissao', $valor2);
    And it worked! :D

    Regarding to the data, is it possible to use my convert code:

    Code:
    $tempData = explode("-", $this->dataRecord['data_cadastro']);
    $this->dataRecord['data_cadastro'] = $tempData[2]."/".$tempData[1]."/".$tempData[0];
    inside the onShow() method?
     
    Last edited: Oct 1, 2010
  12. pma_

    pma_ New Member

    I have exactly same problem, how did you solve one? I have latest ISP installed.

    EDIT: problem solved I just changed foder names in module.conf.php
     
    Last edited: Apr 13, 2011

Share This Page