Exemplo n.º 1
0
}
if (isset($_POST['submit'])) {
    // Parse data: calculate the hash and populate the data array
    $new_slot = array('time_start' => sprintf("%02d:%02d:00", clean_string($_POST['start_time_h']), clean_string($_POST['start_time_m'])), 'time_end' => sprintf("%02d:%02d:00", clean_string($_POST['end_time_h']), clean_string($_POST['end_time_m'])), 'days_hash' => day_hash($_POST['days']));
    // Get the data for all slots
    $all_slots = $db->GetAssoc("SELECT * FROM " . SLOTS_TABLE);
    // If there are no slots to loop through, there won't be a clash
    if (count($all_slots) == 0) {
        $clash = FALSE;
    } else {
        // Loop through existing slots and check for clashes
        foreach ($all_slots as $existing_slot) {
            if ($clash = check_clash($new_slot, $existing_slot)) {
                break;
            } else {
                $clash = FALSE;
            }
        }
    }
    if ($clash) {
        // If there is a clash, print an error
        echo "<p class=\"error\"><strong>Error:</strong> Your submitted slot clashes with an existing slot, between " . substr($clash['time_start'], 0, 5) . " and " . substr($clash['time_end'], 0, 5) . " on " . $days_long[$clash['clash_index']] . ".</p>";
    } elseif (!$db->Execute("INSERT INTO " . SLOTS_TABLE . " (time_start,time_end,days_hash) VALUES ('" . $new_slot['time_start'] . "','" . $new_slot['time_end'] . "','" . $new_slot['days_hash'] . "')")) {
        echo "<p>There was a database error: " . $db->ErrorMsg() . "</p>";
    } else {
        echo "<p>You have successfully created a slot from <strong>" . substr($new_slot['time_start'], 0, 5) . "</strong> to <strong>" . substr($new_slot['time_end'], 0, 5) . "</strong> on <strong>" . days_hash_to_text($new_slot['days_hash']) . "</strong>.</p>\n<p> The list on the left has also been updated.</p>\n";
    }
    echo "<p><small>[ <a href=\"javascript:hide_element('AJAX_update')\">Hide this message</a> ]</small></p>\n";
} else {
    display_error("The form was not submitted", TRUE);
}
Exemplo n.º 2
0
    ?>
"><input type="button" value="Update" name="update" onclick="javascript:save_edit('<?php 
    echo $slot['slot_id'];
    ?>
')" /><br /><input type="button" value="Cancel" name="cancel" onclick="javascript:toggle_edit('<?php 
    echo $slot['slot_id'];
    ?>
')" /></p>
        </td>
        <td><p><a href="javascript:delete_row('<?php 
    echo $slot['slot_id'];
    ?>
','<?php 
    echo substr($slot['time_start'], 0, 5);
    ?>
','<?php 
    echo substr($slot['time_end'], 0, 5);
    ?>
','<?php 
    echo days_hash_to_text($slot['days_hash']);
    ?>
')"><img src="style/images/icons/delete.png" alt="Delete" title="Delete" /></a></p></td>
    <?php 
    if (!$row) {
        echo "</tr>\n";
    }
}
// End foreach
if (!$ajax) {
    echo "</table>\n</div>\n";
}
Exemplo n.º 3
0
 */
if (!defined('IN_OB')) {
    exit;
}
if (isset($_POST['submit'])) {
    $clash = FALSE;
    $slot = array('time_start' => sprintf("%02d:%02d:00", clean_string($_POST['start_time_h']), clean_string($_POST['start_time_m'])), 'time_end' => sprintf("%02d:%02d:00", clean_string($_POST['end_time_h']), clean_string($_POST['end_time_m'])), 'days_hash' => day_hash($_POST['days']));
    // Get the details of all slots EXCEPT the one we're editing
    $all_slots = $db->Execute("SELECT * FROM " . SLOTS_TABLE . " WHERE slot_id != " . $db->qstr($_POST['slot_id']));
    // If there are no slots to loop through, there won't be a clash
    if (count($all_slots) != 0) {
        // Loop through existing slots and check for clashes
        foreach ($all_slots as $existing_slot) {
            if ($clash = check_clash($slot, $existing_slot)) {
                break;
            }
        }
    }
    if ($clash) {
        // If there is a clash, print an error
        echo "<p class\"error\">Error: Your submitted slot clashed with an existing slot, between " . substr($clash['time_start'], 0, 5) . " and " . $clash['time_end'] . " on " . $days_long[$clash['clash_index']] . ". Please go back and correct the details.</p>";
    } elseif (!$db->Execute("UPDATE " . SLOTS_TABLE . " SET time_start = '" . $slot['time_start'] . "', time_end = '" . $slot['time_end'] . "', days_hash = '" . $slot['days_hash'] . "' WHERE slot_id = " . $db->qstr($_POST['slot_id']))) {
        echo "<p>There was a database error: " . $db->ErrorMsg() . "</p>";
    } else {
        echo "<p>You have successfully edited the slot. The slot now runs from " . substr($slot['time_start'], 0, 5) . " to " . substr($slot['time_end'], 0, 5) . " on " . days_hash_to_text($slot['days_hash']) . ".</p>\n";
    }
    echo "<p><small>[ <a href=\"javascript:hide_element('AJAX_update')\">Hide this message</a> ]</small></p>\n";
} else {
    // If we're not submitting, display an error.
    echo "<p class\"error\">Error: The form was not submitted.</p>\n";
}