Moved vconsole templates to enterprise
This commit is contained in:
parent
9924c7877a
commit
a51851cc79
|
@ -4066,258 +4066,5 @@ function visual_map_macro($label,$module){
|
|||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visual console templates
|
||||
*/
|
||||
|
||||
function visual_map_template_get_template_definition($id_layout_template) {
|
||||
global $config;
|
||||
|
||||
return db_get_row ('tlayout_template', 'id', $id_layout_template);
|
||||
}
|
||||
|
||||
|
||||
function visual_map_template_get_template_elements($id_layout_template) {
|
||||
global $config;
|
||||
|
||||
return db_get_all_rows_filter('tlayout_template_data', array('id_layout_template' => $id_layout_template));
|
||||
}
|
||||
|
||||
function visual_map_get_definition($id_layout) {
|
||||
global $config;
|
||||
|
||||
return db_get_row ('tlayout', 'id', $id_layout);
|
||||
}
|
||||
|
||||
|
||||
function visual_map_get_elements($id_layout) {
|
||||
global $config;
|
||||
|
||||
return db_get_all_rows_filter('tlayout_data', array('id_layout' => $id_layout));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new template from existing visual console
|
||||
* @param int $id_layout existing visual console
|
||||
* @return true OK, false not OK
|
||||
*/
|
||||
function visual_map_create_template($id_layout, $name, $id_group) {
|
||||
global $config;
|
||||
|
||||
$layout = visual_map_get_definition($id_layout);
|
||||
$layout_data = visual_map_get_elements($id_layout);
|
||||
|
||||
// Create new template based on received information
|
||||
$template_skel = $layout;
|
||||
|
||||
// rm id
|
||||
unset($template_skel["id"]);
|
||||
|
||||
// Update fields
|
||||
if (!empty($name)) {
|
||||
$template_skel["name"] = $name;
|
||||
}
|
||||
|
||||
$template_skel["id_group"] = $id_group;
|
||||
|
||||
$template_id = db_process_sql_insert('tlayout_template', $template_skel);
|
||||
|
||||
foreach ($layout_data as $item) {
|
||||
$data_template_skel = $item;
|
||||
|
||||
// remove unwanted fields
|
||||
unset($data_template_skel["id"]);
|
||||
unset($data_template_skel["id_layout"]);
|
||||
|
||||
// Update fields
|
||||
$data_template_skel["id_layout_template"] = $template_id;
|
||||
$data_template_skel["module_name"] = modules_get_agentmodule_name($item["id_agente_modulo"]);
|
||||
$data_template_skel["agent_name"] = agents_get_name($item["id_agent"]);
|
||||
|
||||
// remove unwanted fields
|
||||
unset($data_template_skel["id_agente_modulo"]);
|
||||
unset($data_template_skel["id_agent"]);
|
||||
|
||||
$data_template_id = db_process_sql_insert('tlayout_template_data', $data_template_skel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $template_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new visual console based on target id_layout_template
|
||||
* @param int $id_layout_template target template
|
||||
* @param string $name name for new visual console
|
||||
* @param int $id_agent target id_agent to customize template
|
||||
* @return id_layout OK, null not OK
|
||||
*/
|
||||
function visual_map_instanciate_template($id_layout_template, $name, $id_agent) {
|
||||
global $config;
|
||||
|
||||
$layout_id = false;
|
||||
|
||||
|
||||
if ($id_agent) {
|
||||
// retrieve template data
|
||||
$template = visual_map_template_get_template_definition($id_layout_template);
|
||||
$template_data = visual_map_template_get_template_elements($id_layout_template);
|
||||
|
||||
if ($template === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
$template["name"] = $name;
|
||||
} else {
|
||||
$template["name"] .= io_safe_input(' ') . agents_get_alias($id_agent);
|
||||
}
|
||||
|
||||
unset($template["id"]);
|
||||
|
||||
// insert template schema
|
||||
$layout_id = db_process_sql_insert('tlayout', $template);
|
||||
|
||||
foreach ($template_data as $item) {
|
||||
|
||||
// update fields
|
||||
$item["id_agente_modulo"] = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('nombre' => $item["module_name"], 'id_agente' => $id_agent, 'delete_pending' => 0));
|
||||
$item["id_agent"] = $id_agent;
|
||||
$item["id_layout"] = $layout_id;
|
||||
|
||||
// replace macro names
|
||||
$item["label"] = str_replace('_agentalias_', agents_get_alias($id_agent), $item["label"]);
|
||||
$item["label"] = str_replace('_agent_', agents_get_name($id_agent), $item["label"]);
|
||||
|
||||
// remove useless fields
|
||||
unset($item["id"]);
|
||||
unset($item["id_layout_template"]);
|
||||
unset($item["agent_name"]);
|
||||
unset($item["module_name"]);
|
||||
|
||||
$data_template_id = db_process_sql_insert('tlayout_data', $item);
|
||||
}
|
||||
}
|
||||
|
||||
return $layout_id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases given id_layout_template
|
||||
* @param int $id_layout_template target template to be deleted
|
||||
* @return true OK, false ERR
|
||||
*/
|
||||
function visual_map_delete_template($id_layout_template) {
|
||||
global $config;
|
||||
|
||||
if (!$id_layout_template) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// tlayout_template_data is erased using foreign key
|
||||
return db_process_sql_delete('tlayout_template', array('id' => $id_layout_template));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of layout templates for given user.
|
||||
*
|
||||
* @param int User id.
|
||||
* @param bool Wheter to return all the fields or only the name (to use in
|
||||
* html_print_select() directly)
|
||||
* @param array Additional filters to filter the layouts.
|
||||
* @param bool Whether to return All group or not.
|
||||
*
|
||||
* @return array A list of layouts the user can see.
|
||||
*/
|
||||
function visual_map_get_user_layout_templates ($id_user = 0, $only_names = false, $filter = false,
|
||||
$returnAllGroup = true, $favourite = false) {
|
||||
|
||||
if (! is_array ($filter)){
|
||||
$filter = array ();
|
||||
} else {
|
||||
if(!empty($filter['name'])){
|
||||
$where .= "name LIKE '%".io_safe_output($filter['name'])."%'";
|
||||
unset($filter['name']);
|
||||
}
|
||||
}
|
||||
|
||||
if($favourite){
|
||||
if (empty($where)){
|
||||
$where = "";
|
||||
}
|
||||
|
||||
if ($where != '') {
|
||||
$where .= ' AND ';
|
||||
}
|
||||
|
||||
$where .= "is_favourite = 1";
|
||||
}
|
||||
|
||||
if ($returnAllGroup) {
|
||||
$groups = users_get_groups ($id_user, 'VR', true, true);
|
||||
} else {
|
||||
|
||||
if(!empty($filter['group'])) {
|
||||
$permissions_group = users_get_groups ($id_user, 'VR', false, true);
|
||||
if(empty($permissions_group)){
|
||||
$permissions_group = users_get_groups ($id_user, 'VM', false, true);
|
||||
}
|
||||
$groups = array_intersect_key($filter['group'], $permissions_group);
|
||||
} else {
|
||||
$groups = users_get_groups ($id_user, 'VR', true, true);
|
||||
if(empty($groups)) {
|
||||
$groups = users_get_groups ($id_user, 'VM', true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unset($filter['group']);
|
||||
}
|
||||
|
||||
if (!empty($groups)) {
|
||||
if (empty($where))
|
||||
$where = "";
|
||||
|
||||
if ($where != '') {
|
||||
$where .= ' AND ';
|
||||
}
|
||||
$where .= sprintf ('id_group IN (%s)', implode (",", array_keys ($groups)));
|
||||
}
|
||||
|
||||
$where .= db_format_array_where_clause_sql ($filter);
|
||||
|
||||
if ($where == '') {
|
||||
$where = array();
|
||||
}
|
||||
|
||||
$layouts = db_get_all_rows_filter ('tlayout_template', $where);
|
||||
if ($layouts == false)
|
||||
return array ();
|
||||
|
||||
$retval = array ();
|
||||
foreach ($layouts as $layout) {
|
||||
if ($only_names)
|
||||
$retval[$layout['id']] = $layout['name'];
|
||||
else
|
||||
$retval[$layout['id']] = $layout;
|
||||
|
||||
//add_perms
|
||||
if ($groups[$layout['id_group']]['vconsole_view']){
|
||||
$retval[$layout['id']]['vr'] = $groups[$layout['id_group']]['vconsole_view'];
|
||||
}
|
||||
if ($groups[$layout['id_group']]['vconsole_edit']){
|
||||
$retval[$layout['id']]['vw'] = $groups[$layout['id_group']]['vconsole_edit'];
|
||||
}
|
||||
if ($groups[$layout['id_group']]['vconsole_management']){
|
||||
$retval[$layout['id']]['vm'] = $groups[$layout['id_group']]['vconsole_management'];
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue