Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
0ce8cbda
Commit
0ce8cbda
authored
Jan 10, 2007
by
Richard Mansfield
Browse files
Allow main menu to link to admin files
parent
f5568e54
Changes
8
Hide whitespace changes
Inline
Side-by-side
htdocs/admin/site/files.php
View file @
0ce8cbda
...
...
@@ -42,6 +42,7 @@ var browser = new FileBrowser('filelist', '{$wwwroot}artefact/file/myfiles.json.
browser.createfolderscript = '{$wwwroot}artefact/file/createfolder.json.php';
browser.deletescript = '{$wwwroot}artefact/file/delete.json.php';
browser.updatemetadatascript = '{$wwwroot}artefact/file/updatemetadata.json.php';
browser.downloadscript = '{$wwwroot}artefact/file/download.php';
var uploader = new FileUploader('uploader', '{$wwwroot}artefact/file/upload.php', {'adminfiles':true},
null, null, browser.refresh, browser.fileexists);
browser.changedircallback = uploader.updatedestination;
...
...
htdocs/admin/site/getadminfiles.json.php
0 → 100644
View file @
0ce8cbda
<?php
/**
* This program is part of Mahara
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
define
(
'ADMIN'
,
1
);
define
(
'JSON'
,
1
);
require
(
dirname
(
dirname
(
dirname
(
__FILE__
)))
.
'/init.php'
);
$public
=
param_boolean
(
'public'
);
safe_require
(
'artefact'
,
'file'
);
$result
=
array
();
if
(
$adminfiles
=
ArtefactTypeFile
::
get_admin_files
(
$public
))
{
foreach
(
$adminfiles
as
$adminfile
)
{
$result
[
'adminfiles'
][]
=
array
(
'name'
=>
$adminfile
->
title
,
'id'
=>
$adminfile
->
id
);
}
}
else
{
$result
[
'adminfiles'
]
=
null
;
}
$result
[
'error'
]
=
false
;
$result
[
'message'
]
=
get_string
(
'adminfilesloaded'
,
'artefact.file'
);
json_headers
();
echo
json_encode
(
$result
);
?>
htdocs/admin/site/getmenuitems.json.php
View file @
0ce8cbda
...
...
@@ -30,15 +30,20 @@ define('JSON', 1);
require
(
dirname
(
dirname
(
dirname
(
__FILE__
)))
.
'/init.php'
);
json_headers
();
$public
=
(
int
)
param_boolean
(
'public'
);
$result
=
array
();
$menuitems
=
get_records_array
(
'site_menu'
,
'public'
,
$public
,
'displayorder'
);
// @todo: Get all the filenames of the files referred to in the $menuitems records.
// (files table doesn't exist yet)
//$menuitems = get_records_array('site_menu','public',$public,'displayorder');
$prefix
=
get_config
(
'dbprefix'
);
$menuitems
=
get_records_sql_array
(
'
SELECT
s.*, a.title AS filename
FROM '
.
$prefix
.
'site_menu s
LEFT OUTER JOIN '
.
$prefix
.
'artefact a ON s.file = a.id
WHERE
s.public = '
.
$public
.
'
ORDER BY s.displayorder'
,
null
);
$rows
=
array
();
if
(
$menuitems
)
{
foreach
(
$menuitems
as
$i
)
{
...
...
@@ -47,13 +52,14 @@ if ($menuitems) {
$r
[
'name'
]
=
$i
->
title
;
if
(
empty
(
$i
->
url
)
&&
!
empty
(
$i
->
file
))
{
$r
[
'type'
]
=
'adminfile'
;
$r
[
'linkedto'
]
=
$i
->
file
;
// @todo: substitute the appropriate filename.
// $r['link'] = ''; // @todo: provide a link to the file
$r
[
'linkedto'
]
=
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$i
->
file
;
$r
[
'linktext'
]
=
$i
->
filename
;
$r
[
'file'
]
=
$i
->
file
;
}
else
if
(
!
empty
(
$i
->
url
)
&&
empty
(
$i
->
file
))
{
$r
[
'type'
]
=
'externallink'
;
$r
[
'linkedto'
]
=
$i
->
url
;
//
$r['link'] = $i->url;
$r
[
'link
text
'
]
=
$i
->
url
;
}
else
{
json_reply
(
'local'
,
get_string
(
'loadmenuitemsfailed'
,
'admin'
));
...
...
@@ -61,6 +67,7 @@ if ($menuitems) {
$rows
[]
=
$r
;
}
}
$result
[
'menuitems'
]
=
array_values
(
$rows
);
$result
[
'error'
]
=
false
;
$result
[
'message'
]
=
get_string
(
'menuitemsloaded'
,
'admin'
);
...
...
htdocs/admin/site/menu.php
View file @
0ce8cbda
...
...
@@ -33,7 +33,8 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$strings
=
array
(
'edit'
,
'delete'
,
'update'
,
'cancel'
,
'add'
,
'name'
,
'unknownerror'
);
$adminstrings
=
array
(
'deletefailed'
,
'deletingmenuitem'
,
'savingmenuitem'
,
'noadminfiles'
,
'loggedinmenu'
,
'loggedoutmenu'
,
'linkedto'
,
'externallink'
,
'adminfile'
,
'loadingmenuitems'
,
'menuitemsloaded'
,
'failedloadingmenuitems'
);
'loadingmenuitems'
,
'menuitemsloaded'
,
'failedloadingadminfiles'
,
'failedloadingmenuitems'
);
foreach
(
$strings
as
$string
)
{
$getstring
[
$string
]
=
"'"
.
get_string
(
$string
)
.
"'"
;
}
...
...
@@ -49,12 +50,11 @@ $ijs .= "var adminfile = '" . get_string('adminfile','admin') . "';\n";
$ijs
.
=
<<<
EOJS
// Request a list of menu items from the server
function
getitems
()
{
logDebug
({
$getstring
[
'loadingmenuitems'
]});
processingStart
();
var
d
=
loadJSONDoc
(
'getmenuitems.json.php'
,{
'public'
:
selectedmenu
==
'loggedoutmenu'
});
d
.
addCallback
(
function
(
data
)
{
if
(
!
data
.
error
)
{
logDebug
({
$getstring
[
'menuitemsloaded'
]});
//
logDebug({$getstring['menuitemsloaded']});
displaymenuitems
(
data
.
menuitems
);
processingStop
();
}
...
...
@@ -65,6 +65,23 @@ function getitems() {
});
}
// Get a list of the available admin files
function
getadminfiles
()
{
processingStart
();
var
d
=
loadJSONDoc
(
'getadminfiles.json.php'
,{
'public'
:
selectedmenu
==
'loggedoutmenu'
});
d
.
addCallback
(
function
(
data
)
{
if
(
!
data
.
error
)
{
adminfiles
=
data
.
adminfiles
;
processingStop
();
}
else
{
displayMessage
({
$getstring
[
'failedloadingadminfiles'
]},
'error'
);
adminfiles
=
null
;
processingStop
();
}
});
}
// Puts the list of menu items into the empty table.
function
displaymenuitems
(
itemlist
)
{
var
rows
=
map
(
formatrow
,
itemlist
);
...
...
@@ -78,7 +95,7 @@ function displaymenuitems(itemlist) {
function
formatrow
(
item
)
{
// item has id, type, name, link, linkedto
var
type
=
eval
(
item
.
type
);
var
linkedto
=
A
({
'href'
:
item
.
linkedto
},
item
.
link
edto
);
var
linkedto
=
A
({
'href'
:
item
.
linkedto
},
item
.
link
text
);
var
del
=
INPUT
({
'type'
:
'button'
,
'value'
:
{
$getstring
[
'delete'
]}});
del
.
onclick
=
function
()
{
delitem
(
item
.
id
);
};
var
edit
=
INPUT
({
'type'
:
'button'
,
'value'
:
{
$getstring
[
'edit'
]}});
...
...
@@ -140,7 +157,6 @@ function editform(item) {
var
name
=
INPUT
({
'type'
:
'text'
,
'id'
:
'name'
+
item
.
id
,
'value'
:
item
.
name
});
if
(
item
.
type
==
'adminfile'
)
{
var
adminfiles
=
getadminfiles
();
if
(
adminfiles
==
null
)
{
// There are no admin files, we don't need the select or save button
linkedto
=
{
$getstring
[
'noadminfiles'
]};
...
...
@@ -148,7 +164,15 @@ function editform(item) {
}
else
{
// Select the currently selected file.
linkedto
=
INPUT
({
'type'
:
'select'
,
'id'
:
'linkedto'
+
item
.
id
});
linkedto
=
SELECT
({
'id'
:
'linkedto'
+
item
.
id
});
for
(
var
i
=
0
;
i
<
adminfiles
.
length
;
i
++
)
{
if
(
item
.
file
==
adminfiles
[
i
]
.
id
)
{
appendChildNodes
(
linkedto
,
OPTION
({
'value'
:
adminfiles
[
i
]
.
id
,
'selected'
:
true
},
adminfiles
[
i
]
.
name
));
}
else
{
appendChildNodes
(
linkedto
,
OPTION
({
'value'
:
adminfiles
[
i
]
.
id
},
adminfiles
[
i
]
.
name
));
}
}
}
setNodeAttribute
(
afile
,
'checked'
,
true
);
}
...
...
@@ -227,17 +251,14 @@ function saveitem(itemid) {
return
false
;
}
// In phase 1 there are no files in the system
function
getadminfiles
()
{
return
null
;
}
function
changemenu
()
{
selectedmenu
=
$
(
'menuselect'
)
.
value
;
getitems
();
getadminfiles
();
}
var
selectedmenu
=
'loggedoutmenu'
;
var
adminfiles
=
null
;
addLoadEvent
(
function
()
{
$
(
'menuselect'
)
.
value
=
selectedmenu
;
$
(
'menuselect'
)
.
onchange
=
changemenu
;
...
...
htdocs/artefact/file/js/file.js
View file @
0ce8cbda
...
...
@@ -21,6 +21,7 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
this
.
deletescript
=
'
delete.json.php
'
;
this
.
createfolderscript
=
'
createfolder.json.php
'
;
this
.
updatemetadatascript
=
'
updatemetadata.json.php
'
;
this
.
downloadscript
=
'
download.php
'
;
if
(
this
.
actionname
)
{
this
.
lastcolumnfunc
=
function
(
r
)
{
...
...
@@ -221,7 +222,7 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
if
(
self
.
actionname
)
{
return
TD
(
null
,
r
.
title
);
}
return
TD
(
null
,
A
({
'
href
'
:
'
download
.php
?file=
'
+
r
.
id
},
r
.
title
));
return
TD
(
null
,
A
({
'
href
'
:
self
.
download
script
+
'
?file=
'
+
r
.
id
},
r
.
title
));
}
this
.
fileexists
=
function
(
filename
)
{
...
...
htdocs/artefact/file/lib.php
View file @
0ce8cbda
...
...
@@ -281,8 +281,6 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return
get_config
(
'dataroot'
)
.
self
::
get_file_directory
(
$this
->
id
)
.
'/'
.
$this
->
id
;
}
/**
* Test file type and return a new Image or File.
*/
...
...
@@ -296,7 +294,6 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return
new
ArtefactTypeFile
(
0
,
$data
);
}
/**
* Moves a file into the myfiles area.
* Takes the name of a file outside the myfiles area.
...
...
@@ -323,7 +320,6 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return
$id
;
}
/**
* Processes a newly uploaded file, copies it to disk, and creates
* a new artefact object.
...
...
@@ -350,6 +346,23 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return
$error
;
}
public
static
function
get_admin_files
(
$public
)
{
if
(
$public
)
{
$foldersql
=
'parent = '
.
ArtefactTypeFolder
::
admin_public_folder_id
();
}
else
{
$foldersql
=
'parent IS NULL'
;
}
$prefix
=
get_config
(
'dbprefix'
);
return
get_records_sql_array
(
'
SELECT
a.id, a.title
FROM '
.
$prefix
.
'artefact a
INNER JOIN '
.
$prefix
.
'artefact_file_files f ON f.artefact = a.id
WHERE a.'
.
$foldersql
.
"
AND f.adminfiles = 1
AND a.artefacttype != 'folder'"
,
null
);
}
public
function
delete
()
{
if
(
empty
(
$this
->
id
))
{
...
...
@@ -402,6 +415,30 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
FORMAT_ARTEFACT_RENDERFULL
,
FORMAT_ARTEFACT_RENDERMETADATA
);
}
public
static
function
admin_public_folder_id
()
{
$name
=
get_string
(
'adminpublicdirname'
,
'admin'
);
$prefix
=
get_config
(
'dbprefix'
);
$folderid
=
get_field_sql
(
'
SELECT
a.id
FROM '
.
$prefix
.
'artefact a
INNER JOIN '
.
$prefix
.
'artefact_file_files f ON a.id = f.artefact
WHERE a.title = ?
AND a.artefacttype = ?
AND f.adminfiles = 1
AND a.parent IS NULL'
,
array
(
$name
,
'folder'
));
if
(
!
$folderid
)
{
global
$USER
;
$data
=
(
object
)
array
(
'title'
=>
$name
);
$f
=
new
ArtefactTypeFolder
(
0
,
$data
);
$f
->
set
(
'owner'
,
$USER
->
get
(
'id'
));
$f
->
set
(
'adminfiles'
,
1
);
$f
->
commit
();
$folderid
=
$f
->
get
(
'id'
);
}
return
$folderid
;
}
public
static
function
get_folder_by_name
(
$name
,
$parentfolderid
=
null
)
{
global
$USER
;
$prefix
=
get_config
(
'dbprefix'
);
...
...
htdocs/lang/en.utf8/admin.php
View file @
0ce8cbda
...
...
@@ -108,6 +108,7 @@ $string['viruscheckingdescription'] = 'If checked, virus checking will be enable
// Admin menu editor
//$string['menueditor'] = 'Menu editor';
$string
[
'adminfile'
]
=
'Admin file'
;
$string
[
'adminpublicdirname'
]
=
'public'
;
// Name of the directory in which to store public admin files
$string
[
'badmenuitemtype'
]
=
'Unknown menu item type'
;
$string
[
'externallink'
]
=
'External link'
;
$string
[
'type'
]
=
'Type'
;
...
...
htdocs/lib/web.php
View file @
0ce8cbda
...
...
@@ -1078,6 +1078,10 @@ function site_menu() {
$menu
[]
=
array
(
'name'
=>
$i
->
title
,
'link'
=>
$i
->
url
);
}
else
if
(
$i
->
file
)
{
$menu
[]
=
array
(
'name'
=>
$i
->
title
,
'link'
=>
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$i
->
file
);
}
}
}
return
$menu
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment