Solved

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

Posted on 2010-09-20
5
525 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
Comment Utility
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 24

Author Comment

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

Thanks
0
 
LVL 24

Author Comment

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

Author Comment

by:lenamtl
Comment Utility
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 24

Author Closing Comment

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

Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now