Skip to content

Commit

Permalink
making account preferences work
Browse files Browse the repository at this point in the history
git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@57 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
Kenzaburo Ito committed Dec 10, 2000
1 parent a9a0fd3 commit 1da9550
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 34 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -39,6 +39,7 @@ To Do:
* Added a string_display() function to prevent HTML tags from screwing up display
* Modified version to be an enum.
* Added version editing capability
* Added account preferences

12.06.2000 - 0.10.2

Expand Down
2 changes: 1 addition & 1 deletion UPGRADING
Expand Up @@ -29,7 +29,7 @@ CREATE TABLE mantis_user_profile_table (

ALTER TABLE mantis_bug_table CHANGE version version ENUM ('none') not null;

CREATE TABLE mantis_user_defaults_table (
CREATE TABLE mantis_user_pref_table (
id int(10) unsigned zerofill DEFAULT '0000000000' NOT NULL auto_increment,
user_id int(10) unsigned zerofill DEFAULT '0000000000' NOT NULL,
hide_resolved char(3) NOT NULL,
Expand Down
50 changes: 42 additions & 8 deletions account_prefs_page.php3
Expand Up @@ -17,10 +17,41 @@
<?
db_mysql_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name );

$query = "SELECT *
### grab the user id
$query = "SELECT id
FROM $g_mantis_user_table
WHERE cookie_string='$g_string_cookie_val'";
$result = db_mysql_query($query);
$u_id = mysql_result( $result, 0 );

### Grab the data
$query = "SELECT *
FROM $g_mantis_user_pref_table
WHERE user_id='$u_id'";
$result = db_mysql_query($query);

## OOPS, No entry in the database yet. Lets make one
if ( mysql_num_rows( $result )==0 ) {

### Create row
$query = "INSERT
INTO $g_mantis_user_pref_table
(id, user_id, hide_resolved, limit_view,
show_last, advanced_report, advanced_view)
VALUES
(null, '$u_id', '$g_default_hide_resolved',
'$g_default_limit_view', '$g_default_show_last',
'$g_default_advanced_report', '$g_default_advanced_view')";
$result = db_mysql_query($query);

### Rerun select query
$query = "SELECT *
FROM $g_mantis_user_pref_table
WHERE user_id='$u_id'";
$result = db_mysql_query($query);
}

### prefix data with u_
$row = mysql_fetch_array($result);
extract( $row, EXTR_PREFIX_ALL, "u" );
?>
Expand All @@ -36,6 +67,8 @@
<table width=100% cols=2>
<form method=post action="<? echo $g_account_prefs_update ?>">
<input type=hidden name=f_action value="update">
<input type=hidden name=f_id value="<? echo $u_id ?>">
<input type=hidden name=f_user_id value="<? echo $u_user_id ?>">
<tr>
<td colspan=2 bgcolor=<? echo $g_table_title_color ?>>
<b>Default Account Preferences</b>
Expand All @@ -46,48 +79,49 @@
Hide Resolved
</td>
<td width=60%>
<input type=checkbox name=f_hide_resolved <? if ( $g_hide_resolved_val=="on" ) echo "CHECKED"?>>
<input type=checkbox name=f_hide_resolved <? if ( $u_hide_resolved=="on" ) echo "CHECKED"?>>
</td>
</tr>
<tr bgcolor=<? echo $g_primary_color_light ?>>
<td>
Limit to
</td>
<td>
<input type=text name=f_view_limit size=7 maxlength=7 value="<? echo $g_view_limit_val ?>">
<input type=text name=f_limit_view size=7 maxlength=7 value="<? echo $u_limit_view ?>">
</td>
</tr>
<tr bgcolor=<? echo $g_primary_color_dark ?>>
<td>
Show changed since
</td>
<td>
<input type=text name=f_hours size=4 maxlength=4 value="<? echo $v_hour_count ?>"> hours ago
<input type=text name=f_show_last size=4 maxlength=4 value="<? echo $u_show_last ?>"> hours ago
</td>
</tr>
<tr bgcolor=<? echo $g_primary_color_light ?>>
<td>
Advanced report
</td>
<td>
<input type=checkbox name=f_advanced_report size=4 maxlength=4 value="<? echo $v_hour_count ?>">
<input type=checkbox name=f_advanced_report size=4 maxlength=4 <? if ( $u_advanced_report=="on" ) echo "CHECKED"?>
</td>
</tr>
<tr bgcolor=<? echo $g_primary_color_dark ?>>
<td>
Advanced view
</td>
<td>
<input type=checkbox name=f_advanced_view size=4 maxlength=4 value="<? echo $v_hour_count ?>">
<input type=checkbox name=f_advanced_view size=4 maxlength=4 <? if ( $u_advanced_view=="on" ) echo "CHECKED"?>
</td>
</tr>
<tr align=center>
<td>
<input type=submit value=" Update Prefs ">
</td>
</form>
<form method=post action="<? echo $g_view_prefs_update ?>">
<input type=hidden name=f_action value="reset">
<form method=post action="<? echo $g_account_prefs_update ?>">
<input type=hidden name=f_action value="reset">
<input type=hidden name=f_id value="<? echo $u_id ?>">
<td>
<input type=submit value=" Reset Prefs ">
</td>
Expand Down
35 changes: 25 additions & 10 deletions account_prefs_update.php3
Expand Up @@ -7,19 +7,34 @@
<? include( "core_API.php" ) ?>
<? login_cookie_check() ?>
<?
db_mysql_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name );

### Some sensible defaults
if ( empty( $f_limit_view ) ) {
$f_limit_view = $g_default_limit_view;
}
if ( empty( $f_show_last ) ) {
$f_show_last = $g_default_show_last;
}

if ( $f_action="update" ) {
if ( $f_save_prefs=="on" ) {
setcookie( $g_hide_resolved_cookie, $f_hide_resolved, $g_time_length );
setcookie( $g_view_limit_cookie, $f_view_limit, $g_time_length );
}
else {
setcookie( $g_hide_resolved_cookie, $f_hide_resolved );
setcookie( $g_view_limit_cookie, $f_view_limit );
}
## update preferences
$query = "UPDATE $g_mantis_user_pref_table
SET hide_resolved='$f_hide_resolved', limit_view='$f_limit_view',
show_last='$f_show_last', advanced_report='$f_advanced_report',
advanced_view='$f_advanced_view'
WHERE id='$f_id'";
$result = mysql_query( $query );
}
else if ( $f_action="reset" ) {
setcookie( $g_hide_resolved_cookie );
setcookie( $g_view_limit_cookie );
## reset to defaults
$query = "UPDATE $g_mantis_user_pref_table
SET hide_resolved='$g_default_hide_resolved', limit_view='$g_default_limit_view',
show_last='$g_default_show_last',
advanced_report='$g_default_advanced_report',
advanced_view='$g_default_advanced_view'
WHERE id='$f_id'";
$result = mysql_query( $query );
}
else {
echo "ERROR: invalid action";
Expand Down
10 changes: 10 additions & 0 deletions config_inc.php
Expand Up @@ -83,6 +83,7 @@
$g_mantis_news_table = $g_db_table_prefix."_news_table";
$g_mantis_user_table = $g_db_table_prefix."_user_table";
$g_mantis_user_profile_table = $g_db_table_prefix."_user_profile_table";
$g_mantis_user_pref_table = $g_db_table_prefix."_user_pref_table";
#--------------------

#--------------------
Expand Down Expand Up @@ -198,6 +199,15 @@
$g_wait_time = 1; # in seconds
#--------------------

#--------------------
# defaults for viewing preferences
$g_default_limit_view = 50;
$g_default_show_last = 1;
$g_default_hide_resolved = ""; # set to on to enable
$g_default_advanced_report = ""; # set to on to enable
$g_default_advanced_view = ""; # set to on to enable
#--------------------

#--------------------
# date lengths to bount bugs by
# folows the english required by strtotime()
Expand Down
43 changes: 43 additions & 0 deletions core_API.php
Expand Up @@ -410,6 +410,29 @@ function index_login_cookie_check( $p_redirect_url="" ) {
}
}
#--------------------
### Returns the id of the currently logged in user, otherwise 0
function get_current_user_id() {
global $g_string_cookie_val,
$g_hostname, $g_db_username, $g_db_password, $g_database_name,
$g_mantis_user_table;

### if logged in
if ( isset( $g_string_cookie_val ) ) {

db_mysql_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name );

### get user info
$query = "SELECT id
FROM $g_mantis_user_table
WHERE cookie_string='$g_string_cookie_val'";
$result = db_mysql_query( $query );
return mysql_result( $result, 0 );
}
else {
return 0;
}
}
#--------------------
####################
# Authentication API
####################
Expand Down Expand Up @@ -442,6 +465,26 @@ function create_cookie_string( $p_email ) {
}
#--------------------
####################
# Preferences API
####################
#--------------------
### return a vlue of a table of the currently logged in user
function get_user_value( $p_table_name, $p_table_field ) {
global $g_hostname, $g_db_username, $g_db_password, $g_database_name;

### get user id
$u_id = get_current_user_id();

db_mysql_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name );

