Solved

save and load query file / folder for jquery.sqlbuilderdemo-0.06.js

Posted on 2010-09-20
5
528 Views
Last Modified: 2012-05-10
Hi,

I'm using this plugin sqlbuilderdemo-0.06.js
http://plugins.jquery.com/project/SQL_QUERY_BUILDER
I'm looking for a way to save and load the query file in a specific folder instead of the root folder.

Here is the code

<?
switch($_REQUEST['op']){
 case 'load':   
   $ff=join('',file(stripslashes($_REQUEST['reportname']).'.'.$_REQUEST['reportid'].'_sql'));
   echo $ff;
 break;

 case 'save':
   $querytosave=stripslashes($_REQUEST['querytosave']);
   $fd=fopen($_REQUEST['reportname'].'.'.$_REQUEST['reportid'].'_sql','w');
   fputs($fd,$querytosave);
   fclose($fd); 
   echo $_REQUEST['reportname']." saved...."; 
 break;
  
 case 'list':
?>
  <ul class='treeview' id='treeview_<?echo $_REQUEST['reportid'];?>'>
	<li class='list'>Saved sql files
		<ul>
<?
if ($dh = opendir('./')) {
        while (($filenm = readdir($dh))) {
            if(strstr($filenm,$_REQUEST['reportid'].'_sql')){
                 $parts = explode('.',$filenm);             
    			 echo "<li class='item'>".$parts[0]."</li>";              
            }            
        }
        closedir($dh);
}
?>
		</ul>
	</li>
  </ul>  

<?  
 break;



}

?>

Open in new window


I have edit this line
if ($dh = opendir('./')) {
to
if ($dh = opendir('./reports')) {

but it's not saving and loading from there it's only displaying the content in the tree list if I put a file inside manually

Thanks
0
Comment
Question by:lenamtl
  • 4
5 Comments
 
LVL 8

Accepted Solution

by:
ropenner earned 500 total points
ID: 33796593
These three lines would need to change

line4)   $ff=join('',file(stripslashes($_REQUEST['reportname']).'.'.$_REQUEST['reportid'].'_sql'));

line 10)   $fd=fopen($_REQUEST['reportname'].'.'.$_REQUEST['reportid'].'_sql','w');

line 22)   if ($dh = opendir('./')) {

perhaps set a variable at the top just after <?

$basedirectory = "./someotherdirectory/";

line 4 becomes
$ff=join('',file($basedirectory."".stripslashes($_REQUEST['reportname']).'.'.$_REQUEST['reportid'].'_sql'));

line 10 becomes

$fd=fopen($basedirectory."".$_REQUEST['reportname'].'.'.$_REQUEST['reportid'].'_sql'),'w');

and line 22 becomes

 if ($dh = opendir($basedirectory))

Whatever you do you will need to reference that new directory in each of the three routines
LOAD
SAVE
and the Directory LIST

0
 
LVL 25

Author Comment

by:lenamtl
ID: 33810489
ok I will give it a try and get back to you tomorrow

Thanks
0
 
LVL 25

Author Comment

by:lenamtl
ID: 33817320
Hi,
I'm getting
Parse error on
$fd=fopen($basedirectory."".$_REQUEST['reportname'].'.'.$_REQUEST['reportid'].'_sql'),'w');
0
 
LVL 25

Author Comment

by:lenamtl
ID: 33824528
Ok I have found the problem

there is an extra )
$fd=fopen($basedirectory."".$_REQUEST['reportname'].'.'.$_REQUEST['reportid'].'_sql'),'w');
should be
$fd=fopen($basedirectory."".$_REQUEST['reportname'].'.'.$_REQUEST['reportid'].'_sql','w');

and { was missing

if ($dh = opendir($basedirectory))
should be
if ($dh = opendir($basedirectory)) {

This is working ok Thanks
0
 
LVL 25

Author Closing Comment

by:lenamtl
ID: 33824538
For those that want to apply this modification
check my last answer for little corrections.

Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question