From b4c87cc504216af360f18bcb3123540fbea5091a Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 26 Jan 2010 10:57:00 +0000 Subject: ACP usability git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10450 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 73 ++++++++++++++++++---- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 45811c5d26..7526cb67cf 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -214,6 +214,22 @@ class phpbb_captcha_qa */ function get_demo_template() { + global $config, $db, $template; + + if ($this->is_available()) + { + $sql = 'SELECT question_text + FROM ' . CAPTCHA_QUESTIONS_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; + $result = $db->sql_query_limit($sql, 1); + if ($row = $db->sql_fetchrow($result)) + { + $template->assign_vars(array( + 'QA_CONFIRM_QUESTION' => $row['question_text'], + )); + } + $db->sql_freeresult($result); + } return 'captcha_qa_acp_demo.html'; } @@ -393,7 +409,6 @@ class phpbb_captcha_qa { global $db, $user; - if (!sizeof($this->question_ids)) { return false; @@ -617,21 +632,28 @@ class phpbb_captcha_qa } else if ($question_id && $action == 'delete') { - if (confirm_box(true)) + if ($this->get_class_name() !== $config['captcha_plugin'] || !$this->acp_is_last($question_id)) { - $this->acp_delete_question($question_id); + if (confirm_box(true)) + { + $this->acp_delete_question($question_id); - trigger_error($user->lang['QUESTION_DELETED'] . adm_back_link($list_url)); + trigger_error($user->lang['QUESTION_DELETED'] . adm_back_link($list_url)); + } + else + { + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + 'question_id' => $question_id, + 'action' => $action, + 'configure' => 1, + 'select_captcha' => $this->get_class_name(), + )) + ); + } } else { - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( - 'question_id' => $question_id, - 'action' => $action, - 'configure' => 1, - 'select_captcha' => $this->get_class_name(), - )) - ); + trigger_error($user->lang['QA_LAST_QUESTION'] . adm_back_link($list_url), E_USER_WARNING); } } else @@ -711,7 +733,7 @@ class phpbb_captcha_qa } else if ($submit) { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($list_url)); + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($list_url), E_USER_WARNING); } } } @@ -942,6 +964,33 @@ class phpbb_captcha_qa return $langs; } + + + + /** + * See if there is a question other than the one we have + */ + function acp_is_last($question_id) + { + global $config, $db; + + if ($question_id) + { + $sql = 'SELECT question_id + FROM ' . CAPTCHA_QUESTIONS_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "' + AND question_id <> " . (int) $question_id; + $result = $db->sql_query_limit($sql, 1); + $question = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$question) + { + return true; + } + return false; + } + } } ?> \ No newline at end of file -- cgit v1.2.1 From 345de34ac1645f578498930a7927e1cf9a6b94e7 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 26 Jan 2010 11:07:47 +0000 Subject: tuning git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10451 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 7526cb67cf..c121af5b3a 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -253,11 +253,11 @@ class phpbb_captcha_qa /** * API function */ - function garbage_collect($type) + function garbage_collect($type = 0) { global $db, $config; - $sql = 'SELECT DISTINCT c.session_id + $sql = 'SELECT c.question_id FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' c LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) @@ -266,19 +266,19 @@ class phpbb_captcha_qa $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) - { + {print_r($row); $sql_in = array(); do { - $sql_in[] = (string) $row['session_id']; + $sql_in[] = (string) $row['question_id']; } while ($row = $db->sql_fetchrow($result)); if (sizeof($sql_in)) { $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' - WHERE ' . $db->sql_in_set('session_id', $sql_in); + WHERE ' . $db->sql_in_set('question_id', $sql_in); $db->sql_query($sql); } } -- cgit v1.2.1 From 3e224cf856f7ef414e341a980d8175da0e373fc8 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 26 Jan 2010 11:41:43 +0000 Subject: debug code, begone git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10453 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index c121af5b3a..c8f68f23f0 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -266,7 +266,7 @@ class phpbb_captcha_qa $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) - {print_r($row); + { $sql_in = array(); do -- cgit v1.2.1 From 8a9c7c92bef76a8dfbb72556aaf55f961aa711b3 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 26 Jan 2010 14:01:20 +0000 Subject: tuning git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10454 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index c8f68f23f0..619a05663f 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -87,6 +87,12 @@ class phpbb_captcha_qa } $db->sql_freeresult($result); } + + // Possible snag: the user didn't send a confirm_id. See, if we have something on file. + if (!strlen($this->confirm_id)) + { + $this->load_confirm_id(); + } // okay, if there is a confirm_id, we try to load that confirm's state if (!strlen($this->confirm_id) || !$this->load_answer()) @@ -473,6 +479,38 @@ class phpbb_captcha_qa $this->load_answer(); } + + /** + * See if there is already an entry for the current session. + */ + function load_confirm_id() + { + global $db, $user; + + if (!sizeof($this->question_ids)) + { + return false; + } + + $sql = 'SELECT confirm_id + FROM ' . CAPTCHA_QA_CONFIRM_TABLE . " + WHERE + session_id = '" . $db->sql_escape($user->session_id) . "' + AND lang_iso = '" . $db->sql_escape($this->question_lang) . "' + AND confirm_type = " . $this->type; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + $this->confirm_id = $row['confirm_id']; + return true; + } + + return false; + } + /** * Look up everything we need and populate the instance variables. */ -- cgit v1.2.1 From 62d7e3c6340086548790bd136bc33fa19fee1746 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 26 Jan 2010 14:58:55 +0000 Subject: erm, that wouldn't work git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10457 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 619a05663f..065de23e72 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -263,7 +263,7 @@ class phpbb_captcha_qa { global $db, $config; - $sql = 'SELECT c.question_id + $sql = 'SELECT c.confirm_id FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' c LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id) @@ -277,14 +277,14 @@ class phpbb_captcha_qa do { - $sql_in[] = (string) $row['question_id']; + $sql_in[] = (string) $row['confirm_id']; } while ($row = $db->sql_fetchrow($result)); if (sizeof($sql_in)) { $sql = 'DELETE FROM ' . CAPTCHA_QA_CONFIRM_TABLE . ' - WHERE ' . $db->sql_in_set('question_id', $sql_in); + WHERE ' . $db->sql_in_set('confirm_id', $sql_in); $db->sql_query($sql); } } -- cgit v1.2.1 From 81e62b4da808767fb7eef7fcb625383cbea0d9a4 Mon Sep 17 00:00:00 2001 From: Henry Sudhof Date: Tue, 26 Jan 2010 15:34:21 +0000 Subject: okay, now the confirm_id is no longer enough to get a new row into the qa table git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@10459 89ea8834-ac86-4346-8a33-228a782c2dd0 --- .../captcha/plugins/phpbb_captcha_qa_plugin.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php') diff --git a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php index 065de23e72..ef4d8e9fac 100644 --- a/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php +++ b/phpBB/includes/captcha/plugins/phpbb_captcha_qa_plugin.php @@ -88,14 +88,8 @@ class phpbb_captcha_qa $db->sql_freeresult($result); } - // Possible snag: the user didn't send a confirm_id. See, if we have something on file. - if (!strlen($this->confirm_id)) - { - $this->load_confirm_id(); - } - - // okay, if there is a confirm_id, we try to load that confirm's state - if (!strlen($this->confirm_id) || !$this->load_answer()) + // okay, if there is a confirm_id, we try to load that confirm's state. If not, we try to find one + if (!$this->load_answer() && (!$this->load_confirm_id() || !$this->load_answer())) { // we have no valid confirm ID, better get ready to ask something $this->select_question(); @@ -486,11 +480,6 @@ class phpbb_captcha_qa function load_confirm_id() { global $db, $user; - - if (!sizeof($this->question_ids)) - { - return false; - } $sql = 'SELECT confirm_id FROM ' . CAPTCHA_QA_CONFIRM_TABLE . " @@ -507,7 +496,6 @@ class phpbb_captcha_qa $this->confirm_id = $row['confirm_id']; return true; } - return false; } @@ -518,7 +506,7 @@ class phpbb_captcha_qa { global $db, $user; - if (!sizeof($this->question_ids)) + if (!strlen($this->confirm_id) || !sizeof($this->question_ids)) { return false; } -- cgit v1.2.1