예제 #1
0
/**
 * modify an existing list
 * this function is registered in xajax
 * @todo this function uses a query to alter table
 * @param string $former_title former title of this list
 * @param string $title title of the new list
 * @param string $description description of the new list
 * @param array $new_definition_values new definition of current list that is to be modified
 * @param string $old_definition_str definition of current list that is to be modified
 * @return xajaxResponse every xajax registered function needs to return this object
 */
function action_modify_list($former_title, $title, $description, $new_definition_values)
{
    global $database;
    global $logging;
    global $user;
    global $list_table_description;
    global $user_start_time_array;
    $logging->info("USER_ACTION " . __METHOD__ . " (user="******", former_title={$former_title}, title={$title})");
    # store start time
    $user_start_time_array[__METHOD__] = microtime(TRUE);
    # create necessary objects
    $response = new xajaxResponse();
    $json = new Services_JSON();
    $list_table = new ListTable($former_title);
    if ($list_table->get_is_valid() == FALSE) {
        $logging->warn("create list object returns false");
        $error_message_str = $list_table->get_error_message_str();
        $error_log_str = $list_table->get_error_log_str();
        $error_str = $list_table->get_error_str();
        set_error_message("action_bar_button_modify", "above", $error_message_str, $error_log_str, $error_str, $response);
        return $response;
    }
    $list_table_note = $list_table->get_list_table_note();
    # check if title and description have been given
    if (!check_title_and_description($title, $description, $response)) {
        return $response;
    }
    # check if the new definition is correct
    $new_definition = check_definition($new_definition_values, $response);
    if (count($new_definition) == 0) {
        return $response;
    }
    # transform listtable (with new definition which contains id's)
    if ($list_table->transform($former_title, $title, $description, $new_definition) == FALSE) {
        $logging->warn("transform list returns false");
        $error_message_str = $list_table->get_error_message_str();
        $error_log_str = $list_table->get_error_log_str();
        $error_str = $list_table->get_error_str();
        set_error_message("action_bar_button_modify", "above", $error_message_str, $error_log_str, $error_str, $response);
        return $response;
    }
    # reset current list name only when name of active list has been changed
    if ($former_title != $title && $former_title == $user->get_current_list_name()) {
        $user->set_current_list_name("");
    }
    set_info_message("action_bar_button_modify", "above", "LABEL_LIST_MODIFICATIONS_DONE", $response);
    # log total time for this function
    $logging->info(get_function_time_str(__METHOD__));
    return $response;
}