def admin_check_login(request):
    user_id = SQLS.db_fetch("SELECT username FROM userAccess WHERE username = '******';" % request[2])
    if len(user_id) > 0:
        user_id = user_id[0][0]
        password = SQLS.db_fetch("SELECT password FROM userAccess WHERE username = '******';" % user_id)[0][0]
        if password == request[3]:
            return "1"
    else:
        return "3"
    return "2"
def select_reservation_by_id(data):

    info = []
    for el in SQLS.db_fetch("SELECT * FROM reservations WHERE resId = '%s';" % str(data))[0]:
        info.append(str(el))
        info.append("|")
    info.pop(-1)

    SQLS.output_update_to_screen("Received a request reservation by ID . . . . . . . ")
    return info
def select_schedule():

    info = []
    info_get = SQLS.db_fetch("SELECT inventoryItemID, datesUnavailable from inventorySchedule;")

    try:
        for el in info_get:
            for ell in el:
                info.append(str(ell))
                info.append(", ")
            info.append("%")
        info.pop(-1)
    except:
        info.append("NA")

    SQLS.output_update_to_screen("Received a request for schedule . . . . . . . ")
    return info
def select_rooms():

    info = []
    info_get = SQLS.db_fetch("SELECT * from rooms ORDER BY roomName;")

    try:
        for el in info_get:
            for ell in el:
                info.append(str(ell))
                info.append("|")
            info.append("%")
        info.pop(-1)
    except :
        info.append("NA")

    SQLS.output_update_to_screen("Received a request for room names . . . . . . . ")
    return info
def select_inventory():

    info = []
    info_get = SQLS.db_fetch("SELECT * from inventory ORDER BY title;")

    try:
        for el in info_get:
            for ell in el:
                info.append(str(ell).replace('\n', ' '))
                info.append("|")
            info.append("%")
        info.pop(-1)
    except :
        info.append("NA")

    SQLS.output_update_to_screen("Received a request for inventory items . . . . . . . ")

    return info
def select_links():

    info = []
    info_get = SQLS.db_fetch("SELECT * FROM repeated ;")

    try:
        for el in info_get:
            for ell in el:
                info.append(str(ell))
                info.append("|")
            info.append("%")
        info.pop(-1)
    except:
        info.append("NA")

    SQLS.output_update_to_screen("Received a request for linked items . . . . . . . ")

    return info;
def admin_add_device(request):

    cells = request.split("|")
    SQLS.db_update(
        "INSERT INTO inventory (title, description, type, barcode) VALUES ('%s','%s','%s','%s');" %
        (cells[0], cells[1], cells[2], cells[3])
    )

    new_id = SQLS.db_fetch(
        "SELECT invID FROM inventory WHERE title = '%s' AND barcode = '%s';" % (cells[0], cells[3])
    )[0][0]

    SQLS.db_update(
        "INSERT INTO inventorySchedule (inventoryItemID, datesUnavailable) "
        "VALUES ('%s','%s');" %
        (new_id, "0000-00-00 00:00:00 | 0000-00-00 00:00:00")
    )
    return "1"
def select_reserved_items_not_returned():

    info = []
    reservations = SQLS.db_fetch(
        "SELECT * FROM reservations WHERE timeDelivered != '0000-00-00 00:00:00' AND timePickedup = '0000-00-00 00:00:00';"
    )

    for el in reservations:
        for ell in el:
            info.append(str(ell))
            info.append("|")
        info.append("%")
    info.pop(-1)

    if info[-1] == "|":
        info.pop(-1)

    SQLS.output_update_to_screen("Request for items not in reservation room . . . . . . . . ")

    return info
def select_past_deliveries():

    info = []
    info_get = SQLS.db_fetch("SELECT * FROM reservations WHERE timeDelivered != '0000-00-00 00:00:00' AND timePickedup \
    = '0000-00-00 00:00:00' AND DATE(resEnd) <= CURDATE() ORDER BY resEnd;")

    # "SELECT * FROM reservations WHERE timeDelivered != '0000-00-00 00:00:00' AND timePickedup \
    #  = '0000-00-00 00:00:00' AND resEnd <= NOW() ORDER BY resEnd;"

    try:
        for el in info_get:
            for ell in el:
                info.append(str(ell))
                info.append("|")
            info.append("%")
        info.pop(-1)
    except:
        info.append("NA")

    SQLS.output_update_to_screen("Request for today's pickups . . . . . . . . . . . . . ")

    return info
def select_reservations_by_date(date):

    info = []
    reservations = SQLS.db_fetch(
        "SELECT * FROM reservations WHERE DATE(resStart) = DATE('%s');" % date
    )

    try:
        for el in reservations:
            for ell in el:
                info.append(str(ell))
                info.append("|")
            info.append("%")
        info.pop(-1)

        if info[-1] == "|":
            info.pop(-1)
    except :
        # If there are no deliveries for the day, send this back :
        info.append("NA")

    return info
