Welcome, Guest
Username: Password: Remember me

TOPIC: Action Script to rename a Filename

Action Script to rename a Filename 3 years 2 months ago #64398

  • rg_vkalp
  • rg_vkalp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Hi,

Based on a question and answer sequence i have generated a answer. Based on this answer, I would like to add a action Script in my survey that launches a command to change and relocate a particular file. e.g. below

QiD 1 Original Filename

A) 200811_xyz

QiD 2 Reference ID

B) 5924

QiD 3 New File name ( codes added for INSERTANS......)

A) 211111_xyz_5924


Now I need to do either of the following. Either Using the Submit button or any other Action Button on the same survey page should launch the following command on my system

Something like this ;

It should launch a rename command in a particular directory and change the file name of "200811_xyz" as in ans Qid1 and name it as ans of QiD3 in some other directory.
Location of original directory and relocate directory remain constant e.g.

Original Directory in home folder and relocate to temp folder in home directory

rename("{INSERTANS:SIDXGIDXQID1}", "{INSERTANS:SIDXGIDXQID3}");
The administrator has disabled public write access.

Re: Action Script to rename a Filename 3 years 2 months ago #64415

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
I think you will need to fire a remote PHP script to do this - I'm not a PHP expert so can't help with the details of that script.

Here's an example of how to fire a remote PHP script - www.limesurvey.org/en/forum/can-i-do-thi...on-of-a-survey#55975.

To find how to use the Submit button, search the forum for "interrupt next/submit process".
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Action Script to rename a Filename 3 years 2 months ago #64422

  • rg_vkalp
  • rg_vkalp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Hi,
Thanks. I think i will be able to get a remote php script made by an expert. What I need to know now is how will this php script be able to take the required values from the survey like i mentioned.

Will the php script be able to take the INSERTANS functions based on this submitted form?

RG
The administrator has disabled public write access.

Re: Action Script to rename a Filename 3 years 2 months ago #64426

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
The link I posted indicates how to pass data to the PHP script.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Action Script to rename a Filename 3 years 2 months ago #64429

  • rg_vkalp
  • rg_vkalp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Hi Tony,
I am still very confused. Can you help or recommend someone who can with PhP. I think its not very complex but I am unable to get any further.

1. I could not find much help on how i can interrupt the submit process and add this script

2. Do you think the php script will be able to insert values from the survey as I have explained earlier.

A little more detailed help will be more useful. Thanks much for your time.
The administrator has disabled public write access.

Re: Action Script to rename a Filename 3 years 2 months ago #64436

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
I can't help you with the PHP - it's not my expertise.

To interrupt the next/submit function and call a script, do this:

1) Set up your survey to use JavaScript.

2) Add the following script to the source of any question on the page.

When the next/submit button is clicked, the "yourFile.php" script is called and the "originalName" and "newName" variables are passed to it in the GET array.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Interrupt the Next/Submit function
		$('form#limesurvey').submit(function(){	
 
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			// Call a remote script
			$.get('pathToYourFile/yourFile.php', { originalName: '{INSERTANS:SIDXGIDXQID1}', newName: '{INSERTANS:SIDXGIDXQID3}' } );
 
			return true;
 
		});
 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 2 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: rg_vkalp

Re: Action Script to rename a Filename 3 years 2 months ago #64490

  • rg_vkalp
  • rg_vkalp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Hello,

Ok I tried but not getting any variable passed to php it seems. here is my Javascript and here is my PHP.

location of php file is /var/www/rename.php

original file is located in
/home/origdirectory

renamed file should goto
/renamebkp

So now either something is wrong with the PHP or JS is not able to call the PHP or not able to pass the variables.

RG
Attachments:
The administrator has disabled public write access.

Re: Action Script to rename a Filename 3 years 2 months ago #64494

  • rg_vkalp
  • rg_vkalp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
WORKS.......

made just the wrong entry to path for launching rename.php. was using /var/www/rename.php
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.110 seconds
Donation Image