if ( !$edit_name ) {
$edit_name = "true";
}
+if ( !$prefs_user_field ) {
+ $prefs_user_field = 'user';
+}
+if ( !$prefs_key_field ) {
+ $prefs_key_field = 'prefkey';
+}
+if ( !$prefs_val_field ) {
+ $prefs_val_field = 'prefval';
+}
if ( $ARGV[0] eq '--install-plugin' ) {
print "Activating plugin " . $ARGV[1] . "\n";
print $WHT. "Database\n" . $NRM;
print "1. DSN for Address Book : $WHT$addrbook_dsn$NRM\n";
print "2. Table for Address Book : $WHT$addrbook_table$NRM\n";
+ print "\n";
print "3. DSN for Preferences : $WHT$prefs_dsn$NRM\n";
print "4. Table for Preferences : $WHT$prefs_table$NRM\n";
+ print "5. Field for username : $WHT$prefs_user_field$NRM\n";
+ print "6. Field for prefs key : $WHT$prefs_key_field$NRM\n";
+ print "7. Field for prefs value : $WHT$prefs_val_field$NRM\n";
print "\n";
print "S Save data\n";
print "R Return to Main Menu\n";
if ( $command =~ /^[0-9]+/ ) { @plugins = command81(); }
elsif ( $command eq "a" ) { command8s(); }
} elsif ( $menu == 9 ) {
- if ( $command == 1 ) { $addrbook_dsn = command91(); }
- elsif ( $command == 2 ) { $addrbook_table = command92(); }
- elsif ( $command == 3 ) { $prefs_dsn = command93(); }
- elsif ( $command == 4 ) { $prefs_table = command94(); }
+ if ( $command == 1 ) { $addrbook_dsn = command91(); }
+ elsif ( $command == 2 ) { $addrbook_table = command92(); }
+ elsif ( $command == 3 ) { $prefs_dsn = command93(); }
+ elsif ( $command == 4 ) { $prefs_table = command94(); }
+ elsif ( $command == 5 ) { $prefs_user_field = command95(); }
+ elsif ( $command == 6 ) { $prefs_key_field = command96(); }
+ elsif ( $command == 7 ) { $prefs_val_field = command97(); }
}
}
}
sub command94 {
print "This is the name of the table you want to store the preferences\n";
- print "data in, it defaults to 'address'\n";
+ print "data in, it defaults to 'userprefs'\n";
print "\n";
print "[$WHT$prefs_table$NRM]: $WHT";
$new_table = <STDIN>;
return $new_table;
}
+sub command95 {
+ print "This is the name of the field in which you want to store the\n";
+ print "username of the person the prefs are for. It default to 'user'\n";
+ print "which clashes with a reserved keyword in PostgreSQL so this\n";
+ print "will need to be changed for that database at least\n";
+ print "\n";
+ print "[$WHT$prefs_user_field$NRM]: $WHT";
+ $new_field = <STDIN>;
+ if ( $new_field eq "\n" ) {
+ $new_field = $prefs_user_field;
+ } else {
+ $new_field =~ s/[\r|\n]//g;
+ }
+ return $new_field;
+}
+
+sub command96 {
+ print "This is the name of the field in which you want to store the\n";
+ print "preferences keyword. It defaults to 'prefkey'\n";
+ print "\n";
+ print "[$WHT$prefs_key_field$NRM]: $WHT";
+ $new_field = <STDIN>;
+ if ( $new_field eq "\n" ) {
+ $new_field = $prefs_key_field;
+ } else {
+ $new_field =~ s/[\r|\n]//g;
+ }
+ return $new_field;
+}
+
+sub command97 {
+ print "This is the name of the field in which you want to store the\n";
+ print "preferences value. It defaults to 'prefval'\n";
+ print "\n";
+ print "[$WHT$prefs_val_field$NRM]: $WHT";
+ $new_field = <STDIN>;
+ if ( $new_field eq "\n" ) {
+ $new_field = $prefs_val_field;
+ } else {
+ $new_field =~ s/[\r|\n]//g;
+ }
+ return $new_field;
+}
+
sub save_data {
$tab = " ";
if ( open( CF, ">config.php" ) ) {
print CF "\$addrbook_dsn = '$addrbook_dsn';\n";
print CF "\$addrbook_table = '$addrbook_table';\n\n";
print CF "\$prefs_dsn = '$prefs_dsn';\n";
- print CF "\$prefs_table = '$prefs_table';\n\n";
+ print CF "\$prefs_table = '$prefs_table';\n";
+ print CF "\$prefs_user_field = '$prefs_user_field';\n";
+ print CF "\$prefs_key_field = '$prefs_key_field';\n";
+ print CF "\$prefs_val_field = '$prefs_val_field';\n";
+ print CF "\n";
print CF "/**\n";
print CF " * Make sure there are no characters after the PHP closing\n";
* Database:
* ---------
*
- * The preferences table should have tree columns:
- * username char \ primary
+ * The preferences table should have three columns:
+ * user char \ primary
* prefkey char / key
* prefval blob
*
class dbPrefs {
var $table = 'userprefs';
+ var $user_field = 'user';
+ var $key_field = 'prefkey';
+ var $val_field = 'prefval';
var $dbh = NULL;
var $error = NULL;
if (!empty($prefs_table)) {
$this->table = $prefs_table;
}
+ if (!empty($prefs_user_field)) {
+ $this->user_field = $prefs_user_field;
+ }
+ if (!empty($prefs_key_field)) {
+ $this->key_field = $prefs_key_field;
+ }
+ if (!empty($prefs_val_field)) {
+ $this->val_field = $prefs_val_field;
+ }
$dbh = DB::connect($prefs_dsn, true);
if(DB::isError($dbh) || DB::isWarning($dbh)) {
if (!$this->open()) {
return false;
}
- $query = sprintf("DELETE FROM %s WHERE user='%s' AND prefkey='%s'",
+ $query = sprintf("DELETE FROM %s WHERE %s='%s' AND %s='%s'",
$this->table,
+ $this->user_field,
$this->dbh->quoteString($user),
+ $this->key_field,
$this->dbh->quoteString($key));
$res = $this->dbh->simpleQuery($query);
if (!$this->open()) {
return false;
}
- $query = sprintf("REPLACE INTO %s (user,prefkey,prefval) ".
+ $query = sprintf("REPLACE INTO %s (%s, %s, %s) ".
"VALUES('%s','%s','%s')",
$this->table,
+ $this->user_field,
+ $this->key_field,
+ $this->val_field,
$this->dbh->quoteString($user),
$this->dbh->quoteString($key),
$this->dbh->quoteString($value));
}
$prefs_cache = array();
- $query = sprintf("SELECT prefkey, prefval FROM %s ".
- "WHERE user = '%s'",
+ $query = sprintf("SELECT %s as prefkey, %s as prefval FROM %s ".
+ "WHERE %s = '%s'",
+ $this->key_field,
+ $this->val_field,
$this->table,
+ $this->user_field,
$this->dbh->quoteString($user));
$res = $this->dbh->query($query);
if (DB::isError($res)) {
if (!$this->open()) {
return;
}
- $query = sprintf("SELECT * FROM %s WHERE user='%s' ".
- "AND prefkey LIKE 'highlight%%' ORDER BY prefkey",
+ $query = sprintf("SELECT %s, %s as prefkey, %s as prefval FROM %s WHERE %s='%s' ".
+ "AND %s LIKE 'highlight%%' ORDER BY %s",
+ $this->user_field,
+ $this->key_field,
+ $this->val_field,
$this->table,
- $this->dbh->quoteString($user));
+ $this->user_field,
+ $this->dbh->quoteString($user),
+ $this->key_field,
+ $this->key_field);
$res = $this->dbh->query($query);
if(DB::isError($res)) {
$hilinum++;
if($oldkey != $newkey) {
- $query = sprintf("UPDATE %s SET prefkey='%s' ".
- "WHERE user ='%s' AND prefkey='%s'",
+ $query = sprintf("UPDATE %s SET %s='%s' ".
+ "WHERE %s ='%s' AND %s='%s'",
$this->table,
+ $this->key_field,
$this->dbh->quoteString($newkey),
+ $this->user_field,
$this->dbh->quoteString($user),
+ $this->key_field,
$this->dbh->quoteString($oldkey));
$res = $this->dbh->simpleQuery($query);
'type' => SMOPT_TYPE_STRING,
'size' => 40,
'default' => 'userprefs' ),
+ '$prefs_user_field' => array('name' => _("Preferences username field"),
+ 'type' => SMOPT_TYPE_STRING,
+ 'size' => 40,
+ 'default' => 'user' ),
+ '$prefs_key_field' => array('name' => _("Preferences key field"),
+ 'type' => SMOPT_TYPE_STRING,
+ 'size' => 40,
+ 'default' => 'prefkey' ),
+ '$prefs_val_field' => array('name' => _("Preferences value field"),
+ 'type' => SMOPT_TYPE_STRING,
+ 'size' => 40,
+ 'default' => 'prefval' ),
/* --------------------------------------------------------*/
'Group7' => array( 'name' => _("Themes"),
'type' => SMOPT_TYPE_TITLE ),