Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 public function testLocationSelected()
 {
     //valid
     $_POST["levels"] = 3;
     $_POST["1"] = "country";
     $this->assertTrue(shn_vm_location_selected());
     $_POST = array();
     $_POST["levels"] = 3;
     $_POST["3"] = "";
     $this->assertTrue(shn_vm_location_selected());
     //invalid
     $_POST = array();
     $_POST["levels"] = 0;
     $_POST["1"] = "country";
     $this->assertFalse(shn_vm_location_selected());
     $_POST = array();
     $_POST["levels"] = 3;
     $_POST["5"] = "country";
     $this->assertFalse(shn_vm_location_selected());
 }