# Class: MsgareaController

# MessageAreaController

The Message Area controller.

# Public Instance Methods

### menu ()

Show source...

         # File bbs/lib/controllers/messagearea.rb, line 59
     59:   def menu
     60:     done = false
     61:     validkeys=['A','B','I','J','L','N','O','P','S',']','[','X']
     62:     until done == true
     63:
     64:       # Retrieve a list and count of Message Areas - This is done each menu loop in the event soemthing changes
     65:       # by an admin during the user's session. Potentially, a change could cause the controller to crash.
     66:       arealist  = $db[:msgareas].select(:id).order(:id).map(:id)
     67:       areacount =  $db[:msgareas].count
     68:       # Track the user's current area from the session table.
     69:       if $session.msgarea.nil? == true
     70:         curarea = arealist.first
     71:         $session.msgarea = curarea
     72:         $session.save
     73:       else
     74:         curarea = $session.msgarea
     75:       end
     76:       # Set the array iterator index location
     77:       areaindex = arealist.index(curarea)
     78:       # Get area's metadata info
     79:       areameta = $db[:msgareas].where(:id => curarea).first
     80:       # Get a count of total files in this area
     81:       msgcount = $db[:msgs].filter(:msgarea_id => $session.msgarea).count
     82:       # Get network information
     83:       if areameta[:type] == 1 #(network)
     84:         network = Tgtemplate::Template.parse_hash($db[:networks].where(:id => areameta[:network_id]).first)
     85:       else
     86:         network = nil
     87:       end
     88:
     89:
     90:
     91:       # Display menu
     92:       key = Tgio::Input.menuprompt('menu_msgarea.ftl',validkeys, {"areanum" => areameta[:id].to_s,"areaname" => areameta[:name].capitalize, "areadesc" => areameta[:description], "areacount" => msgcount })
     93:       print "\n"
     94:       case key
     95:         when "A" # List all Message Area Names/Descriptions
     96:           areas = Tgtemplate::Template.parse_dataset($db[:msgareas].all)
     97:           Tgtemplate.display('msgarea_list_areas.ftl', {'areas' => areas})
     98:
     99:         when "B" # Message Browser
    100:           MessageController.new.browser(curarea)
    101:
    102:         when "I" # Area Information
    103:           Tgtemplate.display('msgarea_area_meta.ftl', {'area' => Tgtemplate::Template.parse_hash(areameta), 'network' => network})
    104:
    105:
    106:         when "J" # Jump to another area
    107:           Tgtemplate.display('msgarea_jumpto.ftl', nil)
    108:           jumper = Tgio::Input::inputform(4).to_i
    109:           # Validate input for correctness before switching areas
    110:           if arealist.include?(jumper) == true
    111:             $session.msgarea = jumper
    112:             $session.save
    113:           else
    114:             Tgtemplate.display('msgsarea_jumpto_invalid.ftl', nil)
    115:           end
    116:
    117:         when "L" # List messages in current area
    118:           if $session.level >= areameta[:minlevel_read]
    119:             MessageController.new.listall(curarea)
    120:           else
    121:             Tgtemplate.display('msgarea_read_forbidden.ftl', {'areaname'=>areameta[:name].capitalize})
    122:           end
    123:
    124:         when "N" # New Message
    125:           Telegard.unimplemented
    126:
    127:         when "S" # Search for Message
    128:           Telegard.unimplemented
    129:
    130:         when "]" # Next Area
    131:           if areaindex > (areacount - 1)
    132:             $session.msgarea = arealist.first
    133:           else
    134:             $session.msgarea = arealist.at(areaindex + 1)
    135:           end
    136:           $session.save
    137:
    138:         when "[" # Previous Area
    139:           if areaindex <= 0
    140:             $session.msgarea = arealist.last
    141:           else
    142:             $session.msgarea = arealist.at(areaindex - 1)
    143:           end
    144:           $session.save
    145:         when "X"
    146:           return 0
    147:       end #/case
    148:     end #/until
    149:   end