Solved

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

Posted on 2010-09-20
5
531 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

856 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