$deleteWarningMessage = "Are you sure you want to delete \'".($datasource->publicName)."\'? ".
                        "This will delete all the associated Dashboards, Reports and Datasets from that topic. ".
                        "This action cannot be undone.";

if ( isset($_POST['editdatamart']) && $_POST['editdatamart'] == "yes" ) {

    $errors = array();

    // validate
    if ( trim($_POST['publicName']) == '' ) {
        $errors[] = "Name can not be blank";
    }

    if ( trim($_POST['publicName']) != $datasource->publicName && !gd_datasource_name_is_unique(trim($_POST['publicName'])) ) {
        $errors[] = "Topic Name already exists. Please rename the topic";
    }

    // process
    if ( empty($errors) ) {
        $action = (isset($_POST['save_datamart'])) ? $_POST['save_datamart'] : $_POST['delete_datamart'];

        if ( $action == 'Save' ) {

            try {
                gd_datasource_update($datasourceName,$_POST);

                drupal_set_message("Topic successfully updated","status");
                drupal_goto("account_datamart_statistics_charts");
            } catch ( Exception $e ) {
<?php

if ( !gd_account_user_is_admin() ) {
    echo "<h3>Access Denied</h3>";
    drupal_exit();
}

$errors = array();
if ( isset($_POST['createdatamart']) && ($_POST['createdatamart'] == "yes") ) {

    // validate
    if ( trim($_POST['publicName']) == '' ) {
        $errors[] = "Name can not be blank";
    }

    if ( !gd_datasource_name_is_unique(trim($_POST['publicName'])) ) {
        $errors[] = "Topic Name already exists. Please rename the topic";
    }

    // process
    if ( empty($errors) ) {
        global $user;

        $new = array();
        $new['publicName'] = $_POST['publicName'];
        $new['description'] = $_POST['description'];

        try {
            $datasourceName = gd_datasource_create($new);
            gd_datasource_set_active($datasourceName);