Example #1
0
 public function testValidDate()
 {
     $this->assertTrue(shn_vm_valid_date('1986-12-21'));
     $this->assertTrue(shn_vm_valid_date('1954-10-10'));
     $this->assertTrue(shn_vm_valid_date('2004-02-29'));
     $this->assertTrue(shn_vm_valid_date('1982-02-28'));
     $this->assertFalse(shn_vm_valid_date('1982-02-29'));
     // not a leap year
     $this->assertFalse(shn_vm_valid_date('1982-52-20'));
     // month out of range
     $this->assertFalse(shn_vm_valid_date('1982-10-40'));
     // day out of range
     $this->assertFalse(shn_vm_valid_date(''));
     $this->assertFalse(shn_vm_valid_date('garbage'));
 }
Example #2
0
 /**
  * Validates the fields in the search form
  *
  * @return true if the form is valid, false otherwise
  */
 function validateSearchForm($getvars)
 {
     //print_r($_REQUEST);
     $validated = true;
     //validate that at least one field is specified if we are not assigning to a project
     if (!$getvars['assigning']) {
         if (!shn_vm_not_empty($getvars['vol_iden']) && !shn_vm_not_empty($getvars['vol_name']) && !shn_vm_skill_selected($getvars) && !shn_vm_not_empty($getvars['start_date']) && !shn_vm_not_empty($getvars['end_date']) && !shn_vm_location_selected() && $getvars['unassigned'] != 'true') {
             add_error(SHN_ERR_VM_SEARCH_NO_PARAMS);
             $validated = false;
         } else {
             if (strlen($getvars['vol_iden']) <= 3 && !shn_vm_not_empty($getvars['vol_name']) && !shn_vm_skill_selected($getvars) && !shn_vm_not_empty($getvars['start_date']) && !shn_vm_not_empty($getvars['end_date']) && !shn_vm_location_selected() && $getvars['unassigned'] != 'true') {
                 add_error(SHN_ERR_VM_SEARCH_BAD_ID);
                 $validated = false;
             }
         }
     }
     if ($getvars['date_constraint'] == 'full_date' && (!shn_vm_not_empty($getvars['start_date']) || !shn_vm_not_empty($getvars['end_date']))) {
         add_error(SHN_ERR_VM_BAD_DATE_RANGE);
         $validated = false;
     } else {
         if (!shn_vm_not_empty($getvars['start_date']) && shn_vm_not_empty($getvars['end_date'])) {
             add_error(SHN_ERR_VM_NO_START_DATE);
             $validated = false;
         }
     }
     $valid_start = null;
     $valid_end = null;
     if ($getvars['start_date'] != '') {
         if (!shn_vm_valid_date($getvars['start_date'])) {
             add_error(SHN_ERR_VM_BAD_PROJECT_DATES);
             $validated = false;
             $valid_start = false;
         } else {
             $valid_start = true;
         }
     }
     if ($getvars['end_date'] != '') {
         if (!shn_vm_valid_date($getvars['end_date'])) {
             if ($valid_start !== false) {
                 add_error(SHN_ERR_VM_BAD_PROJECT_DATES);
             }
             $valid_end = false;
             $validated = false;
         } else {
             $valid_end = true;
         }
     }
     if ($valid_start && $valid_end) {
         $validated = $validated && shn_vm_compatible_dates($getvars['start_date'], $getvars['end_date'], SHN_ERR_VM_DATES_INCOMPATIBLE);
     }
     return $validated;
 }
Example #3
0
 /**
  * Validates that the required fields are filled in and correct
  *
  * @access public
  * @return true if the form is valid, and false otherwise;
  */
 function validateAddForm($getvars)
 {
     //include the validation library
     global $global;
     require_once $global['approot'] . 'inc/lib_validate.inc';
     require_once $global['approot'] . 'mod/vm/lib/vm_validate.inc';
     //assume the form is valid
     $validated = true;
     //validate that there is a name entered
     $validated = $validated && shn_vm_not_empty($getvars['name'], SHN_ERR_VM_NO_NAME);
     //validate that a site manager has been selected only if we're adding
     if (!isset($getvars['proj_id'])) {
         $validated = $validated && shn_vm_not_empty($getvars['manager'], SHN_ERR_VM_NO_MGR);
     }
     //validate that the dates if specified are in the correct format and if both specified the start date is before the end date;
     $valid_start = null;
     $valid_end = null;
     if ($getvars['start_date'] != '') {
         if (!shn_vm_valid_date($getvars['start_date'])) {
             add_error(SHN_ERR_VM_BAD_PROJECT_DATES);
             $validated = false;
             $valid_start = false;
         } else {
             $valid_start = true;
         }
     }
     if ($getvars['end_date'] != '') {
         if (!shn_vm_valid_date($getvars['end_date'])) {
             if ($valid_start !== false) {
                 add_error(SHN_ERR_VM_BAD_PROJECT_DATES);
             }
             $valid_end = false;
             $validated = false;
         } else {
             $valid_end = true;
         }
     }
     if ($valid_start && $valid_end) {
         $validated = $validated && shn_vm_compatible_dates($getvars['start_date'], $getvars['end_date'], SHN_ERR_VM_DATES_INCOMPATIBLE);
     }
     return $validated;
 }