rev |
line source |
bsw/jbe@4
|
1 local member_id = app.session.member_id
|
bsw/jbe@4
|
2
|
bsw/jbe@4
|
3 local deleted = 0
|
bsw/jbe@4
|
4 local updated = 0
|
bsw/jbe@4
|
5
|
bsw/jbe@4
|
6 for i, image_type in ipairs{"avatar", "photo"} do
|
bsw/jbe@4
|
7
|
bsw/jbe@4
|
8 local member_image = MemberImage:by_pk(member_id, image_type, false)
|
bsw/jbe@4
|
9 local member_image_scaled = MemberImage:by_pk(member_id, image_type, true)
|
bsw/jbe@4
|
10
|
bsw/jbe@4
|
11 if param.get(image_type .. "_delete", atom.boolean) then
|
bsw/jbe@4
|
12 if member_image then
|
bsw/jbe@4
|
13 member_image:destroy()
|
bsw/jbe@4
|
14 end
|
bsw/jbe@4
|
15 if member_image_scaled then
|
bsw/jbe@4
|
16 member_image_scaled:destroy()
|
bsw/jbe@4
|
17 end
|
bsw/jbe@4
|
18 deleted = deleted + 1
|
bsw/jbe@4
|
19 else
|
bsw/jbe@4
|
20
|
bsw/jbe@4
|
21 local data = param.get(image_type)
|
bsw/jbe@4
|
22 if data and #data > 0 and #data < 1024*1024 then
|
bsw/jbe@4
|
23 local convert_func = config.member_image_convert_func[image_type]
|
bsw/jbe@4
|
24 local data_scaled, err, status = convert_func(data)
|
bsw/jbe@4
|
25 if status ~= 0 or data_scaled == nil then
|
bsw@75
|
26 slot.put_into("error", _"Error while converting image. Please note, that only JPG files are supported!")
|
bsw@75
|
27 return false
|
bsw/jbe@4
|
28 end
|
bsw/jbe@4
|
29
|
bsw/jbe@4
|
30 if not member_image then
|
bsw@1176
|
31 local meta = request.get_param{ name = image_type, meta = true }
|
bsw/jbe@4
|
32 member_image = MemberImage:new()
|
bsw/jbe@4
|
33 member_image.member_id = member_id
|
bsw/jbe@4
|
34 member_image.image_type = image_type
|
bsw/jbe@4
|
35 member_image.scaled = false
|
bsw@1176
|
36 member_image.content_type = meta.content_type
|
bsw/jbe@4
|
37 member_image.data = ""
|
bsw/jbe@4
|
38 member_image:save()
|
bsw/jbe@4
|
39 end
|
bsw/jbe@4
|
40
|
bsw/jbe@4
|
41 if not member_image_scaled then
|
bsw/jbe@4
|
42 member_image_scaled = MemberImage:new()
|
bsw/jbe@4
|
43 member_image_scaled.member_id = member_id
|
bsw/jbe@4
|
44 member_image_scaled.image_type = image_type
|
bsw/jbe@4
|
45 member_image_scaled.scaled = true
|
bsw/jbe@52
|
46 member_image_scaled.content_type = config.member_image_content_type
|
bsw/jbe@4
|
47 member_image_scaled.data = ""
|
bsw/jbe@4
|
48 member_image_scaled:save()
|
bsw/jbe@4
|
49 end
|
bsw/jbe@4
|
50
|
bsw/jbe@4
|
51 if data and #data > 0 then
|
bsw/jbe@4
|
52 db:query{ "UPDATE member_image SET data = $ WHERE member_id = ? AND image_type='" .. image_type .. "' AND scaled=FALSE", { db:quote_binary(data) }, app.session.member.id }
|
bsw/jbe@4
|
53 end
|
bsw/jbe@4
|
54
|
bsw/jbe@4
|
55 if data_scaled and #data_scaled > 0 then
|
bsw/jbe@4
|
56 db:query{ "UPDATE member_image SET data = $ WHERE member_id = ? AND image_type='" .. image_type .. "' AND scaled=TRUE", { db:quote_binary(data_scaled) }, app.session.member.id }
|
bsw/jbe@4
|
57 end
|
bsw/jbe@4
|
58
|
bsw/jbe@4
|
59 updated = updated + 1
|
bsw/jbe@4
|
60 end
|
bsw/jbe@4
|
61 end
|
bsw/jbe@4
|
62 end
|
bsw/jbe@4
|
63
|
bsw/jbe@4
|
64 if updated > 0 then
|
bsw/jbe@4
|
65 slot.put_into("notice", _("#{number} Image(s) has been updated", { number = updated }))
|
bsw/jbe@4
|
66 end
|
bsw/jbe@4
|
67 if updated > 0 and deleted > 0 then
|
bsw/jbe@4
|
68 slot.put_into("notice", " · ")
|
bsw/jbe@4
|
69 end
|
bsw/jbe@4
|
70 if deleted > 0 then
|
bsw/jbe@4
|
71 slot.put_into("notice", _("#{number} Image(s) has been deleted", { number = deleted }))
|
bsw/jbe@4
|
72 end
|
bsw/jbe@4
|
73
|
bsw/jbe@4
|
74 if updated == 0 and deleted == 0 then
|
bsw/jbe@4
|
75 slot.put_into("warning", _("No changes to your images were made"))
|
bsw/jbe@4
|
76 end |