liquid_feedback_frontend
view app/main/admin/_action/member_update.lua @ 1012:6c087fa4ba35
Fixed typo in admin cancel issue
| author | bsw | 
|---|---|
| date | Sun Aug 11 22:07:13 2013 +0200 (2013-08-11) | 
| parents | cb5bac9da089 | 
| children | e17e35dc8aa6 | 
 line source
     1 local id = param.get_id()
     3 local member = Member:by_id(id) or Member:new()
     5 param.update(member, "identification", "notify_email", "admin")
     7 local locked = param.get("locked", atom.boolean)
     8 if locked ~= nil then
     9   member.locked = locked
    10 end
    11 local deactivate = param.get("deactivate", atom.boolean)
    12 if deactivate then
    13   member.active = false
    14 end
    15 local login = param.get("login")
    16 if login then
    17   member.login = login
    18 end
    19 local name = param.get("name")
    20 if name then
    21   member.name = name
    22 end
    23 local identification = param.get("identification")
    24 if identification then
    25   identification = util.trim(identification)
    26   if identification == "" then
    27     identification = nil
    28   end
    29 end
    30 member.identification = identification
    32 local err = member:try_save()
    34 if err then
    35   slot.put_into("error", (_("Error while updating member, database reported:<br /><br /> (#{errormessage})"):gsub("#{errormessage}", tostring(err.message))))
    36   return false
    37 end
    39 if not id and config.single_unit_id then
    40   local privilege = Privilege:new()
    41   privilege.member_id = member.id
    42   privilege.unit_id = config.single_unit_id
    43   privilege.voting_right = true
    44   privilege:save()
    45 end
    47 local units = Unit:new_selector()
    48   :add_field("privilege.member_id NOTNULL", "privilege_exists")
    49   :add_field("privilege.voting_right", "voting_right")
    50   :left_join("privilege", nil, { "privilege.member_id = ? AND privilege.unit_id = unit.id", member.id })
    51   :exec()
    53 for i, unit in ipairs(units) do
    54   local value = param.get("unit_" .. unit.id, atom.boolean)
    55   if value and not unit.privilege_exists then
    56     privilege = Privilege:new()
    57     privilege.unit_id = unit.id
    58     privilege.member_id = member.id
    59     privilege.voting_right = true
    60     privilege:save()
    61   elseif not value and unit.privilege_exists then
    62     local privilege = Privilege:by_pk(unit.id, member.id)
    63     privilege:destroy()
    64   end
    65 end
    67 if not member.activated and param.get("invite_member", atom.boolean) then
    68   member:send_invitation()
    69 end
    71 if id then
    72   slot.put_into("notice", _"Member successfully updated")
    73 else
    74   slot.put_into("notice", _"Member successfully registered")
    75 end
