Home
LimeSurvey Forums
Welcome, Guest
Please Login or Register.    Lost Password?
Re:How to import a survey from webapplication? (1 viewing) (1) Guest
Go to bottom Favoured: 0
TOPIC: Re:How to import a survey from webapplication?
#11724
rakete (User)
Expert Lime
Posts: 112
graphgraph
User Offline Click here to see the profile of this user
[done] How to import a survey from webapplication? 7 Months, 3 Weeks ago Karma: 3  
Hello there,

We are developing a webservice for Limesurvey 1.7...
Our Main Goal is to import an existing Survey, change the relevant Data (ID and Surveytitle) and in a second step we add tokens to the survey and activate it.

My Question is:

How can I manage to import a survey.csv file, which lies on any webspace?

I tried it like that:

require_once('../config-defaults.php';
//we import a survey to change it.
$the_full_file_path = "../docs/demosurveys/studiply-test.csv";

//$the_full_file_path = "localhost/limesurvey/docs/demosurveys/studiply-test.csv";

$argv[1] = $the_full_file_path;
$argc[2] = "admin";
$argc[3] = "password";
include("../admin/cmdline_importsurvey.php";

the uncommented file_path is the one who finds the file, but gives back an error message: "Call to a member function MetaTables() on a non-object".
The commented path doesn't even find the file and I don't understand why.


Hopefully someone could help, I've already spent hours on this issue...

greetings
Tim


/edit: I experimented a bit with importsurvey, cmdline_importsurvey, http_importsurvey, even tried it with setting the $_SESSION[loginID],[USER_RIGHT_MANAGE_*] Variables but it always comes to this Error:

"Call to a member function MetaTables() on a non-object"

and I really don't know where the error occours and why...
please help, I am getting frustrated..

thx
 
Logged Logged  
 
Last Edit: 2008/04/14 11:33 By Mazi.
 
  The administrator has disabled public write access.
#11730
c_schmitz (Admin)
Moderator Lime
Posts: 1354
graphgraph
User Online Now Click here to see the profile of this user
Re:How to import a survey from webapplication? 7 Months, 3 Weeks ago Karma: 39  
Hi

It looks like the database settings are not read.

cmdline_importsurvey.php does contain all the necessary includes.
But these includes are on a relative path so you have to make sure that you are executing from the right dir. (/admin)
Also switch on debug messages and check your server log to get a better impression of what's going on.
 
Logged Logged  
 
Last Edit: 2008/04/04 15:36 By c_schmitz.
 
Best regards

Carsten Schmitz
LimeSurvey Project Leader
  The administrator has disabled public write access.
#11731
rakete (User)
Expert Lime
Posts: 112
graphgraph
User Offline Click here to see the profile of this user
Re:How to import a survey from webapplication? 7 Months, 3 Weeks ago Karma: 3  
thx for the hint!... the script is now located in the /admin dir and it works perfect for me, with this small code only...

Code:

   
$the_full_file_path = "../docs/demosurveys/studiply-test.csv";

// just for passing the first check in cmdline_importsurvey
$argc[2] = "";
$argc[3] = "";
     
$argv[1] = $the_full_file_path;
$argv[2] = "admin";
$argv[3] = "password";

require_once("cmdline_importsurvey.php");

 
Logged Logged  
 
  The administrator has disabled public write access.
#11807
rakete (User)
Expert Lime
Posts: 112
graphgraph
User Offline Click here to see the profile of this user
Re:How to import a survey from webapplication? 7 Months, 2 Weeks ago Karma: 3  
My Problem still exists, after copying the Webservice to the /admin dir...

PHP Fatal error: Call to a member function MetaTables() on a non-object in D:\xampplite\htdocs\limesurvey\common.php on line 1108

the confusing thing is, that when I put the code to import the survey into a single file and go to that File in my Browser, it imports the survey... everything is fine... but the same code in my webserviceapplikation fails with the error above...

Here are the codes, hopefully somebody notice, what I am doing wrong...

Could It be, that the Problem occures because the japhserver is a remote called Instanz and not a blank Script?
Any ideas for a workaround?

japhfunctions.php (in /limesurvey/admin/) working
<?

$importingfrom = "cmdline"; // "http" for the web version and "cmdline" for the command line version
$the_full_file_path = "../docs/demosurveys/studiply-test.csv";

$argv[1] = $the_full_file_path;
$argc[2] = "";
$argc[3] = "";
$argv[2] = "admin";
$argv[3] = "password";

require_once("cmdline_importsurvey.php";

?>


japhserver.php (also in /limesurvey/admin/) not working
<?php
# Name: japhserver.php
# Author: J. Morti Uhlig, Tim Wahrendorff
# Usage: Web Service for registering and starting surveys in LimeSurvey

# Function to write a new survey into the database. Required parameters are:
# $iVid= Veranstaltungs-ID
# $sVbez=Veranstaltungs-Nr - 'Veranstaltungsname', 'Veranstaltungs-Typ' von 'Dozenten-Titel' 'Dozenten-Name',
function sCreateSurvey($iVid, $sVbez) {
# check for existing Survey in database: Is there a row with a Survey-ID (sid)
# matching the value of our $iVid? Case true leads to aborting with a message
# that the survey to register already exists.
require_once('../config-defaults.php';
require_once('../common.php';
$query2check_id = "SELECT * FROM `lime_surveys` WHERE `sid` = ".$iVid." ";
$con = mysql_connect($databaselocation, $databaseuser, $databasepass);
$checkRs = mysql_db_query($databasename, $query2check_id, $con);
$checkCnt = mysql_num_rows($checkRs);
mysql_close($con);

if ($checkCnt > 0)
{
throw new SoapFault("Database", "SurveyID already exists";
exit;
}

if(is_int($iVid) && $sVbez!=''
{
####### HERE is the relavant code

$importingfrom = "cmdline"; // "http" for the web version and "cmdline" for the command line version
$the_full_file_path = "../docs/demosurveys/studiply-test.csv";

$argv[1] = $the_full_file_path;
$argc[2] = "";
$argc[3] = "";
$argv[2] = "admin";
$argv[3] = "password";

require_once("cmdline_importsurvey.php";

$sReturn = $iVid." - ".$sVbez;
mysql_close($con);
return $sReturn;
}
else
{
if($iVid=='' || $sVbez==''
{
throw new SoapFault("Server", "One or more Parameters missing";
exit;
}
throw new SoapFault("Server", "Given VeranstaltungsID is no Integer";
exit;
}
}
// Function to insert Tokens to existing Surveys
function sInsertToken() {
// empty by now
}

//we don't like caching while testing, so we disable it
ini_set("soap.wsdl_cache_enabled", "0";
//error log enabled, hint(.../apache/logs/error.log)
ini_set("log_errors", "1";
# vars for instantiation of a server using SSL:
$wsdl="./japh.wsdl";
$cert="/etc/apache2/ssl/mort.pem";

//we initiate a SoapServer Objekt
$server = new SoapServer($wsdl,
array('soap_version' => SOAP_1_1));

//adds the functions to the SoapServer Object
$server->addFunction("sCreateSurvey";
$server->addFunction("sInsertToken";
// handle the soap request!
$server->handle();

?>


thx for any help..

greetings
Tim
 
Logged Logged  
 
Last Edit: 2008/04/07 13:50 By Mazi.
 
  The administrator has disabled public write access.
#11813
Mazi (Moderator)
Moderator Lime
Posts: 3252
graph
User Offline Click here to see the profile of this user
Re:How to import a survey from webapplication? 7 Months, 2 Weeks ago Karma: 25  
What do you need this for?
Code:

require_once('../common.php');
 
Logged Logged  
 
Best regards,
Mazi
______________________
Need help? I can: set up Limesurvey for you / create your survey / implement additional features / design your template / offer premium support -> Contact.
  The administrator has disabled public write access.
#11816
rakete (User)
Expert Lime
Posts: 112
graphgraph
User Offline Click here to see the profile of this user
Re:How to import a survey from webapplication? 7 Months, 2 Weeks ago Karma: 3  
This is wasteful...
Of course don't need it... sorry for this "trial and error" mess

same error without this include (but common.php is included in the cmdline_importsurvey.php)

this are the lines from common.php

Code:

function checkifemptydb()
{
global $connect, $dbprefix;
$tablelist = $connect->MetaTables('TABLES'); //Line 1108
if ( in_array($dbprefix.'surveys',$tablelist) ) {Return(false);}
else {Return(true);}
}



I presume the $connect variable is NULL, when the script comes to this point, but I can't figure out why...
 
Logged Logged  
 
  The administrator has disabled public write access.
Go to top