Display different buttons in a list

Discussion in 'Developers' Forum' started by stefanmcds-mnt, Dec 5, 2014.

  1. How can I render different buttons in a list?

    I have a table with the state of the domain according to the state to be displayed one or more different buttons
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    There are many ways as you can do anything thats possible with html. either you use the value of the column that you want to render as button as css class or you use template if consructs in the template to show different html parts depending on the value. This can all be done in the html template, no need to write any php code.
     
  3. Whilst on the topic of the environment ispconfig and then using its programming style I would use the template below what I understand.

    But unfortunately declaring variables from epp_domains_list.php with $ app-> tpl-> SetVar () these are applied globally and not individually on each record.

    You can have an explanatory example?

    Below is the code of the related files

    From epp_domains_list.php
    Code:
    <?php
    require_once ('../../lib/config.inc.php');
    require_once ('../../lib/app.inc.php');
    
    $list_def_file = 'list/epp_domains.list.php';
    
    $app->auth->check_module_permissions ( 'eppclient' );
    
    $app->uses ( 'listform_actions' );
    include ISPC_ROOT_PATH . '/web/eppclient/lib/lang/' . $_SESSION ['s'] ['language'] . '_epp.lng';
    $app->tpl->setVar ( $wb );
    class listform_action extends listform_actions {
    	
    	public function onShow() {
    		global $app;
    
    		$epp_domains = $app->db->queryAll ( "SELECT * FROM epp_domains WHERE active='y'" );
    		foreach ( $epp_domains as $domains ) {
    			switch ($domains ['status']) {
    				case "autoRenewPeriod" :
    					// only info operations
    					$app->tpl->setVar("show_info", "ok");
    					break;
    				case "ok" :
    					// delete,check,sync,info operation
    					$app->tpl->setVar("show_delete", "ok");
    					$app->tpl->setVar("show_check", "ok");
    					$app->tpl->setVar("show_sync", "ok");
    					$app->tpl->setVar("show_info", "ok");
    					break;
    				case "pendingTransfer" :
    					// only transfer operation
    					$app->tpl->setVar("style", "background-color:red; color:black;");
    					$app->tpl->setVar ( "show_transfer", "ok" );
    					break;
    				case "pendingDelete" :
    					// only restore operations
    					$app->tpl->setVar("show_restore", "ok");
    					break;
    			}
    		}
    		
    		// $app->tpl->setVar('currency_txt',$invoice_settings['currency']);
    		
    		parent::onShow ();
    	}
    }
    
    
    $list = new listform_action ();
    $list->SQLOrderBy = 'ORDER BY domain ASC';
    $list->onLoad ();
    
    ?>
    
    The epp_domains_list.htm

    Code:
    <h2><tmpl_var name="list_head_txt"></h2>
    
    <div class="panel panel_list_epp_domains">
    <!-- 
    	<div class="pnl_toolsarea">
    		<fieldset>
    			<legend>{tmpl_var name="toolsarea_head_txt"}</legend>
    			<div class="buttons">
    				<button class="iconstxt icoAdd" type="button"
    					onclick="loadContent('eppclient/epp_domains_edit.php');">
    					<span>{tmpl_var name="add_new_record_txt"}</span>
    				</button>
    			</div>
    		</fieldset>
    	</div>
    -->
    	<div class="pnl_listarea">
    		<fieldset>
    			<legend>
    				<tmpl_var name="list_head_txt">
    			</legend>
    			<table class="list">
    				<thead>
    					<tr>
    						<th class="tbl_col_active" scope="col"><tmpl_var name="active_txt"></th>
    						<th class="tbl_col_domain" scope="col"><tmpl_var name="domain_txt"></th>
    						<th class="tbl_col_buttons" style="text-align:center;" scope="col" rowspan="1" colspan="5"><tmpl_var name="action_txt"></th>
    					</tr>
    					<tr>
    						<td class="tbl_col_active"><select name="search_active" onChange="submitForm('pageForm','eppclient/epp_domains_list.php');">{tmpl_var name='search_active'}</select></td>
    						<td class="tbl_col_domain"><select name="search_domain" onChange="submitForm('pageForm','eppclient/epp_domains_list.php');">{tmpl_var name='search_domain'}</select></td>
    						<td class="tbl_col_buttons"><div class="buttons"><button type="button" class="icons16 icoFilter" name="Filter" id="Filter" value="{tmpl_var name='filter_txt'}" onclick="submitForm('pageForm','eppclient/epp_domains_list.php');"><span>{tmpl_var name="filter_txt"}</span></button></div></td>
    					</tr>
    				</thead>
    				<tbody>
    					<tmpl_loop name="records">
    						<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
    							<td class="tbl_col_active"><a href="#" onclick="loadContent('eppclient/epp_domains_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="active"}</a></td>
    							<td class="tbl_col_domain"><a href="#" onclick="loadContent('eppclient/epp_domains_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="domain"}</a></td>
    						<tmpl_if name="show_transfer">
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=tranfer_accept&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='transfer_confirmation'}');">{tmpl_var name='transfer_accept_txt'}</a></div></td>
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=tranfer_reject&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='transfer_confirmation'}');">{tmpl_var name='transfer_reject_txt'}</a></div></td>
    						</tmpl_if>
    						<tmpl_if name="show_delete">
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=delete&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');"> {tmpl_var name='delete_txt'}</a></div></td>
    						</tmpl_if>
    						<tmpl_if name="show_check">
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=check&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='check_confirmation'}');">{tmpl_var name='check_txt'}</a></div></td>
    						</tmpl_if>
    						<tmpl_if name="show_sync">
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=sync&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='sync_confirmation'}');">{tmpl_var name='sync_txt'}</a></div></td>
    						</tmpl_if>
    						<tmpl_if name="show_restore">
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=restore&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='restore_confirmation'}');">{tmpl_var name='restore_txt'}</a></div></td>
    						</tmpl_if>
    						<tmpl_if name="show_info">
    							<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=info&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='info_confirmation'}');">{tmpl_var name='info_txt'}</a></div></td>
    						</tmpl_if>
    					</tr>
    					</tmpl_loop>
    					<tmpl_unless name="records">
    					<tr
    						class="tbl_row_noresults tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
    						<td colspan="5">{tmpl_var
    							name='globalsearch_noresults_text_txt'}</td>
    					</tr>
    					</tmpl_unless>
    				</tbody>
    				<tfoot>
    					<tr>
    						<td class="tbl_footer tbl_paging" colspan="3"><tmpl_var
    								name="paging"></td>
    					</tr>
    				</tfoot>
    			</table>
    		</fieldset>
    	</div>
    
    </div>
    
     
    Last edited: Dec 6, 2014
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    You have to define the variables as new key in the array that you pass to the setLoop function.
     
  5. Can you give me an example?
     
  6. dont'work why?



    Code:
    class listform_action extends listform_actions {
    	
    	public function onShow() {
    		global $app, $wb, $btn;
    		
    		
    		$epp_domains = $app->db->queryAll ( "SELECT * FROM epp_domains WHERE active='y'" );
    		foreach ( $epp_domains as $domains ) {
    			switch ($domains ['status']) {
    				case "autoRenewPeriod" :
    					// only info operations
    					array_push($btn,array("show_info"=>$wb['btn_info_txt']));
    					break;
    				case "ok" :
    					// delete,check,sync,info operation
    					array_push($btn,array(
    						"show_delete"=>$wb['btn_delete_txt'],
    						"show_check"=>$wb['btn_check_txt'],
    						"show_sync"=>$wb['btn_sync_txt'],
    						"show_info"=>$wb['btn_info_txt'],
    					));
    					break;
    				case "pendingTransfer" :
    					// only transfer operation
    					array_push($btn,array(
    						"show_info"=>$wb['btn_info_txt'],
    						"show_transfer_approve"=>$wb['btn_transfer_approve_txt'],
    						"show_tranfer_reject"=>$wb['btn_transfer_reject_txt'],
    					));
    					break;
    				case "pendingDelete" :
    					// only restore operations
    					array_push($btn,array(
    						"show_restore"=>$wb['btn_restore_txt'],
    					));
    					break;
    			}
    		}
    		//$app->tpl->newLoop("btn");
    		$app->tpl->setLoop("btn", $btn);
    		//$app->tpl->addLoop();
    		
    		// $app->tpl->setVar('currency_txt',$invoice_settings['currency']);
    		
    		parent::onShow ();
    	}
    }
    
    htm
    Code:
    <tmpl_loop name="records">
    						<tr class="tbl_row_<tmpl_if name='__EVEN__'}even<tmpl_else>uneven</tmpl_if>">
    							<td class="tbl_col_active"><a href="#" onclick="loadContent('eppclient/epp_domains_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="active"}</a></td>
    							<td class="tbl_col_domain"><a href="#" onclick="loadContent('eppclient/epp_domains_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="domain"}</a></td>
    							<tmpl_loop name="btn">
    							<tmpl_if name="show_transfer_approve">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=tranfer_approve&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='transfer_confirmation_txt'}');">{tmpl_var name="btn_transfer_approve_txt"}</a></div></td>
    							</tmpl_if>
    							<tmpl_if name="show_transfer_reject">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=tranfer_reject&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='transfer_confirmation_txt'}');">{tmpl_var name="btn_transfer_reject_txt"}</a></div></td>
    							</tmpl_if>
    							<tmpl_if name="show_delete">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=delete&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation_txt'}');">{tmpl_var name="btn_delete_txt"}</a></div></td>
    							</tmpl_if>
    							<tmpl_if name="show_check">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=check&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='check_confirmation_txt'}');">{tmpl_var name="btn_show_check_txt"}</a></div></td>
    							</tmpl_if>
    							<tmpl_if name="show_sync">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=sync&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='sync_confirmation_txt'}');">{tmpl_var name="btn_show_sync_txt"}</a></div></td>
    							</tmpl_if>
    							<tmpl_if name="show_restore">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=restore&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='restore_confirmation_txt'}');">{tmpl_var name="btn_show_restore_txt"}</a></div></td>
    							</tmpl_if>
    							<tmpl_if name="show_info">
    								<td class="tbl_col_buttons"><div class="buttons"><a class="button" href="javascript: del_record('eppclient/templates_epp/IT/epp_domains_action.php?action=info&id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='info_confirmation_txt'}');">{tmpl_var name="btn_show_info_txt"}</a></div></td>
    							</tmpl_if>
    							<td>booooo</td>
    							</tmpl_loop>
    					</tr>
    					</tmpl_loop>
    
     
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    The loop thats shows the rows of the table is named records:

    <tmpl_loop name="records">

    and not "btn".
     

Share This Page