Commit d5630ace authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1886614: frameworks.php refactoring

frameworks.php:
 This file contains the forms that are displayed when we go to Admin
menu-> Extensions-> SmartEvidence

The code should have the same functionalities as before,
nothing should change from the user interface side

Change-Id: Ia385b7265f52640172e31c3ef5954f9efbf24fd2
parent d0fe8abb
Loading
Loading
Loading
Loading
+90 −90
Original line number Diff line number Diff line
@@ -27,17 +27,38 @@ if (!PluginModuleFramework::is_active()) {
$upload = param_boolean('upload');
$uploadmatrix = param_boolean('uploadmatrix');

function get_institutions() {
    $insts = get_records_array('institution');
    $inst_names = array();
    foreach ($insts as $inst) {
        array_push($inst_names, $inst->displayname);
if ($uploadmatrix) {
    import_matrix_file_section();
}
else if ($upload) {
    edit_framework_section();
}
    return $inst_names;
else {
    management_section();
}

// on frameworks page (rubbish bin icon)
function framework_delete_submit(Pieform $form, $values) {
    global $SESSION;

if ($uploadmatrix) {
    $framework = new Framework($values['framework']);
    if (!$framework->is_in_collections()) {
        $framework->delete();
        $SESSION->add_ok_msg(get_string('itemdeleted'));
    }
    else {
        $SESSION->add_error_msg(get_string('deletefailed', 'admin'));
    }

    redirect('/module/framework/frameworks.php');
}

// edit framework on main page
function framework_config_submit(Pieform $form, $values) {
    redirect(get_config('wwwroot') . 'module/framework/frameworkmanager.php?id=' . $values['framework']);
}

function import_matrix_file_section() {
    //show Browse for matrix file form.
    define('SUBSECTIONHEADING', get_string('upload'));
    $active_tab = 'import';
@@ -50,9 +71,10 @@ if ($uploadmatrix) {
    $smarty->display('module:framework:uploadframework.tpl');
    exit;
}
else if ($upload) {
    //jsoneditor page:
    //get existing frameworks.

function edit_framework_section() {
    global $SESSION;

    define('SUBSECTIONHEADING', get_string('editor', 'module.framework'));
    $active_tab = 'editor';
    $fw = array();
@@ -143,7 +165,7 @@ else if ($upload) {
    );

    //set up variables for correct selection of framework from dropdowns
    $inst_names = get_institutions();
    $inst_names = get_column('institution', 'displayname');
    $inst_stg = get_string('all', 'module.framework') . ',';
    foreach ($inst_names as $inst) {
        $inst_stg .= $inst . ',';
@@ -164,12 +186,10 @@ else if ($upload) {
    $smarty->display('module:framework:jsoneditor.tpl');
    exit;
}
else {
    //for overview page
    $active_tab = 'overview';
}

function management_section() {
    define('SUBSECTIONHEADING', get_string('Management', 'module.framework'));
    $active_tab = 'overview';
    $frameworks = Framework::get_frameworks('any');
    if ($frameworks) {
        foreach ($frameworks as $framework) {
@@ -235,30 +255,10 @@ if ($frameworks) {
        }
    }

//on frameworks page (rubbish bin icon)
function framework_delete_submit(Pieform $form, $values) {
    global $SESSION;

    $framework = new Framework($values['framework']);
    if (!$framework->is_in_collections()) {
        $framework->delete();
        $SESSION->add_ok_msg(get_string('itemdeleted'));
    }
    else {
        $SESSION->add_error_msg(get_string('deletefailed', 'admin'));
    }

    redirect('/module/framework/frameworks.php');
}

//edit framework on main page
function framework_config_submit(Pieform $form, $values) {
    redirect(get_config('wwwroot') . 'module/framework/frameworkmanager.php?id=' . $values['framework']);
}

    $smarty = smarty();
    setpageicon($smarty, 'icon-th');
    $smarty->assign('frameworks', $frameworks);
    $smarty->assign('SUBPAGENAV', PluginModuleFramework::submenu_items($active_tab));
    $smarty->assign('wwwroot', get_config('wwwroot'));
    $smarty->display('module:framework:frameworks.tpl');
}
 No newline at end of file