Esempio n. 1
0
 /**
  * Validates the event. Should be run during any form submission or saving operation.
  * @return boolean
  */
 function validate()
 {
     $missing_fields = array();
     foreach ($this->required_fields as $field) {
         $true_field = $this->fields[$field]['name'];
         if ($this->{$true_field} == "") {
             $missing_fields[] = $field;
         }
     }
     if (count($missing_fields) > 0) {
         // TODO Create friendly equivelant names for missing fields notice in validation
         $this->add_error(__('Missing fields: ') . implode(", ", $missing_fields) . ". ");
     }
     if (!empty($_POST['repeated_event']) && $_POST['repeated_event'] == "1" && $this->end_date == "") {
         $this->add_error(__('Since the event is repeated, you must specify an event date.', 'dbem'));
     }
     if (preg_match('/\\d{4}-\\d{2}-\\d{2}/', $this->start_date) && preg_match('/\\d{4}-\\d{2}-\\d{2}/', $this->end_date)) {
         if (strtotime($this->start_date . $this->start_time) > strtotime($this->end_date . $this->end_time)) {
             $this->add_error(__('Events cannot start after they end.', 'dbem'));
         }
     } else {
         $this->add_error(__('Dates must have correct formatting. Please use the date picker provided.', 'dbem'));
     }
     if ($this->get_location()->id == '' && !$this->location->validate()) {
         $this->errors = array_merge($this->errors, $this->location->errors);
     }
     $this->image_validate();
     //TODO validate recurrence during event validate
     $count = count($this->errors);
     return apply_filters('em_event_validate', count($this->errors) == 0, $this);
 }
Esempio n. 2
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();
    }
}
function dbem_validate_location($location)
{
    $EM_Location = new EM_Location($location);
    if ($EM_Location->validate()) {
        return "OK";
    } else {
        return '<strong>' . __('Ach, some problems here:', 'dbem') . '</strong><br /><br />' . "\n" . implode('<br />', $EM_Location->errors);
    }
}