forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 plugins => Topic started by: just_some_guy on October 28, 2007, 02:32:37 pm

Title: Plugin install code help.
Post by: just_some_guy on October 28, 2007, 02:32:37 pm
Hello,

I am making a plugin and seems to be good apart from the install function.
It works without the install function but just reports a critical error when i put the code in. Heres the code:

Code: [Select]
<?php 
function this_install() {
global 
$CONFIG;

   
$sql = ("INSERT INTO `{$CONFIG['TABLE_PREFIX']}` (`name` ,`value` )VALUES ('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'), ('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text')");

$result mysql_query($sql);


}
?>

any ideas?

thanks,
Title: Re: Plugin install code help.
Post by: Sami on October 28, 2007, 02:44:15 pm
GauGau already told you , please post to plugin board instead of Coppermine coding discussion borad

you forget table name under query
Title: Re: Plugin install code help.
Post by: just_some_guy on October 28, 2007, 03:48:51 pm
Sorry, that was an error when i posted its actually `{$CONFIG['TABLE_CONFIG']}`  and it doesent work. just returns the error.
Title: Re: Plugin install code help.
Post by: just_some_guy on October 28, 2007, 07:34:54 pm
I have made an improvment.

I know have this:

Code: [Select]
function this_install() {

    // Install
    if ($_POST['submit']=='Submit') {

        return true;

        // Loop again
    } else {

        return 1;
    }
 $sql = ("INSERT INTO `{$CONFIG['TABLE_CONFIG']}` (`name` ,`value` )VALUES ('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'), ('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text')");


}


When i click install it shows the configure part of the codebase and when i click submit it just loops the same page. What is wrong with the above code?

Thanks,

ps the if else clause in that code is from the FileMove plugin.


Title: Re: Plugin install code help.
Post by: Nibbler on October 28, 2007, 08:34:08 pm
1. Code placed after a return; will never run.
2. $sql is just a string, so does nothing anyway. You need to actually run the query using cpg_db_query($sql).
Title: Re: Plugin install code help.
Post by: just_some_guy on October 28, 2007, 08:50:10 pm
I now have this:

What should go after the $_POST? is it correct?

Code: [Select]
function this_install() {

    // Install
    if ($_POST['submit']=='Submit') {
   
 $sql = ("INSERT INTO `{$CONFIG['TABLE_CONFIG']}` (`name` ,`value` )VALUES ('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text'), ('text', 'text'),('text', 'text'),('text', 'text'),('text', 'text')");

   cpg_db_query($sql);
        return true;

        // Loop again
 } else {


        return 1;
    }




}

And it just does the same, any ideas?

Thanks Nibbler
Title: Re: Plugin install code help.
Post by: just_some_guy on October 28, 2007, 09:36:15 pm
I fixed it, but when you create the admin button what should it link to? i know its plugin_name/????

Thanks,
Title: Re: Plugin install code help.
Post by: Sami on October 29, 2007, 04:39:04 am
It depends on what you up to with admin button , usually it links to configuration (e.g. config.php)
Title: Re: Plugin install code help.
Post by: Joachim Müller on October 29, 2007, 08:45:07 am
GauGau already told you , please post to plugin board instead of Coppermine coding discussion borad
Moving accordingly.

Title: Re: Plugin install code help.
Post by: just_some_guy on October 29, 2007, 06:27:18 pm
Using Frantz's backup plugin as an example the link is "file=backup/backup"  where does this link to? is it backup.php where backup is the file which contains the config? am i getting the function of "function plugin_configure()" confused? Right now i am thinking that this contains the information that can be configured (ie the content that the button links to). This may be wrong and i need to then create a file called config.php to contain the config information.

What is correct?

Thanks,
Title: Re: Plugin install code help.
Post by: Sami on October 29, 2007, 06:57:14 pm
file=folder/file means :
include file.php from {gallery root}/plugins/folder into index.php


and yes backup.php contains configuration settings for that plugin
You can name the file, what ever you want to
Title: Re: Plugin install code help.
Post by: just_some_guy on October 29, 2007, 07:47:09 pm
Aha! thanks,the problem is that the .php extension is not required. it can just be file="plugin/config". Thanks Sami.

On the config page how do i make it fit in with the theme?
What file must i include to solve this error on the config page?
Undefined variable: CONFIG
Call to undefined function cpg_db_query()

Thanks,

And very sorry for all the questions, im not new to php and mysql but i am new to pluginizing.
Title: Re: Plugin install code help.
Post by: Sami on October 30, 2007, 04:44:20 am
just add this to the very first of your file to define CONFIG and coppermine functions
Code: [Select]
require('include/init.inc.php');

then use pageheader function to add coppermine header to your page
Code: [Select]
pageheader($title);
$title is your page title
Title: Re: Plugin install code help.
Post by: just_some_guy on October 30, 2007, 10:24:24 pm
Fantastic Sami, thats much better thanks again!