summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2015-01-21 01:54:45 +0000
committerGreg Roach <fisharebest@gmail.com>2015-01-21 01:54:45 +0000
commitc38ff5e556f4e998cdab43df05a4c8d35106b393 (patch)
treee5bb91a8d4c4a7c8c192336b80d30043e085aebb
parent1cbc816e4ae8f71235de84e2cdb03dfeef8670fd (diff)
downloadwebtrees-c38ff5e556f4e998cdab43df05a4c8d35106b393.tar.gz
webtrees-c38ff5e556f4e998cdab43df05a4c8d35106b393.tar.bz2
webtrees-c38ff5e556f4e998cdab43df05a4c8d35106b393.zip
Remove remaining inline-edit code
-rw-r--r--admin_site_access.php22
-rw-r--r--admin_users.php11
-rw-r--r--includes/functions/functions_edit.php129
-rw-r--r--save.php204
-rw-r--r--tests/includes/functions/FunctionsEditTest.php45
-rw-r--r--tests/includes/functions/FunctionsTest.php2
6 files changed, 23 insertions, 390 deletions
diff --git a/admin_site_access.php b/admin_site_access.php
index e4197f4d4f..9c2895c1c4 100644
--- a/admin_site_access.php
+++ b/admin_site_access.php
@@ -24,6 +24,12 @@ define('WT_SCRIPT_NAME', 'admin_site_access.php');
require './includes/session.php';
require WT_ROOT . 'includes/functions/functions_edit.php';
+$rules = array(
+ 'allow' => /* I18N: An access rule - allow access to the site */ WT_I18N::translate('allow'),
+ 'deny' => /* I18N: An access rule - deny access to the site */ WT_I18N::translate('deny'),
+ 'robot' => /* I18N: http://en.wikipedia.org/wiki/Web_crawler */ WT_I18N::translate('robot'),
+);
+
$controller = new WT_Controller_Page;
$controller
->restrictAccess(Auth::isAdmin())
@@ -104,15 +110,7 @@ case 'load_rules':
foreach ($data as &$datum) {
$site_access_rule_id = $datum[7];
$user_agent = $datum[4];
- $datum[0] = edit_field_inline('site_access_rule-ip_address_start-' . $site_access_rule_id, $datum[0]);
- $datum[2] = edit_field_inline('site_access_rule-ip_address_end-' . $site_access_rule_id, $datum[2]);
- $datum[4] = edit_field_inline('site_access_rule-user_agent_pattern-' . $site_access_rule_id, $datum[4]);
- $datum[5] = select_edit_control_inline('site_access_rule-rule-' . $site_access_rule_id, array(
- 'allow' => /* I18N: An access rule - allow access to the site */ WT_I18N::translate('allow'),
- 'deny' => /* I18N: An access rule - deny access to the site */ WT_I18N::translate('deny'),
- 'robot' => /* I18N: http://en.wikipedia.org/wiki/Web_crawler */ WT_I18N::translate('robot'),
- ), null, $datum[5]);
- $datum[6] = edit_field_inline('site_access_rule-comment-' . $site_access_rule_id, $datum[6]);
+ $datum[5] = $rules[$datum[5]];
$datum[7] = '<button class="btn btn-danger" onclick="if (confirm(\'' . WT_Filter::escapeHtml(WT_I18N::translate('Are you sure you want to delete ā€œ%sā€?', strip_tags($user_agent))) . '\')) { document.location=\'' . WT_SCRIPT_NAME . '?action=delete&amp;site_access_rule_id=' . $site_access_rule_id . '\'; }"><i class="fa fa-trash-o"></i></button>';
}
@@ -128,7 +126,8 @@ case 'load_rules':
'recordsFiltered' => $recordsFiltered,
'data' => $data
));
- exit;
+
+ return;
case 'load_unknown':
Zend_Session::writeClose();
// AJAX callback for datatables
@@ -201,7 +200,8 @@ case 'load_unknown':
'recordsFiltered' => $recordsFiltered,
'data' => $data
));
- exit;
+
+ return;
}
$controller
diff --git a/admin_users.php b/admin_users.php
index 5c7181f712..84a3d0119d 100644
--- a/admin_users.php
+++ b/admin_users.php
@@ -91,6 +91,17 @@ case 'save':
}
if ($user) {
+ // Approving for the first time? Send a confirmation email
+ if ($approved && !$user->getPreference('verified_by_admin') && $user->getPreference('sessiontime') == 0) {
+ WT_I18N::init($user->getPreference('language'));
+ WT_Mail::systemMessage(
+ $WT_TREE,
+ $user,
+ WT_I18N::translate('Approval of account at %s', WT_SERVER_NAME . WT_SCRIPT_PATH),
+ WT_I18N::translate('The administrator at the webtrees site %s has approved your application for an account. You may now login by accessing the following link: %s', WT_SERVER_NAME . WT_SCRIPT_PATH, WT_SERVER_NAME . WT_SCRIPT_PATH)
+ );
+ }
+
$user
->setPreference('theme', $theme)
->setPreference('language', $language)
diff --git a/includes/functions/functions_edit.php b/includes/functions/functions_edit.php
index 023870a568..a26bc7d36b 100644
--- a/includes/functions/functions_edit.php
+++ b/includes/functions/functions_edit.php
@@ -25,50 +25,6 @@ use Rhumsaa\Uuid\Uuid;
use WT\Auth;
/**
- * Create an edit control for inline editing using jeditable.
- *
- * @param string $name
- * @param string $value
- * @param WT_Controller_Base $controller
- *
- * @return string
- */
-function edit_field_inline($name, $value, WT_Controller_Base $controller = null) {
- $html = '<span class="editable" id="' . $name . '">' . WT_Filter::escapeHtml($value) . '</span>';
- $js = 'jQuery("#' . $name . '").editable("' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'save.php", {submitdata: {csrf: WT_CSRF_TOKEN}, submit:"&nbsp;&nbsp;' . /* I18N: button label */ WT_I18N::translate('save') . '&nbsp;&nbsp;", style:"inherit", placeholder: "' . WT_I18N::translate('click to edit') . '"});';
-
- if ($controller) {
- $controller->addInlineJavascript($js);
- return $html;
- } else {
- // For AJAX callbacks
- return $html . '<script>' . $js . '</script>';
- }
-}
-
-/**
- * Create a text area for inline editing using jeditable.
- *
- * @param string $name
- * @param string $value
- * @param WT_Controller_Base $controller
- *
- * @return string
- */
-function edit_text_inline($name, $value, WT_Controller_Base $controller = null) {
- $html = '<span class="editable" style="white-space:pre-wrap;" id="' . $name . '">' . WT_Filter::escapeHtml($value) . '</span>';
- $js = 'jQuery("#' . $name . '").editable("' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'save.php", {submitdata: {csrf: WT_CSRF_TOKEN}, submit:"&nbsp;&nbsp;' . WT_I18N::translate('save') . '&nbsp;&nbsp;", style:"inherit", placeholder: "' . WT_I18N::translate('click to edit') . '", type: "textarea", rows:4, cols:60 });';
-
- if ($controller) {
- $controller->addInlineJavascript($js);
- return $html;
- } else {
- // For AJAX callbacks
- return $html . '<script>' . $js . '</script>';
- }
-}
-
-/**
* Create a <select> control for a form.
*
* @param string $name
@@ -110,40 +66,6 @@ function select_edit_control($name, $values, $empty, $selected, $extra = '') {
}
/**
- * An inline-editing version of select_edit_control()
- *
- * @param string $name
- * @param string[] $values
- * @param string|null $empty
- * @param string $selected
- * @param WT_Controller_Base $controller
- *
- * @return string
- */
-function select_edit_control_inline($name, $values, $empty, $selected, WT_Controller_Base $controller = null) {
- if (!is_null($empty)) {
- // Push ''=>$empty onto the front of the array, maintaining keys
- $tmp = array(''=>WT_Filter::escapeHtml($empty));
- foreach ($values as $key=>$value) {
- $tmp[$key] = WT_Filter::escapeHtml($value);
- }
- $values = $tmp;
- }
- $values['selected'] = WT_Filter::escapeHtml($selected);
-
- $html = '<span class="editable" id="' . $name . '">' . (array_key_exists($selected, $values) ? $values[$selected] : '') . '</span>';
- $js = 'jQuery("#' . $name . '").editable("' . WT_SERVER_NAME . WT_SCRIPT_PATH . 'save.php", {submitdata: {csrf: WT_CSRF_TOKEN}, type:"select", data:' . json_encode($values) . ', submit:"&nbsp;&nbsp;' . WT_I18N::translate('save') . '&nbsp;&nbsp;", style:"inherit", placeholder: "' . WT_I18N::translate('click to edit') . '", callback:function(value, settings) {jQuery(this).html(settings.data[value]);} });';
-
- if ($controller) {
- $controller->addInlineJavascript($js);
- return $html;
- } else {
- // For AJAX callbacks
- return $html . '<script>' . $js . '</script>';
- }
-}
-
-/**
* Create a set of radio buttons for a form
*
* @param string $name The ID for the form element
@@ -181,21 +103,6 @@ function edit_field_yes_no($name, $selected = false) {
}
/**
- * An inline-editing version of edit_field_yes_no()
- *
- * @param string $name
- * @param boolean $selected
- * @param WT_Controller_Base $controller
- *
- * @return string
- */
-function edit_field_yes_no_inline($name, $selected = false, WT_Controller_Base $controller = null) {
- return select_edit_control_inline(
- $name, array(true=>WT_I18N::translate('yes'), false=>WT_I18N::translate('no')), null, (int) $selected, $controller
- );
-}
-
-/**
* Print an edit control for a checkbox.
*
* @param string $name
@@ -335,27 +242,6 @@ function edit_field_contact($name, $selected = '', $extra = '') {
}
/**
- * Print an edit control for a contact method field.
- *
- * @param string $name
- * @param string $selected
- * @param WT_Controller_Base $controller
- *
- * @return string
- */
-function edit_field_contact_inline($name, $selected = '', WT_Controller_Base $controller = null) {
- // Different ways to contact the users
- $CONTACT_METHODS = array(
- 'messaging' =>WT_I18N::translate('webtrees internal messaging'),
- 'messaging2'=>WT_I18N::translate('Internal messaging with emails'),
- 'messaging3'=>WT_I18N::translate('webtrees sends emails with no storage'),
- 'mailto' =>WT_I18N::translate('Mailto link'),
- 'none' =>WT_I18N::translate('No contact'),
- );
- return select_edit_control_inline($name, $CONTACT_METHODS, null, $selected, $controller);
-}
-
-/**
* Print an edit control for a language field.
*
* @param string $name
@@ -369,21 +255,6 @@ function edit_field_language($name, $selected = '', $extra = '') {
}
/**
- * An inline-editing version of edit_field_language().
- *
- * @param string $name
- * @param string $selected
- * @param WT_Controller_Base $controller
- *
- * @return string
- */
-function edit_field_language_inline($name, $selected = '', WT_Controller_Base $controller = null) {
- return select_edit_control_inline(
- $name, WT_I18N::installed_languages(), null, $selected, $controller
- );
-}
-
-/**
* Print an edit control for a range of integers.
*
* @param string $name
diff --git a/save.php b/save.php
deleted file mode 100644
index 02bb11e925..0000000000
--- a/save.php
+++ /dev/null
@@ -1,204 +0,0 @@
-<?php
-// Callback function for inline editing.
-//
-// webtrees: Web based Family History software
-// Copyright (C) 2015 webtrees development team.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-use WT\Auth;
-use WT\User;
-
-define('WT_SCRIPT_NAME', 'save.php');
-require './includes/session.php';
-
-Zend_Session::writeClose();
-
-// The script must always end by calling one of these two functions.
-function ok() {
- global $value;
- header('Content-type: text/html; charset=UTF-8');
- echo $value;
- exit;
-}
-function fail() {
- // Any 4xx code should work. jeditable recommends 406
- header('HTTP/1.0 406 Not Acceptable');
- exit;
-}
-
-// Do we have a valid CSRF token?
-if (!WT_Filter::checkCsrf()) {
- fail();
-}
-
-// The data item to updated must identified with a single "id" element.
-// The id must be a valid CSS identifier, so it can be used in HTML.
-// We use "[A-Za-z0-9_]+" separated by "-".
-
-$id = WT_Filter::post('id', '[a-zA-Z0-9_-]+');
-list($table, $id1, $id2, $id3) = explode('-', $id . '---');
-
-// The replacement value.
-$value = WT_Filter::post('value');
-
-// Every switch must have a default case, and every case must end in ok() or fail()
-
-switch ($table) {
-case 'site_access_rule':
- //////////////////////////////////////////////////////////////////////////////
- // Table name: WT_SITE_ACCESS_RULE
- // ID format: site_access_rule-{column_name}-{user_id}
- //////////////////////////////////////////////////////////////////////////////
-
- if (!Auth::isAdmin()) {
- fail();
- }
- switch ($id1) {
- case 'ip_address_start':
- case 'ip_address_end':
- WT_DB::prepare("UPDATE `##site_access_rule` SET {$id1}=INET_ATON(?) WHERE site_access_rule_id=?")
- ->execute(array($value, $id2));
- $value = WT_DB::prepare(
- "SELECT INET_NTOA({$id1}) FROM `##site_access_rule` WHERE site_access_rule_id=?"
- )->execute(array($id2))->fetchOne();
- ok();
- break;
- case 'user_agent_pattern':
- case 'rule':
- case 'comment':
- WT_DB::prepare("UPDATE `##site_access_rule` SET {$id1}=? WHERE site_access_rule_id=?")
- ->execute(array($value, $id2));
- ok();
- }
- fail();
-
-case 'user':
- //////////////////////////////////////////////////////////////////////////////
- // Table name: WT_USER
- // ID format: user-{column_name}-{user_id}
- //////////////////////////////////////////////////////////////////////////////
-
- $user = User::find($id2);
-
- // Authorisation
- if (!Auth::isAdmin() && Auth::id() != $user) {
- fail();
- }
-
- // Validation
- switch ($id1) {
- case 'password':
- $user->setPassword($value);
- // The password will be displayed as "click to edit" on screen.
- // Accept the update, but pretend to fail. This will leave the "click to edit" on screen
- fail();
- break;
- case 'user_name':
- $user->setUserName($value);
- break;
- case 'real_name':
- $user->setRealName($value);
- break;
- case 'email':
- $user->setEmail($value);
- break;
- default:
- // An unrecognized setting
- fail();
- break;
- }
- ok();
- break;
-
-case 'user_gedcom_setting':
- //////////////////////////////////////////////////////////////////////////////
- // Table name: WT_USER_GEDCOM_SETTING
- // ID format: user_gedcom_setting-{user_id}-{gedcom_id}-{setting_name}
- //////////////////////////////////////////////////////////////////////////////
-
- switch ($id3) {
- case 'rootid':
- case 'gedcomid':
- case 'canedit':
- case 'RELATIONSHIP_PATH_LENGTH':
- $user = User::find($id1);
- $tree = WT_Tree::get($id2);
- if (Auth::isManager($tree)) {
- $tree->setUserPreference($user, $id3, $value);
- ok();
- break;
- }
- }
- fail();
- break;
-
-case 'user_setting':
- //////////////////////////////////////////////////////////////////////////////
- // Table name: WT_USER_SETTING
- // ID format: user_setting-{user_id}-{setting_name}
- //////////////////////////////////////////////////////////////////////////////
-
- $user = User::find($id1);
- // Authorisation
- if (!(Auth::isAdmin() || $user && $user->getPreference('editaccount') && in_array($id2, array('language', 'visible_online', 'contact_method')))) {
- fail();
- }
-
- // Validation
- switch ($id2) {
- case 'canadmin':
- // Cannot change our own admin status - either to add it or remove it
- if (Auth::user() == $user) {
- fail();
- }
- break;
- case 'verified_by_admin':
- // Approving for the first time? Send a confirmation email
- if ($value && !$user->getPreference('verified_by_admin') && $user->getPreference('sessiontime') == 0) {
- WT_I18N::init($user->getPreference('language'));
- WT_Mail::systemMessage(
- $WT_TREE,
- $user,
- WT_I18N::translate('Approval of account at %s', WT_SERVER_NAME . WT_SCRIPT_PATH),
- WT_I18N::translate('The administrator at the webtrees site %s has approved your application for an account. You may now login by accessing the following link: %s', WT_SERVER_NAME . WT_SCRIPT_PATH, WT_SERVER_NAME . WT_SCRIPT_PATH)
- );
- }
- break;
- case 'auto_accept':
- case 'editaccount':
- case 'verified':
- case 'visibleonline':
- case 'max_relation_path':
- $value = (int) $value;
- break;
- case 'contactmethod':
- case 'comment':
- case 'language':
- case 'theme':
- break;
- default:
- // An unrecognized setting
- fail();
- }
-
- // Authorised and valid - make update
- $user->setPreference($id2, $value);
- ok();
-
-default:
- // An unrecognized table
- fail();
-}
diff --git a/tests/includes/functions/FunctionsEditTest.php b/tests/includes/functions/FunctionsEditTest.php
index afcc7980a3..00b9dfe90a 100644
--- a/tests/includes/functions/FunctionsEditTest.php
+++ b/tests/includes/functions/FunctionsEditTest.php
@@ -24,24 +24,6 @@ class FunctionsEditTest extends PHPUnit_Framework_TestCase {
}
/**
- * Test that function edit_field_inline() exists in the global namespace.
- *
- * @return void
- */
- public function testFunctionEditFieldInlineExists() {
- $this->assertEquals(function_exists('\\edit_field_inline'), true);
- }
-
- /**
- * Test that function edit_text_inline() exists in the global namespace.
- *
- * @return void
- */
- public function testFunctionEditTextInlineExists() {
- $this->assertEquals(function_exists('\\edit_text_inline'), true);
- }
-
- /**
* Test that function select_edit_control() exists in the global namespace.
*
* @return void
@@ -51,15 +33,6 @@ class FunctionsEditTest extends PHPUnit_Framework_TestCase {
}
/**
- * Test that function select_edit_control_inline() exists in the global namespace.
- *
- * @return void
- */
- public function testFunctionSelectEditControlInlineExists() {
- $this->assertEquals(function_exists('\\select_edit_control_inline'), true);
- }
-
- /**
* Test that function radio_buttons() exists in the global namespace.
* @return void
*
@@ -133,15 +106,6 @@ class FunctionsEditTest extends PHPUnit_Framework_TestCase {
}
/**
- * Test that function edit_field_contact_inline() exists in the global namespace.
- *
- * @return void
- */
- public function testFunctionEditFieldContactInlineExists() {
- $this->assertEquals(function_exists('\\edit_field_contact_inline'), true);
- }
-
- /**
* Test that function edit_field_language() exists in the global namespace.
*
* @return void
@@ -151,15 +115,6 @@ class FunctionsEditTest extends PHPUnit_Framework_TestCase {
}
/**
- * Test that function edit_field_language_inline() exists in the global namespace.
- *
- * @return void
- */
- public function testFunctionEditFieldLanguageInlineExists() {
- $this->assertEquals(function_exists('\\edit_field_language_inline'), true);
- }
-
- /**
* Test that function edit_field_integers() exists in the global namespace.
*
* @return void
diff --git a/tests/includes/functions/FunctionsTest.php b/tests/includes/functions/FunctionsTest.php
index b598b10f12..958a7fbfa2 100644
--- a/tests/includes/functions/FunctionsTest.php
+++ b/tests/includes/functions/FunctionsTest.php
@@ -185,7 +185,7 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
}
/**
- * Tests for function edit_field_inline()
+ * Tests for function isFileExternal()
*
* @return void
*/