def select_future_deliveries():

    info = []
    info_get = SQLS.db_fetch(
        "select * from reservations where DATE(resStart) = CURDATE() AND deliveredBy = 'NA' ORDER BY resStart;")

    try:
        for el in info_get:
            for ell in el:
                info.append(str(ell))
                info.append("|")
            info.append("%")
        info.pop(-1)

        if info[-1] == "|":
            info.pop(-1)
    except :
        # If there are no deliveries for the day, send this back :
        info.append("NA")

    SQLS.output_update_to_screen("Received a request for today's deliveries . . . . . ")

    return info
Example #12
0
def admin_remove_device(request):

    # Get list of reservations
    future_reservations = SQLS.db_fetch(
        "SELECT * from reservations WHERE DATE(resStart) >= CURDATE();"
    )

    conflicts = []
    repeated_ids_checked = []

    for el in future_reservations:

        each_device_in_reservation = el[11].split(", ")

        for ell in each_device_in_reservation:

            if ell == request:

                conflict_map = ""

                if el[12] != "NA" and el[12] not in repeated_ids_checked:

                    repeated_ids_checked = el[12]

                    startEndDateTimes = SQLS.db_fetch(
                        "SELECT firstOccurance, lastOccurance, type FROM repeated WHERE repeatedid = %s;" % el[12]
                    )

                    # If current reservation is part of a series, place in it's id and dates for repeated table
                    conflict_map = "r" + "|" + str(el[12]) + "|" + str(startEndDateTimes[0][0]) \
                                   + "|" + str(startEndDateTimes[0][1]) + "|" + startEndDateTimes[0][2] + "|" + str(ell)

                elif el[12] == "NA":

                    startEndDateTimes = SQLS.db_fetch(
                        "SELECT resStart, resEnd FROM reservations WHERE resId = %s;" % el[0]
                    )

                    # If current reservation is not part of a series, place in its resId, and dateTimes
                    conflict_map = "s" + "|" + str(el[0]) + "|" + str(startEndDateTimes[0][0]) \
                                   + "|" + str(startEndDateTimes[0][1]) + "|" + str(ell)

                if conflict_map != "":
                    conflicts.append(conflict_map)
                    conflicts.append("%")

    if len(conflicts) > 0:
        if conflicts[-1] == "%":
            conflicts.pop(-1)

    conflicts_to_return = ""

    for el in conflicts:
        conflicts_to_return += el

    # If there are conflicts with removing the device, alert the user to do a replacement call
    if conflicts_to_return != "":

        return conflicts_to_return

    else:

        SQLS.output_update_to_screen(("Removing device : " + request + ". No conflicts found."))

        SQLS.db_update(
            "DELETE FROM inventory WHERE invID = %s;" % request
        )

        SQLS.db_update(
            "DELETE FROM inventoryschedule WHERE inventoryItemID = %s;" % request
        )
    return "1"
Example #13
0
def admin_do_remove_device(request):

    print " Replacing item in reservation(s)"

    cells = request.split("|")

    if cells[0] == "r":

        repeated_info = SQLS.db_fetch(
            "SELECT * FROM repeated WHERE repeatedid = %s; " % cells[1]
        )[0]

        for reservation_id in repeated_info[1].split(","):

            reservation = SQLS.db_fetch(
                "SELECT * FROM reservations WHERE resId = %s;" % reservation_id
            )[0]

            # Add time of reservation to the inventory schedule
            new_time_block = str(reservation[1]) + " | " + str(reservation[2])
            INSERT.insert_time_block_to_inventory_schedule(new_time_block, cells[2])

            new_items = []
            items = reservation[11].split(", ")
            for el in items:
                if el == cells[3]:
                    new_items.append(cells[2])
                    new_items.append(", ")
                else:
                    new_items.append(el)
                    new_items.append(", ")

            if len(new_items) > 0:
                if new_items[-1] == ", ":
                    new_items.pop(-1)

            list_string = ""
            for el in new_items:
                list_string += el

            SQLS.db_update(
                "UPDATE reservations SET inventoryList = '%s' WHERE resId = %s;" % (list_string, reservation_id)
            )

    elif cells[0] == "s":

        reservation = SQLS.db_fetch(
            "SELECT * FROM reservations WHERE resId = %s;" % cells[1]
        )[0]

        # Add time of reservation to the inventory schedule
        new_time_block = str(reservation[1]) + " | " + str(reservation[2])
        INSERT.insert_time_block_to_inventory_schedule(new_time_block, cells[2])

        new_items = []
        items = reservation[11].split(", ")
        for el in items:
            if el == cells[3]:
                new_items.append(cells[2])
                new_items.append(", ")
            else:
                new_items.append(el)
                new_items.append(", ")

        if len(new_items) > 0:
            if new_items[-1] == ", ":
                new_items.pop(-1)

        list_string = ""
        for el in new_items:
            list_string += el

        SQLS.db_update(
            "UPDATE reservations SET inventoryList = '%s' WHERE resId = %s;" % (list_string, cells[1])
        )

    return "1"