name)) or profiles filtered * * @param mixed Array with filter conditions to retrieve profiles or false. * * @return array List of all profiles */ function profile_get_profiles ($filter = false) { if ($filter === false) { $profiles = db_get_all_rows_in_table ("tperfil", "name"); } else { $profiles = db_get_all_rows_filter ("tperfil", $filter); } $return = array (); if ($profiles === false) { return $return; } foreach ($profiles as $profile) { $return[$profile["id_perfil"]] = $profile["name"]; } return $return; } /** * Create Profile for User * * @param string User ID * @param int Profile ID (default 1 => AR) * @param int Group ID (default 1 => All) * @param string Assign User who assign the profile to user. * @param string tags where the view of the user in this group will be restricted * @param bool Profile is secondary or not * * @return mixed Number id if succesful, false if not */ function profile_create_user_profile ($id_user, $id_profile = 1, $id_group = 0, $assignUser = false, $tags = '', $is_secondary = false ) { global $config; if (empty ($id_profile) || $id_group < 0) return false; // Secondary server is an enterprise function if (!enterprise_installed() && $is_secondary) return false; // Checks if the user exists $result_user = users_get_user_by_id($id_user); if (!$result_user) { return false; } // Cannot mix secondary and primary profiles if (!profile_check_group_mode($id_user, $id_group, $is_secondary)) return false; if (isset ($config["id_user"])) { //Usually this is set unless we call it while logging in (user known by auth scheme but not by pandora) $assign = $config["id_user"]; } else { $assign = $id_user; } if ($assignUser !== false) $assign = $assignUser; $insert = array ( "id_usuario" => $id_user, "id_perfil" => $id_profile, "id_grupo" => $id_group, "tags" => $tags, "assigned_by" => $assign, "is_secondary" => $is_secondary ? 1 : 0 ); return db_process_sql_insert ("tusuario_perfil", $insert); } /** * Delete user profile from database * * @param string User ID * @param int Profile ID * * @return bool Whether or not it's deleted */ function profile_delete_user_profile ($id_user, $id_profile) { $where = array( 'id_usuario' => $id_user, 'id_up' => $id_profile); return (bool)db_process_sql_delete('tusuario_perfil', $where); } /** * Delete profile from database (not user-profile link (tusuario_perfil), but the actual profile (tperfil)) * * @param int Profile ID * * @return bool Whether or not it's deleted */ function profile_delete_profile ($id_profile) { return (bool)db_process_sql_delete('tperfil', array('id_perfil' => $id_profile)); } /** * Check if a group can be added being secondary or normal * * @param int User ID you want to check * @param int Group ID you want to check * @param bool Mode of profile will be inserted * * @return bool False if there is a group with the mode already added */ function profile_check_group_mode($user_id, $group_id, $is_secondary) { $inserted_type = (int)db_get_value_sql(sprintf( 'SELECT COUNT(*) FROM tusuario_perfil WHERE id_grupo=%d AND is_secondary=%d AND id_usuario="%s"', $group_id, !$is_secondary ? 1 : 0, $user_id) ); return $inserted_type === 0; } /** * Print the table to display, create and delete profiles * * @param int User id * @param string Title of the table view * @param bool Show the tags select or not */ function profile_print_profile_table ($id, $title, $is_secondary = false) { global $config; $is_secondary = enterprise_installed() ? $is_secondary : false; $table = new stdClass(); $table->width = '100%'; $table->class = 'databox data'; if (defined("METACONSOLE")) { $table->head_colspan[0] = 0; $table->width = '100%'; $table->class = 'databox_tactical data'; $table->title = $title; } else { echo '