コード例 #1
0
		ecommerce.formSetup("product_categories_admin","product_categories_admin","return submitForm(document.product_categories_admin)",declarations.store_info['db_name'])

		dbResult = ecommerce.connectDB(form["uHidden"].value, form["pHidden"].value,declarations.store_info['db_name'])
		
		if dbResult['status'] != 'success':
			ecommerce.alertsArea(form, "Could not connect to the database\n" + dbResult['message']);

		else:
			db = dbResult['result']

			sqlStatement = ecommerce.selectAllColumnsSqlStatement(table_data,'product_categories',form["key_id"].value,'category')

			#print sqlStatement

			dbResult = ecommerce.executeSQL(db, sqlStatement)

			if dbResult['status'] != 'success':

				ecommerce.alertsArea(form, "Could not retrieve category values to edit\n" + dbResult['message']);

			else:

				result = dbResult['result']

				table_data = ecommerce.dbToTableData(table_data, 'product_categories', result[0])

				ecommerce.display_form(table_data, 'product_categories', 1, 'useValues', 1, db)
				

				ecommerce.alertsArea(form, "Product Categoriess retrieved successfully");
コード例 #2
0
                                       declarations.store_info['db_name'])

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

        else:
            db = dbResult['result']

            sqlStatement = ecommerce.selectAllColumnsSqlStatement(
                table_data, 'customers', form["key_id"].value)

            #			sqlStatement = "SELECT p.id, p.date_built, p.car_garage, p.town, p.subdivision, p.style, p.full_basement, p.bedrooms, p.baths, p.square_footage, p.price, p.description, p.image, p.directions, p.heating_air, p.number_rooms, p.electric_service, p.school_district, p.acreage FROM customers p WHERE p.id = '" + form["key_id"].value + "'"

            dbResult = ecommerce.executeSQL(db, sqlStatement)

            if dbResult['status'] != 'success':

                ecommerce.alertsArea(
                    form, "Could not retrieve customer data to edit\n" +
                    dbResult['message'])

            else:

                result = dbResult['result']

                table_data = ecommerce.dbToTableData(table_data, 'customers',
                                                     result[0])

                ecommerce.display_form(table_data, 'customers', 1, 'useValues',
コード例 #3
0
		table_data = declarations.define_tables()

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

		dbResult = ecommerce.connectDB(form["uHidden"].value, form["pHidden"].value,declarations.store_info['db_name'])
		
		if dbResult['status'] != 'success':
			ecommerce.alertsArea(form, "Could not connect to the database\n" + dbResult['message'])

		else:

			db = dbResult['result']

			dbResult = ecommerce.executeSQL(db, "SELECT line_item, order_id, product_id, quantity, quantity_shipped, price, line_subtotal FROM order_items WHERE order_id = '" + form['key_id'].value + "'")

			if dbResult['status'] != 'success':
			
				ecommerce.alertsArea(form, "Could not retrieve order data to edit\n" + dbResult['message'])
				print "</FORM>"
				
				ecommerce.trailer(table_data, db)
				db.close()

				print "</BODY>"
				print "</HTML>"
				sys.exit(1)
				
			result = dbResult['result']
コード例 #4
0
        dbResult = ecommerce.connectDB(form["uHidden"].value,
                                       form["pHidden"].value,
                                       declarations.store_info['db_name'])

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

        else:
            db = dbResult['result']

            sqlStatement = ecommerce.selectAllColumnsSqlStatement(
                table_data, 'products', form["key_id"].value)

            dbResult = ecommerce.executeSQL(db, sqlStatement)

            if dbResult['status'] != 'success':

                ecommerce.alertsArea(
                    form, "Could not retrieve product data to edit\n" +
                    dbResult['message'])

            else:

                result = dbResult['result']

                table_data = ecommerce.dbToTableData(table_data, 'products',
                                                     result[0])

                ecommerce.display_form(table_data, 'products', 1, 'useValues',
コード例 #5
0
    def create_db(self):

        import declarations

        os.system('destroydb %s' % (self.db_name))
        os.system("createdb %s" % (self.db_name))

        os.system("/usr/bin/destroyuser " + self.db_admin_username)

        print "Answer NO to the next prompt"

        os.system("/usr/bin/createuser -i 1000 -D -U " +
                  self.db_admin_username)

        os.system("/usr/bin/destroyuser " + self.visitor_username)

        print "Answer NO to the next prompt"

        os.system("/usr/bin/createuser -i 2000 -D -U " + self.visitor_username)

        dbResult = ecommerce.connectDB(self.postgres_username,
                                       self.postgres_password, self.db_name)

        if dbResult['status'] != "success":
            print dbResult['message']
            sys.exit(1)

        db = dbResult['result']

        queryResult = ecommerce.executeSQL(
            db, "DELETE FROM pg_group WHERE groname = 'admins'")

        queryResult = ecommerce.executeSQL(
            db,
            "INSERT INTO pg_group (groname, grosysid, grolist) VALUES ('admins', '1', '{1000}')"
        )

        if queryResult["status"] != 'success':
            print queryResult["status"]
            sys.exit(1)

        queryResult = ecommerce.executeSQL(
            db, "DELETE FROM pg_group WHERE groname = 'users'")

        queryResult = ecommerce.executeSQL(
            db,
            "INSERT INTO pg_group (groname, grosysid, grolist) VALUES ('users', '2', '{2000}')"
        )

        if queryResult["status"] != 'success':
            print queryResult["status"]
            sys.exit(1)

        queryResult = ecommerce.executeSQL(
            db, "ALTER USER postgres WITH PASSWORD " + self.postgres_password)

        if queryResult["status"] != 'success':
            print queryResult['message']
            sys.exit(1)

        queryResult = ecommerce.executeSQL(
            db, "ALTER USER %s WITH PASSWORD %s IN GROUP admins" %
            (self.db_admin_username, self.db_admin_password))

        if queryResult["status"] != 'success':
            print queryResult['message']
            sys.exit(1)

        queryResult = ecommerce.executeSQL(
            db, "ALTER USER %s WITH PASSWORD %s IN GROUP users" %
            (self.visitor_username, self.visitor_password))

        if queryResult["status"] != 'success':
            print queryResult['message']
            sys.exit(1)

        queryResult = ecommerce.create_tables(db, declarations.define_tables(),
                                              1)

        if queryResult["status"] != 'success':
            print queryResult['message']
            sys.exit(1)

        status, populate_tables = file_io.readFromFile(self.db_name +
                                                       '.tables')

        for index in xrange(0, len(populate_tables)):
            populate_tables[index] = string.strip(populate_tables[index])
            if populate_tables[index] == '':
                del populate_tables[index]
            elif populate_tables[index][:4] == 'COPY':
                populate_tables[index] = os.path.expandvars(
                    populate_tables[index])

        queryResult = ecommerce.executeSqlItemList(db, populate_tables, 1, 1)

        if queryResult["status"] != 'success':
            print queryResult
            print "Failed to execute all populate table statements"
            sys.exit(1)

        grantList = []

        privileges = declarations.table_privileges()

        for table_name in privileges.keys():
            for user_name in privileges[table_name].keys():
                grantStatement = "GRANT "
                for privilege in privileges[table_name][user_name]:
                    grantStatement = grantStatement + privilege + ", "

                grantStatement = grantStatement[:
                                                -2] + " ON " + table_name + " TO " + user_name
                grantList.append(grantStatement)

            # grant all privileges to the db admin
            grantList.append("GRANT ALL ON " + table_name + " TO " +
                             self.db_admin_username)

        queryResult = ecommerce.executeSqlItemList(db, grantList, 1)

        if queryResult["status"] != 'success':
            print "Failed to execute all GRANTS"
            sys.exit(1)
コード例 #6
0
def query_properties(performDbQuery=0, onLoad=None, queryFields=None):

    table_data = declarations.define_tables()

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

    ecommerce.javaScript("customer_property_admin", 1)

    ecommerce.title("Customer Property Administration")

    print "</HEAD>"

    ecommerce.bodySetup(onLoad)

    print '<CENTER>'
    print '<TABLE COLS=1 WIDTH=585>'
    print '<TR><TD>'

    ecommerce.mainHeading('Customer Property Administration')

    ecommerce.subHeading('Property Listing')

    ecommerce.formSetup("customer_property_admin", "customer_property_admin",
                        "return submitForm(document.customer_property_admin)",
                        declarations.store_info['db_name'])

    if form.has_key("customer_id"):
        customer_id = form["customer_id"].value
    else:
        if form.has_key("cHidden"):
            customer_id = form["cHidden"].value
        else:
            customer_id = ''

    if form.has_key("username"):
        username = form["username"].value
    else:
        if form.has_key("uHidden"):
            username = form["uHidden"].value
        else:
            username = ''

    if form.has_key("password"):
        password = form["password"].value
    else:
        if form.has_key("pHidden"):
            password = form["pHidden"].value
        else:
            password = ''

    print '<TABLE><BORDER=0>'
    print '<TR>'

    ecommerce.tableColumn('<B>Customer ID:</B>')
    print '<TD ALIGN=CENTER NOWRAP>'

    ecommerce.textbox(None, 'customer_id', customer_id, '10', '10',
                      "checkBlankField(this, 'Customer ID')",
                      "displayHint('Enter your customer id')")
    print '</TD>'

    ecommerce.tableColumn('<B>Username:</B>')
    print '<TD ALIGN=CENTER NOWRAP>'

    ecommerce.textbox(None, 'username', username, '9', '9',
                      "checkBlankField(this, 'Username')",
                      "displayHint('Enter your username')")
    print '</TD>'

    ecommerce.tableColumn('<B>Password:</B>')

    print '<TD ALIGN=CENTER NOWRAP>'

    ecommerce.textbox(None, 'password', password, '8', '8',
                      "checkBlankField(this, 'Password')",
                      "displayHint('Enter your password')", 'password')

    print '</TD>'
    print '</TR>'
    print '</TABLE>'

    if form.has_key("performDbQuery") or performDbQuery == 1:

        dbResult = ecommerce.connectDB(
            declarations.store_info['browser_username'],
            declarations.store_info['browser_password'],
            declarations.store_info['db_name'])

        # could not connect to db
        if dbResult['status'] != 'success':

            ecommerce.alertsArea(
                form, "Can not connect to database,\n" + dbResult['message'])

            print '<HR>'
            print '<TABLE>'
            print '<TR>'
            ecommerce.tableColumn(
                '<INPUT NAME="query" type="button" value=" Query " onClick="return execute('
                + "'query'" + ')">')
            ecommerce.tableColumn(
                '<INPUT TYPE="button" NAME="help" VALUE=" Help " onClick="return goto_url ('
                + "'" + help_pdf + "'" + ')">')
            print '</TR>'
            print '</TABLE>'

        else:

            db = dbResult['result']

            # validate username password and customer id
            dbResult = ecommerce.executeSQL(
                db, "SELECT count(*) FROM customers WHERE id = '" +
                string.strip(customer_id) + "' AND account_username = '******' AND account_password = '******'")

            if dbResult['status'] != 'success':

                ecommerce.alertsArea(
                    form,
                    "Could not validate customer information provided\n" +
                    dbResult['message'])

                ecommerce.textbox(None, 'key_id', '', '10', '10', None, None,
                                  'hidden')
                ecommerce.textbox(None, 'action', '', '10', '10', None, None,
                                  'hidden')
                ecommerce.textbox(None, 'cHidden', customer_id, '10', '10',
                                  None, None, 'hidden')
                ecommerce.textbox(None, 'uHidden', username, '9', '9', None,
                                  None, 'hidden')
                ecommerce.textbox(None, 'pHidden', password, '8', '8', None,
                                  None, 'hidden')

                print "</FORM>"

                ecommerce.trailer(table_data, db)

                print '</TD>'
                print '</TR>'
                print '</TABLE>'
                print '</CENTER>'

                print "</BODY>"
                print "</HTML>"

            else:

                result = dbResult['result']

                if result[0]['count'] != 1:
                    ecommerce.alertsArea(
                        form,
                        "Could not validate customer information provided\n" +
                        dbResult['message'])
                    print '<HR>'
                    print '<TABLE>'
                    print '<TR>'
                    ecommerce.tableColumn(
                        '<INPUT NAME="query" type="button" value=" Query " onClick="return execute('
                        + "'query'" + ')">')
                    ecommerce.tableColumn(
                        '<INPUT TYPE="button" NAME="help" VALUE=" Help " onClick="return goto_url ('
                        + "'" + help_pdf + "'" + ')">')
                    print '</TR>'
                    print '</TABLE>'

                    ecommerce.textbox(None, 'key_id', '', '10', '10', None,
                                      None, 'hidden')
                    ecommerce.textbox(None, 'action', '', '10', '10', None,
                                      None, 'hidden')
                    ecommerce.textbox(None, 'cHidden', customer_id, '10', '10',
                                      None, None, 'hidden')
                    ecommerce.textbox(None, 'uHidden', username, '9', '9',
                                      None, None, 'hidden')
                    ecommerce.textbox(None, 'pHidden', password, '8', '8',
                                      None, None, 'hidden')

                    print "</FORM>"

                    ecommerce.trailer(table_data, db)

                    print '</TD>'
                    print '</TR>'
                    print '</TABLE>'
                    print '</CENTER>'

                    print "</BODY>"
                    print "</HTML>"

                    sys.exit(1)

            queryFields, whereFields = ecommerce.getQueryWhereFields(
                form, table_data, 'properties')

            if queryFields == None or queryFields == []:
                queryFields = []
                whereFields = None
                queryFields.append('id')
                queryFields.append('town')
                queryFields.append('style')
                queryFields.append('bedrooms')
                queryFields.append('price')

            dbResult, queryStatement = ecommerce.executeQuery(
                db, table_data, 'properties', queryFields, whereFields,
                'query', queryCustomerItemHtml, 'ORDER BY id', 'id',
                "customer_id='" + customer_id + "' and display_property = 't'")

            # if query was not successful
            if dbResult['status'] != 'success':
                ecommerce.alertsArea(
                    form, "Could not retrieve properties from database,\n" +
                    dbResult['message'])
            # else properties were retrieved ok
            else:
                ecommerce.alertsArea(
                    form, "Last Query Statement: " + queryStatement + "\n" +
                    ` len(dbResult['result']) ` +
                    " properties retrieved from database")

            print '<HR>'
            print '<TABLE>'
            print '<TR>'
            ecommerce.tableColumn(
                '<INPUT NAME="query" type="button" value=" Query " onClick="return execute('
                + "'query'" + ')">')
            ecommerce.tableColumn(
                '<INPUT TYPE="button" NAME="help" VALUE=" Help " onClick="return goto_url ('
                + "'" + help_pdf + "'" + ')">')
            print '</TR>'
            print '</TABLE>'

    else:
        print '<HR>'
        print '<TABLE>'
        print '<TR>'
        ecommerce.tableColumn(
            '<INPUT NAME="query" type="button" value=" Query " onClick="return execute('
            + "'query'" + ')">')
        ecommerce.tableColumn(
            '<INPUT TYPE="button" NAME="help" VALUE=" Help " onClick="return goto_url ('
            + "'" + help_pdf + "'" + ')">')
        print '</TR>'
        print '</TABLE>'

    ecommerce.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden')
    ecommerce.textbox(None, 'action', '', '10', '10', None, None, 'hidden')
    ecommerce.textbox(None, 'cHidden', customer_id, '10', '10', None, None,
                      'hidden')
    ecommerce.textbox(None, 'uHidden', username, '9', '9', None, None,
                      'hidden')
    ecommerce.textbox(None, 'pHidden', password, '8', '8', None, None,
                      'hidden')

    print "</FORM>"

    try:
        ecommerce.trailer(table_data, db)
        db.close()
    except NameError:
        pass

    print '</TD>'
    print '</TR>'
    print '</TABLE>'
    print '</CENTER>'

    print "</BODY>"
    print "</HTML>"

    if form.has_key("performDbQuery") or performDbQuery == 1:
        return dbResult
    else:
        return {
            'status': 'success',
            'message': 'query successful',
            'result': 0
        }
コード例 #7
0
            declarations.store_info['browser_username'],
            declarations.store_info['browser_password'],
            declarations.store_info['db_name'])

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

        else:
            db = dbResult['result']

            # validate username password and customer id
            dbResult = ecommerce.executeSQL(
                db, "SELECT count(*) FROM customers WHERE id = '" +
                string.strip(form['cHidden'].value) +
                "' AND account_username = '******'uHidden'].value +
                "' AND account_password = '******'pHidden'].value + "'")

            if dbResult['status'] != 'success':

                ecommerce.alertsArea(
                    form,
                    "Could not validate customer information provided\n" +
                    dbResult['message'])

            else:

                result = dbResult['result']

                if result[0]['count'] != 1:
コード例 #8
0
def edit_store_info(performDbQuery=0, onLoad=None, queryFields=None):

    table_data = declarations.define_tables()

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

    ecommerce.javaScript("store_admin", 1)

    ecommerce.title("Store Administration")

    print "</HEAD>"

    ecommerce.bodySetup(onLoad)

    ecommerce.mainHeading('Store Administration')

    ecommerce.subHeading('Store Info')

    ecommerce.formSetup("store_admin", "store_admin",
                        "return submitForm(document.store_admin)",
                        declarations.store_info['db_name'])

    if form.has_key("username"):
        username = form["username"].value
    else:
        if form.has_key("uHidden"):
            username = form["uHidden"].value
        else:
            username = ''

    if form.has_key("password"):
        password = form["password"].value
    else:
        if form.has_key("pHidden"):
            password = form["pHidden"].value
        else:
            password = ''

    ecommerce.usernamePasswordDisplay(username, password)

    if form.has_key("performDbQuery") or performDbQuery == 1:

        dbResult = ecommerce.connectDB(username, password,
                                       declarations.store_info['db_name'])

        # could not connect to db
        if dbResult['status'] != 'success':

            ecommerce.alertsArea(
                form, "Can not connect to database,\n" + dbResult['message'])

            # connected to db

            storeButtons()

        else:
            db = dbResult['result']

            sqlStatement = ecommerce.selectAllColumnsSqlStatement(
                table_data, 'store_info', form["key_id"].value)

            dbResult = ecommerce.executeSQL(db, sqlStatement)

            if dbResult['status'] != 'success':

                ecommerce.alertsArea(
                    form, "Could not retrieve store information\n" +
                    dbResult['message'])

            else:

                result = dbResult['result']

                table_data = ecommerce.dbToTableData(table_data, 'store_info',
                                                     result[0])

                ecommerce.table_data['store_info']['id']['value'] = '1'

                ecommerce.display_form(table_data, 'store_info', 1,
                                       'useValues', 1, db)

                ecommerce.alertsArea(
                    form, "Store Information retrieved successfully")

        storeButtons(button_name='save')

        ecommerce.editHiddenFields(form["uHidden"].value,
                                   form["pHidden"].value)

    else:

        storeButtons(button_name='edit')

        ecommerce.editHiddenFields(username, password, '1')

    print "</FORM>"

    try:
        ecommerce.trailer(table_data, db)
        db.close()
    except NameError:
        pass

    print "</BODY>"
    print "</HTML>"

    if form.has_key("performDbQuery") or performDbQuery == 1:
        return dbResult
    else:
        return {
            'status': 'success',
            'message': 'query successful',
            'result': 0
        }