tags:

views:

165

answers:

2

Hello again! I have a problem with 3rd-party-system integration in my drupal site. Sorry for my english, i'm from russia, but i will try to explain my problem well.

Integration idea:

  • 2 .php files
  • 2 php-script lines (include function's)

The problem is:

  • this scripts call to outside perl (.pl) script. Perl script read the parameters (parameters transfers by url) and generate content.

  • I can't see this perl script, but i know - hes working, but not in my page :)

2 php files:

spectrum_view.php

<?php    
$url = "http://young.spectrum.ru/cgi-bin/programs_view.pl";    
$param = $_GET;     
if (!empty($param))
    {
    $url .= "?";
    foreach ($param as $keys=>$value)
                   {
                   $url .= "&".$keys."=".urlencode($value);
                   }
    }    echo $content = file_get_contents($url);    
?>

spectrum_form.php

<?php 
$url ="http://young.spectrum.ru/cgi-bin/programs_form.pl"; 
$params = $_GET; 
if (!empty($params))
        {
        $url .= "?";
        foreach ($params as $keys=>$value)
              {
               $url .= "&".$keys."=".urlencode($value);
              }
        }    echo iconv("windows-1251","utf-8",(file_get_contents($url))); 
    ?>

and the 2 php-lines, wich i insert in my drupal pages (the first i insert in page http://new.velo-travel.ru/view and the second in the right block)

include("http://new.velo-travel.ru/themes/themex/spectrum_view.php?$QUERY_STRING");

include("http://new.velo-travel.ru/themes/themex/spectrum_form.php?act=/view$QUERY_STRING");

So, i solved this problem, but not in drupal - only on my Localohost, i just create a 2 page:

form.php:

<?php
$url ="http://young.spectrum.ru/cgi-bin/programs_form.pl";
$params = $_GET;
if (!empty($params)){
    $url .= "?";
    foreach ($params as $keys=>$value) $url .= "&".$keys."=".urlencode($value);
}
$content = file_get_contents($url);
print $content;

**require_once 'view.php';**
?>

view.php:

<?php
$url = "http://young.spectrum.ru/cgi-bin/programs_view.pl";
$param = $_GET;
if (!empty($param))
 {
 $url .= "?";
 foreach ($param as $keys=>$value)
                {
                $url .= "&".$keys."=".urlencode($value);
                }
 }

$content = file_get_contents($url);
print $content;
?>

=(

+1  A: 

I'm not entirely sure, as to what you are trying to do. But it seems like you want to generate this content from the perl script. If this is a special page with it's own template, you should move all this code into template.php. This file is made to hold some logic you want to create the content for your page.

Personally I would prefer to make a module to handle all this, but it's probably easier to do this in the theme, with what you got now. It seems like you are making a form, and some content based on the form. This could be done in a module. You could create a Drupal form, and then handle the validation with drupal, and jst submit the data to perl. But if you would want to get it from perl, going with the theme is probably best. So how do you do it?

  1. Implement a preprocess fuction for the tpl.php file you use.
  2. Create all the logic here, you could copy the php files you use over or just include them. Import, assign the result to a variable the will be accessible in the template file.
  3. Print the variable in your template.

In code this would look something like this:

//template.php file
function mytheme_preprocess_somename(&$vars) {
    include('php');
    // Do some logic.
    $vars['form'] = $result_a;
    $vars['my_content'] = $result_b;
}

// your .tpl.php
// Some markup here
<div><?php print $my_content; ?></div>
<div><?php print $form; ?></div>

Now, I'm not sure exactly what you are after, but something like this should help you along. Note it's important what you call your variables inside the template file, as you can overwrite some Drupal variables like $content, which can cause some bugs.

googletorp
A: 

You probably are running into a security issue. Please note allow_url_fopen and allow_url_include - these settings must have accordant settings in your php.ini. Otherwise you can't e.g. include a remote file for security reasons.

schneck