diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php
index 2eb63af9d..906e89f4f 100644
--- a/modules/popup-dialog.php
+++ b/modules/popup-dialog.php
@@ -990,6 +990,59 @@
type=\"submit\">".
__('Close this window')."";
print "";
+ }
+
+ if ($id == "addInstance") {
+
+ print "";
+ print "";
+
+ print "
".__("Instance")."
";
+
+ print "";
+
+ /* URL */
+
+ print __("URL:") . " ";
+
+ print "";
+
+ print "
";
+
+ $access_key = sha1(uniqid(rand(), true));
+
+ /* Access key */
+
+ print __("Access key:") . " ";
+
+ print "";
+
+ print "";
+
+ print "";
+
+ return;
+
+
+
+
}
print "";
diff --git a/modules/pref-instances.php b/modules/pref-instances.php
index c57b46f35..ab3d78c44 100644
--- a/modules/pref-instances.php
+++ b/modules/pref-instances.php
@@ -3,6 +3,37 @@
$subop = $_REQUEST['subop'];
+ if ($subop == "remove") {
+ $ids = db_escape_string($_REQUEST['ids']);
+
+ db_query($link, "DELETE FROM ttrss_linked_instances WHERE
+ id IN ($ids)");
+
+ return;
+ }
+
+ if ($subop == "add") {
+ $id = db_escape_string($_REQUEST["id"]);
+ $access_url = db_escape_string($_REQUEST["access_url"]);
+ $access_key = db_escape_string($_REQUEST["access_key"]);
+
+ db_query($link, "BEGIN");
+
+ $result = db_query($link, "SELECT id FROM ttrss_linked_instances
+ WHERE access_url = '$access_url'");
+
+ if (db_num_rows($result) == 0) {
+ db_query($link, "INSERT INTO ttrss_linked_instances
+ (access_url, access_key, last_connected) VALUES
+ ('$access_url', '$access_key', '1970-01-01')");
+
+ }
+
+ db_query($link, "COMMIT");
+
+ return;
+ }
+
if ($subop == "edit") {
$id = db_escape_string($_REQUEST["id"]);
@@ -67,7 +98,8 @@
$access_key = db_escape_string($_REQUEST["access_key"]);
db_query($link, "UPDATE ttrss_linked_instances SET
- access_key = '$access_key', access_url = '$access_url'
+ access_key = '$access_key', access_url = '$access_url',
+ last_connected = '1970-01-01'
WHERE id = '$id'");
return;
diff --git a/prefs.js b/prefs.js
index 5c7131d2f..1cf294329 100644
--- a/prefs.js
+++ b/prefs.js
@@ -1785,8 +1785,43 @@ function getSelectedInstances() {
function addInstance() {
try {
- alert("TODO: function not implemented.");
+ var query = "backend.php?op=dlg&id=addInstance";
+ if (dijit.byId("instanceAddDlg"))
+ dijit.byId("instanceAddDlg").destroyRecursive();
+
+ dialog = new dijit.Dialog({
+ id: "instanceAddDlg",
+ title: __("Link Instance"),
+ style: "width: 600px",
+ regenKey: function() {
+ new Ajax.Request("backend.php", {
+ parameters: "?op=rpc&subop=genHash",
+ onComplete: function(transport) {
+ var reply = JSON.parse(transport.responseText);
+ if (reply)
+ dijit.byId('instance_add_key').attr('value', reply.hash);
+
+ } });
+ },
+ execute: function() {
+ if (this.validate()) {
+ console.warn(dojo.objectToQuery(this.attr('value')));
+
+ notify_progress('Saving data...', true);
+ new Ajax.Request("backend.php", {
+ parameters: dojo.objectToQuery(this.attr('value')),
+ onComplete: function(transport) {
+ dialog.hide();
+ notify('');
+ updateInstanceList();
+ } });
+ }
+ },
+ href: query,
+ });
+
+ dialog.show();
} catch (e) {
exception_error("addInstance", e);
@@ -1853,7 +1888,29 @@ function editInstance(id, event) {
function removeSelectedInstances() {
try {
- alert("TODO: function not implemented.");
+ var sel_rows = getSelectedInstances();
+
+ if (sel_rows.length > 0) {
+
+ var ok = confirm(__("Remove selected instances?"));
+
+ if (ok) {
+ notify_progress("Removing selected instances...");
+
+ var query = "?op=pref-instances&subop=remove&ids="+
+ param_escape(sel_rows.toString());
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ notify('');
+ updateInstanceList();
+ } });
+ }
+
+ } else {
+ alert(__("No instances are selected."));
+ }
} catch (e) {
exception_error("removeInstance", e);