Example #1
0
def pageInit(subHeading=None, formJS=0):
    table_data = declarations.define_tables()
    print "<HTML>"
    print "<HEAD>"
    if formJS:
        pmt_utils.generate_form_javascript(table_data, 'inventory',
                                           'inv_admin', 0)
    else:
        pmt_utils.javaScript("inv_admin")
    pmt_utils.title("Inventory")
    print "</HEAD>"
    pmt_utils.bodySetup()
    pmt_utils.mainHeading('Inventory')
    if subHeading != None:
        pmt_utils.subHeading(subHeading)
    pmt_utils.formSetup("inv_admin", declarations.pmt_info['db_name'],
                        "inv_admin", "return submitForm(document.inv_admin)")

    dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'],
                                   declarations.pmt_info['browser_password'],
                                   declarations.pmt_info['db_name'])

    if dbResult['status'] != 'success':
        db = None
        status = dbResult['message']
    else:
        db = dbResult['result']
        status = 'success'

    return status, table_data, db
Example #2
0
def doEdit():
    table_data = declarations.define_tables()
    print "<HTML>"
    print "<HEAD>"
    pmt_utils.generate_form_javascript(table_data, 'project_info',
                                       'project_admin', 0)
    pmt_utils.title("Project Info Administration")
    print "</HEAD>"

    pmt_utils.bodySetup()
    pmt_utils.mainHeading('Project Info Administration')
    pmt_utils.subHeading('Edit Project Info')
    pmt_utils.formSetup("project_admin", db_name, "project_admin",
                        "return submitForm(document.project_admin)")

    dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'],
                                   declarations.pmt_info['browser_password'],
                                   declarations.pmt_info['db_name'])

    if dbResult['status'] != 'success':
        msg = "Could not connect to the database\n"
        pmt_utils.alertsArea(form, msg + dbResult['message'])
        sys.exit()

    db = dbResult['result']
    status, details = db_authentication.password_valid(db,
                                                       crypt_salt=db_name,
                                                       username=username,
                                                       password=password)
    if status != 'success':
        print '<form method=post action=/%s-cgi-bin/project_admin.pyc>' % db_name
        pmt_utils.usernamePasswordDisplay(username)
        pmt_utils.alertsArea(form, 'Can not verify you as a valid user')
        print '<hr><input name=reload type=submit value="Query">'
        print '<input name=action value=edit type=hidden>'
        print '</form>'
        sys.exit()

    if pmt_utils.hasPriv(db, username, 'project_data') != 1:
        print '<form method=post action=/%s-cgi-bin/project_admin.pyc>' % db_name
        pmt_utils.usernamePasswordDisplay(username)
        msg = 'User %s does not have project admin privileges' % username
        pmt_utils.alertsArea(form, msg)
        print '<hr><input name=reload type=submit value="Query">'
        print '<input name=action value=edit type=hidden>'
        print '</form>'
        sys.exit()

    sqlStatement = pmt_utils.selectAllColumnsSqlStatement(
        table_data, 'project_info', '1')
    dbResult = pmt_utils.executeSQL(db, sqlStatement)

    if dbResult['status'] != 'success':
        msg = "Could not retrieve project info to edit\n"
        pmt_utils.alertsArea(form, msg + dbResult['message'])
    else:
        result = dbResult['result']
        table_data = pmt_utils.dbToTableData(table_data, 'project_info',
                                             result[0])
        table_data['project_info']['id']['value'] = '1'
        pmt_utils.display_form(table_data, 'project_info', 1, 'useValues', 1,
                               db)
        pmt_utils.alertsArea(form, "Project Info retrieved successfully")

    project_adminButtons('save')
    pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden')
    pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden')
    pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden')
    print "</FORM>"
    pmt_utils.trailer(table_data, db)
    db.close()
    print "</BODY>"
    print "</HTML>"
Example #3
0
def doSave():
    table_data = declarations.define_tables()

    print "<HTML>"
    print "<HEAD>"

    pmt_utils.generate_form_javascript(table_data, 'project_info',
                                       'project_admin', 0)
    pmt_utils.title("Project Info Administration")

    print "</HEAD>"

    pmt_utils.bodySetup()
    pmt_utils.mainHeading('Project Info Administration')
    pmt_utils.subHeading('Edit Project Info')
    pmt_utils.formSetup("project_admin", db_name, "project_admin",
                        "return submitForm(document.project_admin)")

    dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'],
                                   declarations.pmt_info['browser_password'],
                                   declarations.pmt_info['db_name'])

    if dbResult['status'] != 'success':
        msg = "Project Info could not be saved, could not connect to db\n"
        pmt_utils.alertsArea(form, msg + dbResult['message'])
        # generate function button row
        project_adminButtons('save')

        # generate hidden fields for form
        pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden')
        pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden')
        pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden')
        print "</FORM>"
        pmt_utils.trailer(table_data, db)
        db.close()
        print "</BODY>"
        print "</HTML>"
        return

    db = dbResult['result']

    # save the Form
    dbResult = pmt_utils.saveForm(table_data, db, None, "project_info",
                                  " WHERE id = '1'", form)

    # if the form was not successfully saved
    if dbResult['status'] != 'success':
        msg = "Project Info could not be saved due to an error during save,\n"
        pmt_utils.alertsArea(form, msg + dbResult['message'])
    else:
        table_data = declarations.define_tables()
        table_data = pmt_utils.formToTableData(table_data, 'project_info',
                                               form)
        table_data['project_info']['id']['value'] = '1'
        pmt_utils.display_form(table_data, 'project_info', 1, 'useValues', 1,
                               db)
        pmt_utils.alertsArea(form, "Project Info successfully saved")

    # generate function button row
    project_adminButtons('save')

    # generate hidden fields for form
    pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden')
    pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden')
    pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden')
    print "</FORM>"
    pmt_utils.trailer(table_data, db)
    db.close()
    print "</BODY>"
    print "</HTML>"