Forums

Can I run an external script from chrono forms?

samoht 12 Jan, 2010
Hello all,

I have a registration form that creates a user and a software License. Once the new user is activated and logged in they have a new form available to them that shows them their user info - including their license info and reveals a download link that has the license data attached already for them.

I have had this working fine for some time - but then I was asked to create a Session variable that would distinguish between visitors from the US and those outside the US (which I call "INTERNATIONAL")This has caused the download script to complain. So instead of writing this:
<?php
$user =& JFactory::getUser();
$uid = $user->id;

global $mainframe;

$database =& JFactory::getDBO();
$database->setQuery( '
SELECT 
	license_start,
	license_duration,
	key_code,
	first_name,
	last_name,
	user_email,
	title,
	vm_hospitalaffiliation,
	address_1,
	address_2,
	city,
	state,
	country,
	zip
FROM jos_vm_product_license a, jos_vm_user_info b
WHERE a.user_id = '.$uid.'
AND a.user_id = b.user_id');

$database->query();
$licenseinfo = $database->loadAssoc();

$dLicense = 6 * 2592000; //this multiplies the duration by num seconds in a month - I now only want 90 days no matter what
$nTime = $dLicense + $licenseinfo['license_start']; // this gives us the expiration date - should always be 90 days out* 
?>
<div style="position:relative; top:23px; padding:7px; text-align=left;">
<?php
//## code for creating the installer##//

require_once '../test.mysite.com/mysite_api/inc/functions.php';

 $license = $licenseinfo['key_code'];
 $name = $user->username;
 if($_SESSION['country'] != "USA Website")
 {
     $version = "International";
 } 
 else
 {
     $version = "US";
 }
 
if (chdir('../test.mysite.com/mysite_api/nsis/users'))
{
$outdir = getcwd() . '/' . $name;
if(!is_dir($outdir))
{
mkdir ( $outdir );
}

 if($license == '')
  {
    if($version == '')
    {
      $cmd = "makensis " . 
          " -DMYOUTDIR=\"" . $outdir . "\"" . 
          " -DSURGIMAPVERSION=\".\"" . 
          " MySoftware.nsi";    
    }else{
    
      $cmd = "makensis " . 
          " -DMYOUTDIR=\"" . $outdir . "\"" . 
          " -DSURGIMAPVERSION=\"" . $version . "\"" . 
          " MySoftware.nsi";
    }
  }else{
    if($version == '')
    {
      $cmd = "makensis " . 
          " -DMYOUTDIR=\"" . $outdir . "\"" . 
          " -DSURGIMAPVERSION=\".\"" . 
          " -DUSERNAME=\"" . $name . "\"" . 
          " -DLICENSE=\"" . $license . "\"" . 
          " MySoftware.nsi";    
    }else{
      $cmd = "makensis " . 
          " -DMYOUTDIR=\"" . $outdir . "\"" . 
          " -DSURGIMAPVERSION=\"" . $version . "\"" . 
          " -DUSERNAME=\"" . $name . "\"" . 
          " -DLICENSE=\"" . $license . "\"" . 
          " MySoftware.nsi";
    }
  }

  exec($cmd,$output,$rval);
}
echo $version."

";
echo '<a href = "surgimap_api/download.php?login='.$name.'&file=SurgimapSetup.exe" ><img src="/images/stories/download.jpg" border="0" alt="Download Now" title="Download Now" hspace="0" vspace="0" onmouseover="this.src=\'images/stories/download_hover.jpg\';" onmouseout="this.src=\'images/stories/download.jpg\';" /></a><BR>'."
";
//echo "<div style=\"width:733px\"><p>" .  print_r($cmd,TRUE) . "</p></div>";
echo "<div style=\"width:333px\"><pre><font size='1'><b>Return Value: " . $rval . "</b><br/>" .  print_r($output,TRUE) . "</font></pre></div>";

?>
</div>


I would like to simply call a install.php script from the form and send it the 3 variables $login, $name, $version

how can I do that if the script is outside of the Joomla?

Thanks,
GreyHead 13 Jan, 2010
Hi samoht,

I don't understand whay adding the session variable causes a problem :-(

You can call an external script OK - but you have to find a way of passing the data back and forth. You can't use the session data outside Joomla - but you could use a cookie, a database entry, or a temporary file, I think any of these would do the job.

Bob
samoht 13 Jan, 2010
Thanks Bob,

Yes I was able to get the variables I needed from the database. I'm not sure why I thought It would be hard - but thanks for the reply. I got it sorted out easily enough. Sometimes my brain just reverts to "stupify" mode😉
This topic is locked and no more replies can be posted.