$query = "SELECT $p_table_field
FROM $p_table_name
WHERE user_id='$u_id'";
$result = db_mysql_query( $query );
return mysql_result( $result, 0 );
}
#--------------------
####################
# Date API
####################
#--------------------
Expand Down
2 changes: 1 addition & 1 deletion db_generate.sql
Expand Up @@ -132,7 +132,7 @@ CREATE TABLE mantis_user_profile_table (
# Table structure for table 'mantis_user_defaults_table'
#

CREATE TABLE mantis_user_defaults_table (
CREATE TABLE mantis_user_pref_table (
id int(10) unsigned zerofill DEFAULT '0000000000' NOT NULL auto_increment,
user_id int(10) unsigned zerofill DEFAULT '0000000000' NOT NULL,
hide_resolved char(3) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion db_upgrade.sql
Expand Up @@ -44,7 +44,7 @@ ALTER TABLE mantis_bug_table CHANGE version version ENUM ('none') not null;

# New table for default user preferences

CREATE TABLE mantis_user_defaults_table (
CREATE TABLE mantis_user_pref_table (
id int(10) unsigned zerofill DEFAULT '0000000000' NOT NULL auto_increment,
user_id int(10) unsigned zerofill DEFAULT '0000000000' NOT NULL,
hide_resolved char(3) NOT NULL,
Expand Down
18 changes: 14 additions & 4 deletions menu_inc.php
Expand Up @@ -7,9 +7,11 @@
<?
if ( !isset( $g_string_cookie_val ) ) {
### required for variables to get picked up
global $g_string_cookie_val, $g_mantis_user_table, $g_path,
global $g_string_cookie_val, $g_path,
$g_mantis_user_table, $g_mantis_user_pref_table,
$g_hostname, $g_db_username, $g_db_password, $g_database_name,
$g_main_page, $g_view_bug_all_page, $g_report_bug_page,
$g_main_page, $g_view_bug_all_page,
$g_report_bug_page, $g_report_bug_advanced_page,
$g_summary_page, $g_account_page, $g_manage_page,
$g_news_menu_page, $g_logout_page;
}
Expand All @@ -29,9 +31,17 @@
<font face=Verdana size=-1>
<a href="<? echo $g_path.$g_main_page ?>">Main</a> |
<a href="<? echo $g_path.$g_view_bug_all_page ?>">View Bugs</a> |
<? if ( $t_access_level!="viewer" ) { ?>
<?
if ( $t_access_level!="viewer" ) {
if ( get_user_value( $g_mantis_user_pref_table, "advanced_view" )=="on" ) {
?>
<a href="<? echo $g_path.$g_report_bug_advanced_page ?>">Report Bug</a> |
<? } else { ?>
<a href="<? echo $g_path.$g_report_bug_page ?>">Report Bug</a> |
<? } ?>
<?
}
} # end report/viewer if
?>
<a href="<? echo $g_path.$g_summary_page ?>">Summary</a> |
<a href="<? echo $g_path.$g_account_page ?>">Account</a> |
<? if ( $t_access_level=="administrator" ) { ?>
Expand Down
26 changes: 17 additions & 9 deletions view_bug_all_page.php3
Expand Up @@ -18,7 +18,15 @@
db_mysql_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name );

### check whether the user wanted to hide the results
$f_hide_resolved = $g_hide_resolved_val;
$f_hide_resolved = get_user_value( $g_mantis_user_pref_table, "hide_resolved" );
$f_limit_view = get_user_value( $g_mantis_user_pref_table, "limit_view" );

if ( isset( $g_hide_resolved_val ) ) {
$f_hide_resolved = $g_hide_resolved_val;
}
if ( isset( $g_view_limit_val ) ) {
$f_limit_view = $g_view_limit_val;
}

### basically we toggle between ASC and DESC if the user clicks the
### same sort order
Expand Down Expand Up @@ -99,15 +107,15 @@
}
### build our query string based on our viewing criteria
$query = "SELECT * FROM $g_mantis_bug_table";
if ( $g_hide_resolved_val=="on" ) {
if ( $f_hide_resolved=="on" ) {
$query = $query." WHERE status<>'resolved'";
}
if ( !isset( $f_sort ) ) {
$f_sort="id";
}
$query = $query." ORDER BY '$f_sort' $f_dir";
if ( isset( $g_view_limit_val ) ) {
$query = $query." LIMIT $f_offset, $g_view_limit_val";
if ( isset( $f_limit_view ) ) {
$query = $query." LIMIT $f_offset, $f_limit_view";
}

### perform query
Expand Down Expand Up @@ -210,8 +218,8 @@
</table>

<?
$f_offset_next = $f_offset + $g_view_limit_val;
$f_offset_prev = $f_offset - $g_view_limit_val;
$f_offset_next = $f_offset + $f_limit_view;
$f_offset_prev = $f_offset - $f_limit_view;

if ( $f_offset_prev < 0 ) {
$f_offset_prev = -1;
Expand All @@ -220,10 +228,10 @@

<div align=center>
<? if ( $f_offset_prev >= 0 ) { ?>
<a href="<? echo $g_view_bug_all_page ?>?f_offset=<? echo $f_offset_prev ?>">View Prev <? echo $g_view_limit_val ?></a>
<a href="<? echo $g_view_bug_all_page ?>?f_offset=<? echo $f_offset_prev ?>">View Prev <? echo $f_limit_view ?></a>
<? } ?>
<? if ( $row_count == $g_view_limit_val ) { ?>
<a href="<? echo $g_view_bug_all_page ?>?f_offset=<? echo $f_offset_next ?>">View Next <? echo $g_view_limit_val ?></a>
<? if ( $row_count == $f_limit_view ) { ?>
<a href="<? echo $g_view_bug_all_page ?>?f_offset=<? echo $f_offset_next ?>">View Next <? echo $f_limit_view ?></a>
<? } ?>
</div>

Expand Down

0 comments on commit 1da9550

Please sign in to comment.