function oa_files_addmenu_callback in Open Atrium Files 7.2
Ajax Callback for adding a new document within a menu (folder)
Parameters
$node:
1 string reference to 'oa_files_addmenu_callback'
- oa_files_menu in ./
oa_files.module - Implements hook_menu().
File
- ./
oa_files.module, line 773
Code
function oa_files_addmenu_callback($parent = NULL) {
global $user;
if (empty($_REQUEST['token']) || !drupal_valid_token($_REQUEST['token'], 'add-node-' . ($parent ? $parent->nid : 'undefined'))) {
return MENU_ACCESS_DENIED;
}
$new_node = $_POST['node'];
$title = $new_node['name'];
$node = (object) array(
// Create oa_files.
'type' => 'oa_wiki_page',
'uid' => $user->uid,
'name' => $user->name,
'language' => LANGUAGE_NONE,
// Set the Title of the Document node to the same title.
'title' => $title,
'is_new' => TRUE,
);
if (($context = og_context()) && og_user_access($context['group_type'], $context['gid'], "create oa_wiki_page content")) {
// @todo check access, e.g. can add to group/section.
$node->og_group_ref = array(
LANGUAGE_NONE => array(
0 => array(
'target_id' => $context['gid'],
),
),
);
if (($section_id = oa_section_get_section_context()) && node_access('view', node_load($section_id))) {
$node->oa_section_ref = array(
LANGUAGE_NONE => array(
0 => array(
'target_id' => $section_id,
),
),
);
}
if (empty($parent)) {
$parent = node_load($section_id);
}
if ($parent && node_access('view', $parent) && ($mlid = og_menu_single_get_link_mlid('node', $parent->nid))) {
$is_in_group = FALSE;
foreach (field_get_items('node', $parent, 'og_group_ref') as $value) {
if ($value['target_id'] == $context['gid']) {
$is_in_group = TRUE;
break;
}
}
if ($is_in_group) {
$node->menu = array(
'plid' => $mlid,
'link_title' => $title,
'enabled' => TRUE,
'description' => '',
);
if ($parent->type == 'oa_section') {
$node->oa_section_ref = array(
LANGUAGE_NONE => array(
0 => array(
'target_id' => $parent->nid,
),
),
);
}
}
}
node_save($node);
$return = array(
'oa_files' => array(
'node_token' => array(
'node:' . $node->nid => drupal_get_token('add-node-' . $node->nid),
),
),
'id' => $node->nid,
'additions' => array(
'date' => format_date($node->created, 'short'),
'modified' => format_date($node->changed, 'short'),
'editor' => node_access("update", $node),
),
);
print drupal_json_output($return);
}
else {
ajax_deliver(MENU_ACCESS_DENIED);
return FALSE;
}
}