/**
 * Transverse the tree and update/insert entries based on the updated structure.
 * @param	array	The tree from rebuild(), and the subtree from the recursion.
 * @param	int		the ordering of this subtree respect to its parent.
 * @param	int		parent content id
 * @return	null (nothing to return, it updates the db only)
 */
function reconstruct($tree, $order, $content_parent_id, $table_prefix)
{
    global $db;
    //a content page.
    if (!is_array($tree)) {
        $sql = 'UPDATE ' . $table_prefix . "content SET ordering={$order}, content_parent_id={$content_parent_id} WHERE content_id={$tree}";
        if (!mysql_query($sql, $db)) {
            //throw error
            echo mysql_error();
        }
        return;
    }
    foreach ($tree as $k => $v) {
        if (preg_match('/order\\_([\\d]+)/', $k, $match) == 1) {
            //order layer
            reconstruct($v, $match[1], $content_parent_id, $table_prefix);
            //inherit the previous layer id
        } else {
            //content folder layer
            $sql = 'SELECT * FROM ' . $table_prefix . "content WHERE content_id={$k}";
            $result = mysql_query($sql, $db);
            $old_content_row = mysql_fetch_assoc($result);
            $sql = 'INSERT INTO ' . $table_prefix . 'content (course_id, content_parent_id, ordering, last_modified, revision, formatting, release_date, keywords, content_path, title, use_customized_head, allow_test_export, content_type) VALUES (' . $old_content_row['course_id'] . ', ' . $content_parent_id . ', ' . $order . ', ' . '\'' . $old_content_row['last_modified'] . '\', ' . $old_content_row['revision'] . ', ' . $old_content_row['formatting'] . ', ' . '\'' . $old_content_row['release_date'] . '\', ' . '\'' . mysql_real_escape_string($old_content_row['keywords']) . '\', ' . '\'' . mysql_real_escape_string($old_content_row['content_path']) . '\', ' . '\'' . mysql_real_escape_string($old_content_row['title']) . '\', ' . $old_content_row['use_customized_head'] . ', ' . $old_content_row['allow_test_export'] . ', ' . '1)';
            if (mysql_query($sql, $db)) {
                $folder_id = mysql_insert_id();
                reconstruct($v, '', $folder_id, $table_prefix);
            } else {
                //throw error
                echo mysql_error();
            }
        }
    }
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (is_session_active()) {
        //$shares = array($_POST['1'] , $_POST['2'], $_POST['3']);
        $shares = array();
        if (!empty($_POST['1'])) {
            array_push($shares, $_POST['1']);
        }
        if (!empty($_POST['2'])) {
            array_push($shares, $_POST['2']);
        }
        if (!empty($_POST['3'])) {
            array_push($shares, $_POST['3']);
        }
        //var_dump($shares);
        $reconstructed_secret = reconstruct($shares);
        $db = new DBConnection();
        $db->connect();
        $user = get_user_info();
        $secret = $db->query('secret', 'secret', "uid='{$user}'", null, null, null)[0]['secret'];
        $db->delete('secret', "uid='{$user}'");
        $db->disconnect();
        if ($secret == $reconstructed_secret) {
            echo "Secrets matching. Access granted.";
        } else {
            echo "{$secret} != {$reconstructed_secret}. Access denied";
        }
    } else {
        echo "fail";
    }
} else {
include_once "ressources/class.lvm.org.inc";
$user = new usersMenus();
if (!$user->AsSystemAdministrator) {
    echo "alert('no privileges');";
    die;
}
if (isset($_GET["popup"])) {
    popup();
    exit;
}
if (isset($_POST["remove-table"])) {
    remove_table();
    exit;
}
if (isset($_POST["reconstruct"])) {
    reconstruct();
    exit;
}
js();
function js()
{
    $tpl = new templates();
    $page = CurrentPageName();
    if (!is_numeric($_GET["t"])) {
        $t = time();
    }
    $database = $_GET["database"];
    $table = $_GET["table"];
    $title = $tpl->javascript_parse_text("{$database}/{$table}");
    echo "YahooWinBrowse('500','{$page}?popup=yes&t={$t}&database={$database}&table={$table}&t={$t}','{$title}')";
}
Esempio n. 4
0
			$sql = 'SELECT * FROM '.$_POST['step1']['tb_prefix'].'content WHERE course_id='.$row_course['course_id'];
			$result = mysql_query($sql, $db);
			$content_array = array(); 
	
			while ($row = mysql_fetch_assoc($result)){
				$content_array[$row['content_parent_id']][$row['ordering']] = $row['content_id'];
			}

			$tree = buildTree($content_array[0], $content_array);

			/* Restructure the tree */
			$tree = rebuild($tree);

			
			/* Update the Db based on this new tree */
			reconstruct($tree, '', 0, $_POST['step1']['tb_prefix']);
		}
	}

	/* deal with the extra modules: */
	/* for each module in the modules table check if that module still exists in the mod directory. */
	/* if that module does not exist then check the old directory and prompt to have it copied */
	/* or delete it from the modules table. or maybe disable it instead? */
	if (version_compare($_POST['step1']['old_version'], '1.5.1', '>')) {
		define('TABLE_PREFIX', $_POST['step1']['tb_prefix']);
		require(AT_INCLUDE_PATH . '../mods/_core/modules/classes/Module.class.php');
		$moduleFactory = new ModuleFactory(FALSE);
		$module_list =& $moduleFactory->getModules(AT_MODULE_STATUS_DISABLED | AT_MODULE_STATUS_ENABLED);
		$keys = array_keys($module_list);
		foreach($keys as $dir_name) {
			$module =& $module_list[$dir_name];
Esempio n. 5
0
require_once "repoapi.inc";
header('Content-Type: application/json');
$file_info = get_file_info($_GET['fid']);
$colluded_list = is_threshold_met($_GET['fid']);
//	print_r($colluded_list);print_r($file_info);
if ($file_info['status'] != 4) {
    $colluded_list = is_threshold_met($_GET['fid']);
    //	print_r($colluded_list);
    $ret = '';
    if ($colluded_list['more'] <= 0) {
        $shares = get_shares_as_string($_GET['fid']);
        $info['shares'] = $shares;
        $info['file-name'] = get_file_name($_GET['fid']);
        $info['fid'] = $_GET['fid'];
        //		print_r($info);
        $result = reconstruct($info);
        set_decryption_status($_GET['fid'], $result);
        //		print_r($result);
        $data = "<a href='/toyapp/repo/{$result}'>Download file</a><br />";
        $ret = array('status' => 'success', 'data' => $data);
    } else {
        $data = '';
        foreach ($colluded_list['list'] as $key => $value) {
            $data .= $value['uid'] . ', ';
        }
        //$data = trim($data);
        $data .= ' shared secrets. Needs ' . $colluded_list['more'] . ' more shares.';
        $ret = array('status' => 'fail', 'data' => $data);
    }
} else {
    $file = get_file_path($_GET['fid']);