diff --git a/apps/filemanager/handlers/properties.php b/apps/filemanager/handlers/properties.php
index d06ea3f8a..4f85f6a02 100644
--- a/apps/filemanager/handlers/properties.php
+++ b/apps/filemanager/handlers/properties.php
@@ -1,26 +1,36 @@
layout = false;
-
+
header ('Content-Type: application/json');
-
+
$file = urldecode (join ('/', $this->params));
-
+
+$res = PropManager::all();
+$props = array();
+
+foreach($res as $k => $row) {
+ $props[$k]['id'] = $row->id;
+ $props[$k]['value'] = FileManager::prop ($file, $row->id);
+ $props[$k]['type'] = $row->type;
+ $props[$k]['label'] = $row->label;
+}
+
$out = array (
'title' => __ ('Properties'),
'body' => $tpl->render (
'filemanager/properties',
array (
'file' => $file,
- 'desc' => FileManager::prop ($file, 'desc')
+ 'props' => $props
)
)
);
-
+
echo json_encode ($out);
-
+
?>
\ No newline at end of file
diff --git a/apps/filemanager/handlers/propman/add.php b/apps/filemanager/handlers/propman/add.php
new file mode 100644
index 000000000..6da35ffcc
--- /dev/null
+++ b/apps/filemanager/handlers/propman/add.php
@@ -0,0 +1,18 @@
+layout = false;
+
+header ('Content-Type: application/json');
+
+$out = array (
+ 'title' => __ ('Add Property'),
+ 'body' => $tpl->render ('filemanager/propman/add')
+);
+
+echo json_encode ($out);
+
+?>
\ No newline at end of file
diff --git a/apps/filemanager/handlers/propman/edit.php b/apps/filemanager/handlers/propman/edit.php
new file mode 100644
index 000000000..bb8eeba67
--- /dev/null
+++ b/apps/filemanager/handlers/propman/edit.php
@@ -0,0 +1,28 @@
+layout = false;
+
+header ('Content-Type: application/json');
+
+$res = PropManager::all();
+$prop = array();
+
+foreach ($res as $row) {
+ if ($_GET['id'] == $row->id) {
+ $prop['id'] = $row->id;
+ $prop['type'] = $row->type;
+ $prop['label'] = $row->label;
+ }
+}
+
+$out = array (
+ 'title' => __ ('Edit Property'),
+ 'body' => $tpl->render ('filemanager/propman/edit', $prop)
+);
+echo json_encode ($out);
+
+?>
\ No newline at end of file
diff --git a/apps/filemanager/handlers/propmanager.php b/apps/filemanager/handlers/propmanager.php
new file mode 100644
index 000000000..f7ff547dd
--- /dev/null
+++ b/apps/filemanager/handlers/propmanager.php
@@ -0,0 +1,26 @@
+layout = 'admin';
+
+$this->require_acl ('admin', 'user');
+
+$res = PropManager::all();
+$props = array();
+
+foreach ($res as $k => $row) {
+ $props[$k]['id'] = $row->id;
+ $props[$k]['type'] = $row->type;
+ $props[$k]['label'] = $row->label;
+}
+
+
+$page->title = __ ('Properties Manager');
+$page->add_script ('/js/jquery-ui/jquery-ui.min.js');
+$page->add_script ('/apps/filemanager/js/jquery.filemanager.js');
+echo $tpl->render ('filemanager/propmanager', array('props' => $props, 'redirect' => $_GET['redirect']));
+
+?>
\ No newline at end of file
diff --git a/apps/filemanager/js/jquery.filemanager.js b/apps/filemanager/js/jquery.filemanager.js
index bc8677331..ab844b490 100644
--- a/apps/filemanager/js/jquery.filemanager.js
+++ b/apps/filemanager/js/jquery.filemanager.js
@@ -136,7 +136,16 @@
res.body
);
});
- break;
+ break;
+ case 'propman':
+ // display properties dialogue
+ $.get ('/filemanager/propman/' + options.action + '?id=' + options.id, function (res) {
+ $.open_dialog (
+ res.title,
+ res.body
+ );
+ });
+ break;
case 'img':
// edit an image
var url = window.location.href.split ('/filemanager')[0] + '/' + conf_root + '/' + options.file;
@@ -274,13 +283,47 @@
}
$.filemanager_prop = function (form) {
- var file = form.elements.file.value,
- desc = form.elements.desc.value;
-
- $.get ('/filemanager/api/prop/' + file + '?prop=desc&value=' + encodeURIComponent (desc), function (res) {
- $.close_dialog ();
- $.add_notification (res.data.msg);
- });
+ var file = form.elements.file.value, result = '', response = '';
+ $('#properties').children('.prop').each( function() {
+ $.get ('/filemanager/api/prop/' + file + '?prop=' + $(this).attr('id') + '&value=' + encodeURIComponent ($(this).attr('value')), function(res) {
+ result = res.data.value;
+ response = res.data.msg;
+ });
+ });
+ $.close_dialog ();
+ $.add_notification (response);
+ return false;
+ };
+
+ $.propmanager = function (action, form) {
+ if (action != 'delete') {
+ var id = form.elements.id.value;
+ var type = form.elements.type.value;
+ var label = form.elements.label.value;
+ $.get ('/filemanager/api/propman/' + action + '?id=' + encodeURIComponent (id) + '&type=' + type + '&label=' + encodeURIComponent (label), function(res) {
+ if (!res) {
+ return false;
+ }
+ $.close_dialog ();
+ if (action == 'add') {
+ $('#prop-table').append("
" + id + " | " + type + " | " + label + " | Edit | Delete |
");
+ $.add_notification ('Property added.');
+ }
+ if (action == 'edit') {
+ $('tr#' + id + ' td#prop-type').text(type);
+ $('tr#' + id + ' td#prop-label').text(label);
+ $.add_notification ('Property saved.');
+ }
+ });
+ } else {
+ $.get ('/filemanager/api/propman/delete?id=' + encodeURIComponent (form), function(res) {
+ if (!res) {
+ return false;
+ }
+ $('tr#' + form).remove();
+ $.add_notification ('Property removed.');
+ });
+ }
return false;
};
diff --git a/apps/filemanager/lib/API.php b/apps/filemanager/lib/API.php
index f3d17d5b7..63c8f2ccb 100644
--- a/apps/filemanager/lib/API.php
+++ b/apps/filemanager/lib/API.php
@@ -2,7 +2,8 @@
namespace filemanager;
-use DB, FileManager, I18n, Restful;
+//added PropManager
+use DB, FileManager, PropManager, I18n, Restful;
/**
* Provides the JSON API for the admin file manager/browser, as well as functions
@@ -125,7 +126,7 @@ public function get_prop () {
if (! isset ($_GET['prop'])) {
return $this->error (__ ('Missing property name'));
}
- if (isset ($_GET['value'])) {
+ if ((!FileManager::prop($file, $_GET['prop']) && $_GET['value'] != '') || $_GET['value'] != Filemanager::prop ($file, $_GET['prop'])) {
// update and fetch
$res = FileManager::prop ($file, $_GET['prop'], $_GET['value']);
} else {
@@ -139,6 +140,29 @@ public function get_prop () {
'msg' => __ ('Properties saved.')
);
}
+
+ /**
+ * Handle property manager update requests (/filemanager/api/propman).
+ */
+ public function get_propman () {
+ $action = urldecode (join ('/', func_get_args ()));
+ if (! isset ($_GET['id'])) {
+ return $this->error (__ ('Missing property name.'));
+ }
+ if (! preg_match ('/^[a-zA-Z0-9_]+$/', $_GET['id'])) {
+ return $this->error (__ ('Invalid property name.'));
+ }
+ if (! $action == 'delete' && ! preg_match ('/^[a-zA-Z0-9_]+$/', $_GET['label'])) {
+ return $this->error (__ ('Invalid label.'));
+ }
+ if ($action == 'add' || $action == 'edit') {
+ // update and fetch
+ $res = PropManager::set ($_GET['id'], $_GET['type'], $_GET['label']);
+ } elseif ($action == 'delete') {
+ $res = PropManager::delete ($_GET['id']);
+ }
+ return $res;
+ }
}
?>
\ No newline at end of file
diff --git a/apps/filemanager/lib/FileManager.php b/apps/filemanager/lib/FileManager.php
index 8204cce75..acb76f6b3 100644
--- a/apps/filemanager/lib/FileManager.php
+++ b/apps/filemanager/lib/FileManager.php
@@ -415,7 +415,7 @@ public static function fsort ($a, $b) {
}
/**
- * Fetch all of the properties for the specified file.
+ * Fetch all of the properties for the specified file. (not used anymore)
*/
public static function props ($file) {
return DB::pairs ('select prop, value from #prefix#filemanager_prop where file = ?', $file);
@@ -435,9 +435,8 @@ public static function prop ($file, $prop, $value = null) {
} elseif ($res === false || $res === null) {
// doesn't exist yet
if (! DB::execute (
- 'insert into #prefix#filemanager_prop (file, prop, value) values (?, ?, ?)',
+ 'insert into #prefix#filemanager_prop (file, `'.$prop.'`) values (?, ?)',
$file,
- $prop,
$value
)) {
self::$error = DB::error ();
@@ -446,10 +445,9 @@ public static function prop ($file, $prop, $value = null) {
} else {
// already exists, update
if (! DB::execute (
- 'update #prefix#filemanager_prop set value = ? where file = ? and prop = ?',
+ 'update #prefix#filemanager_prop set `'.$prop.'` = ? where file = ?',
$value,
- $file,
- $prop
+ $file
)) {
self::$error = DB::error ();
return false;
@@ -461,16 +459,15 @@ public static function prop ($file, $prop, $value = null) {
// get as a list
$qmarks = array_fill (0, count ($file), '?');
$file[] = $prop;
- return DB::pairs (
- 'select file, value from #prefix#filemanager_prop where file in(' . join (', ', $qmarks) . ') and prop = ?',
- $file
+ return DB::fetch (
+ 'select `'.$prop.'` from #prefix#filemanager_prop where file in(' . join (', ', $qmarks) . ')',
+ $file
);
}
// get a single value
return DB::shift (
- 'select value from #prefix#filemanager_prop where file = ? and prop = ?',
- $file,
- $prop
+ 'select `'.$prop.'` from #prefix#filemanager_prop where file = ?',
+ $file
);
}
diff --git a/apps/filemanager/lib/PropManager.php b/apps/filemanager/lib/PropManager.php
new file mode 100644
index 000000000..859025abf
--- /dev/null
+++ b/apps/filemanager/lib/PropManager.php
@@ -0,0 +1,66 @@
+type === $type && $res->label === $label) {
+ return 'No changes made';
+ } elseif (!$res) {
+ // doesn't exist yet
+ if (DB::execute (
+ 'insert into #prefix#filemanager_propman (id, type, label) values (?, ?, ?)',
+ $id,
+ $type,
+ $label
+ )) {
+ DB::execute ('alter table #prefix#filemanager_prop add '.$id.' char(255) not null');
+ } else {
+ self::$error = DB::error ();
+ return false;
+ }
+ } else {
+ // already exists, update
+ if (! DB::execute (
+ 'update #prefix#filemanager_propman set type = ?, label = ? where id = ?',
+ $type,
+ $label,
+ $id
+ )) {
+ self::$error = DB::error ();
+ return false;
+ }
+ }
+ return self::get($id);
+ }
+ public static function delete ($id) {
+ //check if exists
+ $res = self::get ($id);
+ //return if doesn't exist
+ if (! $res->id === $id) {
+ return 'Property does not exist.';
+ //if exists, execute removal
+ } elseif (DB::execute ('delete from #prefix#filemanager_propman where id = ?', $id)) {
+ DB::execute ('alter table #prefix#filemanager_prop drop column '.$id);
+ return true;
+ } else {
+ self::$error = DB::error ();
+ return self::$error;
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/apps/filemanager/views/index.html b/apps/filemanager/views/index.html
index 31affba6a..2d8da02a4 100644
--- a/apps/filemanager/views/index.html
+++ b/apps/filemanager/views/index.html
@@ -106,8 +106,8 @@
-
-
+
+
{" Name "} |
{" Last modified "} |
{" File size "} |
@@ -115,6 +115,7 @@
+Properties Manager
{% if aviary_key %}
diff --git a/apps/filemanager/views/properties.html b/apps/filemanager/views/properties.html
index 8bd22bde3..05cf73a55 100644
--- a/apps/filemanager/views/properties.html
+++ b/apps/filemanager/views/properties.html
@@ -1,15 +1,20 @@
+
+
\ No newline at end of file
diff --git a/apps/filemanager/views/propman/add.html b/apps/filemanager/views/propman/add.html
new file mode 100644
index 000000000..6cb5c079f
--- /dev/null
+++ b/apps/filemanager/views/propman/add.html
@@ -0,0 +1,20 @@
+
\ No newline at end of file
diff --git a/apps/filemanager/views/propman/edit.html b/apps/filemanager/views/propman/edit.html
new file mode 100644
index 000000000..80eaef0df
--- /dev/null
+++ b/apps/filemanager/views/propman/edit.html
@@ -0,0 +1,21 @@
+
\ No newline at end of file
diff --git a/apps/filemanager/views/propmanager.html b/apps/filemanager/views/propmanager.html
new file mode 100644
index 000000000..178028bd2
--- /dev/null
+++ b/apps/filemanager/views/propmanager.html
@@ -0,0 +1,20 @@
+Add Property
+
+
+
+ {"ID"} |
+ {"Type"} |
+ {"Label"} |
+ |
+
+{% foreach props as prop %}
+
+ {{ prop['id'] }} |
+ {{ prop['type'] }} |
+ {{ prop['label'] }} |
+ {"Edit"} | {"Delete"} |
+
+{% end %}
+
+Return to FileManager
+
\ No newline at end of file
diff --git a/conf/install_mysql.sql b/conf/install_mysql.sql
index a4cfddb01..53c85970e 100644
--- a/conf/install_mysql.sql
+++ b/conf/install_mysql.sql
@@ -103,11 +103,19 @@ create table `#prefix#lock` (
) default charset=utf8;
create table #prefix#filemanager_prop (
- file char(128) not null primary key,
- prop char(32) not null,
- value char(255) not null,
- index (prop)
+ file char(128) not null primary key,
+ desc char(255) not null,
+ index (file)
) default charset=utf8;
+
+create table #prefix#filemanager_propman (
+ id char(8) not null primary key,
+ type char(16) not null,
+ label char(16) not null,
+ index (id)
+) default charset=utf8;
+
+insert into #prefix#filemanager_propman (id, type, label) values ('desc','textarea','Description');
create table #prefix#apps (
name char(48) not null primary key,
diff --git a/conf/install_pgsql.sql b/conf/install_pgsql.sql
index 2adc0e7dd..4d175ea9b 100644
--- a/conf/install_pgsql.sql
+++ b/conf/install_pgsql.sql
@@ -123,12 +123,20 @@ create index #prefix#lock_resource on #prefix#lock (resource, resource_id, expir
create index #prefix#lock_user on #prefix#lock ("user");
create table #prefix#filemanager_prop (
- file char(128) not null primary key,
- prop char(32) not null,
- value char(255) not null
+ file char(128) not null primary key,
+ desc char(255) not null,
);
-
-create index #prefix#filemanager_prop_name on #prefix#filemanager_prop (prop);
+
+create index #prefix#filemanager_prop_name on #prefix#filemanager_prop (file);
+
+create table #prefix#filemanager_propman (
+ id char(8) not null primary key,
+ type char(16) not null,
+ label char(16) not null
+);
+
+create index #prefix#filemanager_prop_types on #prefix#filemanager_propman (id);
+insert into #prefix#filemanager_propman (id, type, label) values ('desc','textarea','Description');
create table #prefix#apps (
name varchar(48) not null primary key,
diff --git a/conf/install_sqlite.sql b/conf/install_sqlite.sql
index 08cd5a243..c15f5d582 100644
--- a/conf/install_sqlite.sql
+++ b/conf/install_sqlite.sql
@@ -111,12 +111,19 @@ create index #prefix#lock_resource on #prefix#lock (resource, resource_id, expir
create index #prefix#lock_user on #prefix#lock (user);
create table #prefix#filemanager_prop (
- file char(128) not null primary key,
- prop char(32) not null,
- value char(255) not null
-);
-
-create index #prefix#filemanager_prop_name on #prefix#filemanager_prop (prop);
+ file char(128) not null primary key,
+ desc char(255) not null,
+ index (file)
+) default charset=utf8;
+
+create table #prefix#filemanager_propman (
+ id char(8) not null primary key,
+ type char(16) not null,
+ label char(16) not null,
+ index (id)
+) default charset=utf8;
+
+insert into #prefix#filemanager_propman (id, type, label) values ('desc','textarea','Description');
create table #prefix#apps (
name char(48) not null primary key,