Jump to content

Is there a hook for buttons?


markcodes

Recommended Posts

Hi all,

 

Here again.

I created an additional tab on productdetails page to give the client an option to see the ports they forwarded. I success fully created a hook to show the value the 4 ports in 4 textbox by connecting to an external server and array'ing the value of each.

An additional feature I would like to achieve is to allow the client to enter the values for each port and upon hitting the "submit" button is to connect to the same external server and insert the values.

 

Problem: I dont have any idea how to link the button to a hook so I can achieve my goal.

The following code below might help us troubleshoot this issue.

 

hook code to show the values of the 4 ports: (it is currently working perfectly though I need to convert to mysqli)

<?php
/**
* Hook for getting the value of ports 1 to 4 from external db
*
* @param array $vars Existing defined template variables
*
* @return array
*/

add_hook('ClientAreaPageProductDetails', 1, function($vars)
   {
   	$service = Menu::context("service");
   	$username = $service->username;

$connection = mysql_connect("152.168.10.24","sdfsdfsdfssa","rterefrgggerer");
$selectdb = mysql_select_db("thisDB",$connection);
$getData = mysql_query("SELECT port1, port2, port3, port4 FROM thisTable WHERE username = '".$username."'");

$result = mysql_fetch_assoc($getData);
       return array(
           "port1" => $result['port1'],
           "port2" => $result['port2'],
           "port3" => $result['port3'],
           "port4" => $result['port4']
       );
   }
);

 

productdetails page tabPortForward code:

 <div class="tab-pane fade in" id="tabPortForward">

       <h3>Port Forwarding</h3>
       <form class="form-horizontal using-password-strength" method="post" action="{$smarty.server.PHP_SELF}?action=productdetails#tabPortForward" role="form">
           <input type="hidden" name="id" value="{$id}" />
           <input type="hidden" name="moduleportforward" value="true" />

           <div id="Port1" class="form-group has-feedback">
               <label for="inputNewPort1" class="col-sm-7 control-label">Port #1</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort1" name="newport1" value="{$port1}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port2" class="form-group has-feedback">
               <label for="inputNewPort2" class="col-sm-7 control-label">Port #2</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort2" name="newport2" value="{$port2}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port3" class="form-group has-feedback">
               <label for="inputNewPort3" class="col-sm-7 control-label">Port #3</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort3" name="newport3" value="{$port3}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port4" class="form-group has-feedback">
               <label for="inputNewPort4" class="col-sm-7 control-label">Port #4</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort4" name="newport4" value="{$port4}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>                     
           <div class="form-group">
               <div class="col-sm-offset-6 col-sm-6">
                   <input class="btn btn-primary" type="submit" value="{$LANG.clientareasavechanges}" />
                   <input class="btn" type="reset" value="{$LANG.cancel}" />
               </div>
           </div>

       </form>
   </div>

 

 

Can anyone point me into the right direction?

 

Sincerely,

me

Link to comment
Share on other sites

HI sentq

 

I tried following the guide but I came across some issue with what kind of smarty variable to use.

Actually from the hook TO the page I used $port1, $port2, $port3 & $port4 respectively.

But how do I get the value FROM the page to the module so I can do INSERT in the db.

 

Below is the productdetails page tabPortForward tab code:

 

<div class="tab-pane fade in" id="tabPortForward">

       <h3>Port Forwarding</h3>
<div class="row">
<div class="col-md-8">
sample sfdvdvsdfvdsfgs
</div>
	<div class="col-md-12">
       <form class="form-horizontal" method="post" action="{$smarty.server.PHP_SELF}?action=productdetails#tabPortForward" role="form">
           <input type="hidden" name="id" value="{$id}" />
           <input type="hidden" name="updateports" value="custom" />

	<div id="Username" class="form-group has-feedback">
               <label for="thisUsername" class="col-sm-7 control-label">Your Username:</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="thisUsername" name="Username" value="{$username}" disabled/>
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           		<div id="Password" class="form-group has-feedback">
               <label for="thisPassword" class="col-sm-7 control-label">Your Password:</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="thisPassword" name="Password" value="{$password}" disabled/>
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port1" class="form-group has-feedback">
               <label for="inputNewPort1" class="col-sm-7 control-label">Port #1</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort1" name="newport1" value="{$port1}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port2" class="form-group has-feedback">
               <label for="inputNewPort2" class="col-sm-7 control-label">Port #2</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort2" name="newport2" value="{$port2}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port3" class="form-group has-feedback">
               <label for="inputNewPort3" class="col-sm-7 control-label">Port #3</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort3" name="newport3" value="{$port3}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>
           <div id="Port4" class="form-group has-feedback">
               <label for="inputNewPort4" class="col-sm-7 control-label">Port #4</label>
               <div class="col-sm-3">
                   <input type="text" class="form-control" id="inputNewPort4" name="newport4" value="{$port4}" />
                   <span class="form-control-feedback glyphicon"></span>
               </div>
           </div>                     
           <div class="form-group">
               <div class="col-sm-offset-6 col-sm-6">
                   <input type="hidden" name="updateports" value="Update Ports" />
                   <input class="btn btn-primary" type="submit" name="updateports" value="Update Ports" />
                   <input class="btn" type="reset" value="{$LANG.cancel}" />
               </div>
           </div>

       </form>
   </div>
   </div>

 

Below are the module function codes:

function nonotagain_updateports($params) {

try {

	# Define the connection
	define('DB_SERVER', $params["configoption1"]);
	define('DB_USER', $params["configoption3"]);
	define('DB_PASSWORD', $params["configoption4"]);
	define('DB_DATABASE', $params["configoption2"]);
	define('DB_DRIVER', "mysql");

	# Connect to remote MySQL database
   		$conn = new PDO(DB_DRIVER . ":dbname=" . DB_DATABASE . ";host=" . DB_SERVER, DB_USER, DB_PASSWORD);
   		$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

		# Update ports in the database
	$query = "UPDATE radcheck SET port = :port1, port2 = :port2, port3 = :port3, port4 = :port4 WHERE username = :username";
	$data = $conn->prepare($query);
	$data->execute(array(':username'=>$params["username"],
			     ':port1'=>$whatvariable_here,
			     ':port2'=>$whatvariable_here,
			     ':port3'=>$whatvariable_here,
			     ':port4'=>$whatvariable_here));


	} catch(PDOException $e) {
   		echo 'ERROR: Having a hard time updating the ports in the database ' . $e->getMessage();
}
return 'success';

}

function nonotagain_ClientAreaCustomButtonArray() {
   $buttonarray = array(
 "update Ports" => "updateports",
);
return $buttonarray;
}

 

 

I can click on the "Update Ports" button but the module is clearly not getting the value from the page.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated