summaryrefslogtreecommitdiff
path: root/admin.c
blob: fec0fcd0daeddbd4f7f5416f45f2c463ecc65d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdlib.h>
#include <stdbool.h>
#include "login.h"
#include "interchange.h"
#include "interchange/member.h"
#include "interchange/ord.h"
#include "interchange/admin.h"

void interchange_admin_login(const char *username, const char *password,
		const char *nextpage, const char *successpage,
		const char *failpage, void (*handler)(interchange_response *),
		void (*callback)(struct interchange_admin *))
{
	login(username, password, NULL, "MMLogin",
			nextpage ? nextpage : "admin/index", successpage,
			failpage, handler, (void (*)(void *))callback);
}

void interchange_admin_new_admin(const char *username, const char *password,
		const char *name, bool super,
		enum interchange_admin_group group,
		void (*handler)(interchange_response *))
{
	request(handler, NULL, (const char *[][2]){
		"mv_todo", "set",
		"mv_data_table", "access",
		"mv_data_key", "username",
		"mv_update_empty", "1",
		"mv_data_fields", "username password name super groups",
		"mv_click", "process_filter",
		"user_id", "NEW",
		"name", name,
		"mv_data_function", "insert",
		"username", username,
		"password", password,
		"super", super ? "1" : "0",
		"groups", group == INTERCHANGE_ADMIN_GROUP_CONTENT ? ":CONTENT"
		: group == INTERCHANGE_ADMIN_GROUP_MERCH ? ":MERCH" : ":ORDERS"
	}, "%s", "ui");
}

void interchange_admin_new_item(const char *description, const char *comment,
		const char *price, const char *image_path,
		void (*handler)(interchange_response *))
{
	request(handler, NULL, (const char *[][2]){
		"mv_click", "process_filter",
		"mv_data_fields",
		"sku description prod_group category comment inactive price "
		"wholesale image thumb image_large weight nontaxable gift_cert",
		"mv_ui", "1",
		"ui_new_item", "1",
		"mv_todo", "set",
		"mv_update_empty", "1",
		"mv_action", "set",
		"mv_data_table", "products",
		"mv_data_function", "insert",
		"mv_data_key", "sku",
		"mv_return_table", "products",
		"sku", image_path,
		"description", description,
		"comment", comment,
		"price", price,
		/*
		"image",
		CURLFORM_FILE, image_path,
		CURLFORM_CONTENTTYPE, "image/jpeg",
		"mv_data_file_field", "image",
		"mv_data_file_path", "images/items"
		*/
		NULL
	}, "%s", "admin/item_edit");
}

void interchange_admin_new_transaction(const struct interchange_ord_order *order,
		const struct interchange_member *member, bool new_customer_id,
		void (*handler)(interchange_response *))
{
	request(handler, NULL, (const char *[][2]){
		"mv_values_space", "order_entry",
		"order_desk_entry", "1",
		"customer_id", member->username,
		"new_customer_id", new_customer_id ? "1" : "0",
		"fname", member->fname,
		"lname", member->lname,
		"address1", member->address1,
		"city", member->city,
		"zip", member->zip,
		"email", member->email,
		"country", member->country,
		"phone_day", member->phone_day,
		NULL
	}, "%s", "process");
}

void interchange_admin_logout()
{
	request(NULL, NULL, NULL, "%s", "admin/login");
}

void interchange_admin_clear(struct interchange_admin *admin)
{
	if (admin->name)
		free(admin->name);
	if (admin->username)
		free(admin->username);
}