Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-20
5
Medium Priority
?
542 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 2000 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 27

Author Comment

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

Thanks
0
 
LVL 27

Author Comment

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

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 27

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

824 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