Example #1
0
/**
 * Looks at the request values, saves/updates and then displays the right menu in the admin
 * @return null
 */
function em_admin_locations_page()
{
    //TODO EM_Location is globalized, use it fully here
    global $EM_Location;
    //Take actions
    if (!empty($_REQUEST['action']) || !empty($_REQUEST['location_id'])) {
        if ($_REQUEST['action'] == "edit" || $_REQUEST['action'] == "add") {
            //edit/add location
            em_admin_location();
        } elseif ($_REQUEST['action'] == "delete") {
            //delelte location
            $locations = $_REQUEST['locations'];
            foreach ($locations as $location_id) {
                $EM_Location = new EM_Location($location_id);
                $EM_Location->delete();
            }
            em_admin_locations(__('Locations Deleted', "dbem"));
        } elseif ($_REQUEST['action'] == "save") {
            // save (add/update) location
            if (empty($EM_Location) || !is_object($EM_Location)) {
                $EM_Location = new EM_Location();
                //blank location
                $success_message = __('The location has been added.', 'dbem');
            } else {
                $success_message = __('The location has been updated.', 'dbem');
            }
            $EM_Location->get_post();
            $validation_result = $EM_Location->validate();
            if ($validation_result) {
                $EM_Location->save();
                //FIXME better handling of db write fails when saving location
                em_admin_locations($success_message);
            } else {
                ?>
				<div id='message' class='error '>
					<p>
						<strong><?php 
                _e("Ach, there's a problem here:", "dbem");
                ?>
</strong><br /><br /><?php 
                echo implode('<br />', $EM_Location->errors);
                ?>
					</p>
				</div>
				<?php 
                unset($EM_Location);
                em_admin_location();
            }
        }
    } else {
        // no action, just a locations list
        em_admin_locations();
    }
}
Example #2
0
/**
 * Looks at the request values, saves/updates and then displays the right menu in the admin
 * @return null
 */
function em_admin_ms_locations()
{
    //TODO EM_Location is globalized, use it fully here
    global $EM_Location;
    //Take actions
    if (!empty($_REQUEST['action']) && ($_REQUEST['action'] == "edit" || $_REQUEST['action'] == "location_save")) {
        em_admin_location();
    } else {
        // no action, just a locations list
        em_admin_locations();
    }
}