} else {
     $organisation_id = $opts["associated_organisation_id"];
     $organisation = Organisation::get($organisation_id);
 }
 if (!$opts["associated_group"]) {
     add_error("Invalid or unspecified Group");
 } else {
     $group = $opts["associated_group"];
 }
 if ($opts["associated_role"] == "all") {
     $role = null;
 } else {
     $role = $opts["associated_role"];
 }
 if (!has_error()) {
     $caching = MetaDataValues::get($organisation_id, $group, $role, null, $category);
     //first go through the values array and verify that all of the indices are correct
     $indices = filter_var(array_keys($_POST['value']), FILTER_VALIDATE_INT, array("flags" => FILTER_REQUIRE_ARRAY));
     if (in_array(false, $indices, true)) {
         add_error("Invalid value id provided. Please try again.");
     }
 }
 //then check each value array to ensure either delete=1 or the other values are valid
 if (!has_error()) {
     $updates = array();
     $deletes = array();
     foreach ($_POST['value'] as $key => $value) {
         //first ensure that the value exists
         $meta_value = MetaDataValue::get($key);
         if (!$meta_value) {
             add_error("Value not found.");
function getUserCategoryValues(User $eUser, MetaDataType $category)
{
    $org_id = $eUser->getOrganisationId();
    $group = $eUser->getGroup();
    $role = $eUser->getRole();
    $proxy_id = $eUser->getID();
    return MetaDataValues::get($org_id, $group, $role, $proxy_id, $category, true, array("order by" => array(array("meta_value_id", "desc"))));
}
 * @author Developer: Jonathan Fingland <*****@*****.**>
 * @copyright Copyright 2011 Queen's University. All Rights Reserved.
*/
if (isset($_SESSION["isAuthorized"]) && (bool) $_SESSION["isAuthorized"]) {
    if ($ENTRADA_ACL->amIAllowed("metadata", "create", false)) {
        ob_clear_open_buffers();
        require_once "Entrada/metadata/functions.inc.php";
        $request = filter_input(INPUT_POST, "request", FILTER_SANITIZE_STRING);
        switch ($request) {
            case 'update':
                $user = User::get($PROXY_ID);
                $org_id = $user->getOrganisationId();
                $group = $user->getGroup();
                $role = $user->getRole();
                $proxy_id = $user->getID();
                $caching = MetaDataValues::get($org_id, $group, $role, $proxy_id);
                //first go through the values array and verify that all of the indices are correct
                $indices = filter_var(array_keys($_POST['value']), FILTER_VALIDATE_INT, array("flags" => FILTER_REQUIRE_ARRAY));
                if (in_array(false, $indices, true)) {
                    add_error("Invalid value id provided. Please try again.");
                }
                //then check each value array to ensure either delete=1 or the other values are valid
                if (!has_error()) {
                    $updates = array();
                    $deletes = array();
                    foreach ($_POST['value'] as $key => $value) {
                        //first ensure that the value exists, and then that it belongs to the user in question
                        $meta_value = MetaDataValue::get($key);
                        if (!$meta_value) {
                            add_error("Value not found.");
                            continue;