示例#1
0
                }
                $user = trim(urldecode($data[1]));
                if (empty($user)) {
                    ajax_error('Sorry, but we cannot delete this user. Please try again later.');
                }
                $result = $db->deleteUser($user);
                break;
            default:
                ajax_error("Unsupported request method.");
        }
    } catch (Exception $e) {
        $success = 0;
        $message = $e->getMessage();
    }
    //Output result
    ajax_result(array("success" => $success, "message" => $message, "total" => count($result), "users" => $result));
} catch (\Exception $e) {
    error_log('[OnlineQuestionnaire] ERROR: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine(), 0);
}
function doInsertUpdateUsers(array $users, Database $db)
{
    $result = array();
    foreach ($users as $user) {
        if (property_exists($user, 'aclID')) {
            $aclID = $user->aclID;
        } else {
            $aclID = null;
        }
        if (!property_exists($user, 'username')) {
            throw new Exception("Username field not found for user with aclID=", aclID);
        } else {
示例#2
0
function guest_login($username, $password)
{
    if ($username == "*****@*****.**" && $password == "guest") {
        $_SESSION['auth'] = true;
        $result = array("success" => 1);
        ajax_result($result);
    } else {
        ajax_error("Invalid username or password.");
    }
}
示例#3
0
require_once "NRG/Configuration.php";
require_once '../database.php';
//Require data entry privileges
setClearanceLevel(30);
//Check for errors
if (empty($_POST) || empty($_POST['subjectid'])) {
    ajax_error('Invalid request.');
}
$subjectid = trim($_POST['subjectid']);
if (empty($subjectid)) {
    ajax_error('Invalid Subject ID.');
}
if (!preg_match('/^[A-Za-z0-9]+$/', $subjectid)) {
    ajax_error('The Subject ID you have entered contains invalid characters.');
}
//Connect to the database
try {
    $config = new \NRG\Configuration(CONFIG_FILE);
    $dbconf = $config->Database;
    $db = new Database($dbconf['host'], $dbconf['user'], $dbconf['pass'], $dbconf['name'], $dbconf['port']);
    //Verify the subject isn't locked
    if ($db->isSubjectLocked($subjectid)) {
        ajax_error('Sorry, this subject has been locked. No data entry is allowed for locked subjects.');
    }
    $session = $db->createSession($subjectid, $_SESSION['aclID']);
    $result = array("success" => 1, "session" => $session['label']);
    ajax_result($result);
} catch (Exception $e) {
    error_log($e->getMessage(), 0);
    ajax_error('An internal server error has occured. Please try again later.' . $e->getMessage());
}
示例#4
0
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * -----------------------------------------------------------------------------
 */
require_once "ajax.php";
require_once "auth.php";
require_once "NRG/Configuration.php";
require_once '../database.php';
//Require some privileges
setClearanceLevel(10);
try {
    $config = new \NRG\Configuration("../config.ini.php");
    $dbconfig = $config->Database;
    $db = new Database($dbconfig['host'], $dbconfig['user'], $dbconfig['pass'], $dbconfig['name']);
    if (!$db) {
        throw new Exception("Couldn't connect to the database.");
    }
    $result = $db->listSubjectsCreatedBy($_SESSION['aclID']);
    ajax_result(array("total" => count($result), "subjects" => $result));
} catch (\Exception $e) {
    error_log('[OnlineQuestionnaire] ERROR: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine(), 0);
}
示例#5
0
$email = strtolower(trim($_POST['email']));
try {
    $config = new \NRG\Configuration(CONFIG_FILE);
    $dbconf = $config->Database;
    //Make sure the username is registered with this application
    $db = new Database($dbconf['host'], $dbconf['user'], $dbconf['pass'], $dbconf['name'], $dbconf['port']);
    $user = $db->searchUser($email);
    if (!empty($user)) {
        if ($user['requested'] == 1) {
            ajax_error('Your access request is pending approval.');
        }
        if ($user['roleID']) {
            ajax_error('Your username has been enabled, please log in.');
        } else {
            ajax_error('Your access request is currently being reviewed.');
        }
    }
    //Looks like there is nothing else left to do, except add the user to the Acl table with
    //NULL privileges
    $db->createUser($email);
    $ur = $config->UserRegistration;
    //Prepare an e-mail message
    $message = "User {$email} requested access to " . $_SERVER['HTTP_HOST'] . " from " . $_SERVER['REMOTE_ADDR'] . ".";
    //Send e-mail
    $result = mail($ur['to'], $ur['subject'], $message, get_mail_headers($config));
    //Send the result back to the server
    ajax_result(array("success" => 1, "mail" => $result));
} catch (Exception $e) {
    error_log($e->getMessage(), 0);
    ajax_error("Internal server error. Please try again later");
}
示例#6
0
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * -----------------------------------------------------------------------------
 */
require_once "ajax.php";
require_once "auth.php";
require_once "NRG/Configuration.php";
require_once '../database.php';
//Require data manager privileges
setClearanceLevel(90);
try {
    $config = new \NRG\Configuration("../config.ini.php");
    $dbconfig = $config->Database;
    $db = new Database($dbconfig['host'], $dbconfig['user'], $dbconfig['pass'], $dbconfig['name']);
    if (!$db) {
        throw new Exception("Couldn't connect to the database.");
    }
    $result = $db->listRoles();
    ajax_result(array("total" => count($result), "roles" => $result));
} catch (\Exception $e) {
    error_log('[OnlineQuestionnaire] ERROR: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine(), 0);
}
示例#7
0
/**
 * Save a notification message for displaying on the subsequent page view
 *
 * Optionally supply a url for redirecting to before displaying the message
 * and/or an options array.
 *
 * Currently the options array only supports a 'class' entry for passing as
 * the second parameter to notification()
 *
 * @param   string  $message    Message to display
 * @param   string  $redirect   Url to redirect to (optional)
 * @param   array   $options    Options array (optional)
 * @return  void
 */
function set_notification($message, $redirect = null, $options = array()) {

    // Check options is an array
    if (!is_array($options)) {
        print_error('error:notificationsparamtypewrong', 'local_core');
    }

    // Add message to options array
    $options['message'] = $message;

    // Add to notifications queue
    queue_append('notifications', $options);

    // Redirect if requested
    if ($redirect !== null) {
        // Cancel redirect for AJAX scripts.
        if (is_ajax_request($_SERVER)) {
            ajax_result(true, queue_shift('notifications'));
        } else {
            redirect($redirect);
        }
        exit();
    }
}
示例#8
0
/** Returns an error message to an ajax request.
 * @param String $message Error message
 * @return JSON
 */
function ajax_error($message = 'An internal error has occurred')
{
    header('Content-type: application/json');
    $result = array("success" => 0, "message" => $message);
    ajax_result($result);
}