Example #1
0
function display_db_exception($pdo_exception)
{
    global $debug_mode;
    if (isset($_SESSION['user'])) {
        $usr_id = $_SESSION['user']->usr_id;
    } else {
        $usr_id = "";
    }
    $stack = generateCallTrace();
    if (strlen($stack) > 1000) {
        $stack = substr($stack, 0, 1000);
    }
    log_pdo_exception($pdo_exception, $usr_id, $stack, '');
    if ($debug_mode === true) {
        display_error('A database error has occurred.<br><br>' . 'Message:<br>' . $pdo_exception->getMessage() . '<br><br>' . 'Stack:<br>' . nl2br($stack) . '<br><br>' . 'PDO Code:<br>' . $pdo_exception->getCode() . '<br><br>' . 'PDO File:<br>' . $pdo_exception->getFile() . '<br><br>' . 'PDO Line:<br>' . $pdo_exception->getLine() . '<br><br>');
    } else {
        display_error('A database error has occurred.  Please try again.');
    }
    exit;
}
Example #2
0
 public function addPresForUser($usr_id)
 {
     // begin transaction
     global $db;
     $db->beginTransaction();
     try {
         // Check if the user currently has a presentation for this session.
         // If so, remove it.
         // The loop is a bit of overkill, but in case of an erroneous situation of the user having multiple
         // presentations for the same session, this will remove those extra cases.
         //
         // Include a check to make sure that presenters don't overwrite their presentations through this method.
         $presentations = get_presentations_by_user_by_session($usr_id, $this->ses_id);
         foreach ($presentations as $presentation) {
             Presentation::deletePresentationsByUser($usr_id, $presentation['pres_id']);
         }
         // Inserts the new session for the user.
         $this->insert_presentation_for_user($usr_id);
         // commit transaction
         $db->commit();
     } catch (PDOException $e) {
         // roll back transaction
         $db->rollback();
         // log any errors to file
         log_pdo_exception($e, $usr_id, "Adding Presentation:" . $this, "addPresForUser");
         display_db_exception($e);
         // display_error("Error saving data.");
         exit;
     }
 }
Example #3
0
 public function addPresForUser($usr_id)
 {
     // begin transaction
     global $db;
     $db->beginTransaction();
     try {
         Presentation::deletePresentationsByUserBySession($usr_id, $this->ses_id);
         // Inserts the new session for the user.
         $this->insert_presentation_for_user($usr_id);
         if ($this->pres_paired_pres_id != null) {
             $pairedPresentation = Presentation::getPresentation($this->pres_paired_pres_id);
             // iterate through a change of presentation ids until we get back to where we started.
             while ($pairedPresentation->pres_id != $this->pres_id) {
                 Presentation::deletePresentationsByUserBySession($usr_id, $pairedPresentation->ses_id);
                 // Inserts the new session for the user.
                 $pairedPresentation->insert_presentation_for_user($usr_id);
                 // iterate down the chain of paired presentations.
                 $pairedPresentation = Presentation::getPresentation($pairedPresentation->pres_paired_pres_id);
             }
         }
         // commit transaction
         $db->commit();
     } catch (PDOException $e) {
         // roll back transaction
         $db->rollback();
         // log any errors to file
         log_pdo_exception($e, $usr_id, "Adding Presentation:" . $this, "addPresForUser");
         display_error("Error saving data.");
         exit;
     }
 }
Example #4
0
function display_db_exception_v2($pdo_exception)
{
    global $debug_mode;
    if (isset($_SESSION['user'])) {
        $usr_id = $_SESSION['user']->usr_id;
    } else {
        $usr_id = "";
    }
    $stack = generateCallTrace();
    if (strlen($stack) > 1000) {
        $stack = substr($stack, 0, 1000);
    }
    log_pdo_exception($pdo_exception, $usr_id, $stack, '');
    display_error('You have tried to delete a format which is being used by a workshop. Please remove the format from the workshops before deleting the format.');
    exit;
}
Example #5
0
function change_user_tests($tests)
{
    global $db;
    global $user;
    $updt_usr_id = isset($_SESSION['prev_usr_id']) ? $_SESSION['prev_usr_id'] : $user->usr_id;
    try {
        $db->beginTransaction();
        $test_array = array();
        if (!empty($tests)) {
            $test_list = explode(',', $tests);
            foreach ($test_list as $test) {
                $test_split = explode(":", $test);
                $bindDate = date('Y-m-d H:i:s');
                $test_id = intval($test_split[0]);
                $test_time_id = intval($test_split[1]);
                $query = "call insert_user_test(:testId, :testTimeId, :usrId, :testDate, :updtUsrId)";
                $statement = $db->prepare($query);
                $statement->bindValue(':testId', $test_id, PDO::PARAM_INT);
                $statement->bindValue(':testTimeId', $test_time_id, PDO::PARAM_INT);
                $statement->bindValue(':usrId', $user->usr_id, PDO::PARAM_INT);
                $statement->bindValue(':testDate', $bindDate, PDO::PARAM_STR);
                $statement->bindValue(':updtUsrId', $updt_usr_id, PDO::PARAM_INT);
                $statement->execute();
                $statement->closeCursor();
                $test_ids = $test_id . ', ' . $test_time_id;
                array_push($test_array, $test_ids);
            }
        }
        del_user_tests($test_array, $user->usr_id);
        $db->commit();
    } catch (PDOException $e) {
        // roll back transaction
        $db->rollback();
        // log any errors to file
        log_pdo_exception($e, $user->usr_id, "Changing User's Tests:" . $user->usr_id, "change_user_tests");
        display_error($e);
        exit;
    }
}
Example #6
0
function del_pres($pres_id)
{
    global $db;
    global $user;
    $query = 'delete from user_presentation_xref where pres_id = :pres_id';
    try {
        $db->beginTransaction();
        $statement = $db->prepare($query);
        $statement->bindValue(':pres_id', $pres_id, PDO::PARAM_INT);
        $statement->execute();
        $statement->closeCursor();
        $query2 = 'delete from presentation where pres_id = :pres_id';
        $statement = $db->prepare($query2);
        $statement->bindValue(':pres_id', $pres_id, PDO::PARAM_INT);
        $statement->execute();
        $statement->closeCursor();
        $query3 = 'delete from mentors where pres_id = :pres_id';
        $statement = $db->prepare($query3);
        $statement->bindValue(':pres_id', $pres_id, PDO::PARAM_INT);
        $statement->execute();
        $statement->closeCursor();
        $db->commit();
    } catch (PDOException $e) {
        // roll back transaction
        $db->rollback();
        // log any errors to file
        log_pdo_exception($e, $user->usr_id, "Deleting Presentation:" . $pres_id, "del_pres");
        display_error($e);
        exit;
    }
}