function validateYear($data, $fieldName)
{
    global $errorCount;
    if (empty($data)) {
        echo "<p>The field {$fieldName} is required.</p>\n";
        ++$errorCount;
        $retval = "";
    } else {
        $data = trim($data);
        $data = stripslashes($data);
        if (is_numberic($data)) {
            $data = round($data);
            if ($data >= 1900 && $data <= 2100) {
                $retval = $data;
            } else {
                echo "<p>The field {$fieldName} must be between 1900 and 2100.</p>\n";
                ++$errorCount;
                $retval = "";
            }
            //end else statement
        } else {
            echo "<p>The field {$fieldName} must be between 1900 and 2100.</p>\n";
            ++$errorCount;
            $retval = "";
        }
    }
    return retval;
}
Example #2
0
                 $newInheritance = new NagiosServiceTemplateInheritance();
                 $newInheritance->setNagiosServiceTemplateRelatedBySourceTemplate($serviceTemplate);
                 $newInheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template);
                 $newInheritance->setOrder(count($templateList));
                 try {
                     $newInheritance->save();
                     $success = "Template added to inheritance chain.";
                 } catch (Exception $e) {
                     $error = $e->getMessage();
                 }
             }
         }
     }
 } else {
     if ($_POST['request'] == 'service_template_modify_checks') {
         if (isset($modifiedData['max_check_attempts']) && !is_numeric($modifiedData['max_check_attempts']) || isset($modifiedData['max_check_attempts']) && !($modifiedData['max_check_attempts'] >= 1) || isset($modifiedData['normal_check_interval']) && !is_numeric($modifiedData['normal_check_interval']) || isset($modifiedData['normal_check_interval']) && !($modifiedData['normal_check_interval'] >= 1) || isset($modifiedData['retry_interval']) && !is_numeric($modifiedData['retry_interval']) || isset($modifiedData['retry_interval']) && !($modifiedData['retry_interval'] >= 1) || isset($modifiedData['retry_interval']) && !is_numeric($modifiedData['retry_interval']) || isset($modifiedData['first_notification_delay']) && !is_numberic($modifiedData['first_notification_delay']) || isset($modifiedData['freshness_threshold']) && !($modifiedData['freshness_threshold'] >= 0)) {
             $addError = 1;
             $error = "Incorrect values for fields.  Please verify.";
         } else {
             // Let's modify our host template
             if (isset($modifiedData['initial_state'])) {
                 $serviceTemplate->setInitialState($modifiedData['initial_state']);
             } else {
                 $serviceTemplate->setInitialState(null);
             }
             if (isset($modifiedData['is_volatile'])) {
                 $serviceTemplate->setIsVolatile($modifiedData['is_volatile']);
             } else {
                 $serviceTemplate->setIsVolatile(null);
             }
             if (isset($modifiedData['is_volatile'])) {
Example #3
0
 /**
  * Verify field by condition before call api.
  */
 public function verifyField($value, $condition)
 {
     $key = $condition['key'];
     // Check length.
     if (isset($condition['length'])) {
         if (strlen($value) != $condition['length']) {
             return sprintf('Field [%s] value length should be [%s].', $key, $condition['length']);
         }
     } else {
         if (isset($condition['min-length'])) {
             if (strlen($value) < $condition['min-length']) {
                 return sprintf('Field [%s] value length should be more than [%s].', $key, $condition['min-length']);
             }
         }
         if (isset($condition['max-length'])) {
             if (strlen($value) > $condition['max-length']) {
                 return sprintf('Field [%s] value length should not be more than [%s].', $key, $condition['max-length']);
             }
         }
     }
     // Check integer.
     if (isset($condition['integer']) && $condition['integer'] === TRUE) {
         if (!is_numberic($value)) {
             return sprintf('Field [%s] value should be integer.', $key);
         }
     }
     // Check allowed values.
     if (isset($condition['allow'])) {
         if (is_array($condition['allow'])) {
             if (!in_array($value, $condition['allow'])) {
                 return sprintf('Field [%s] value should be one of [%s].', $key, implode(',', $condition['allow']));
             }
         } else {
             if (!preg_match($condition['allow'], $value)) {
                 return sprintf('Field [%s] value should be match regex [%s].', $key, $condition['allow']);
             }
         }
     }
     // Check allowed values.
     if (isset($condition['max'])) {
         $value = (int) $value;
         $max = (int) $condition['max'];
         if ($value > $max) {
             return sprintf('Field [%s] value should be larger than [%s].', $key, $max);
         }
     }
     return TRUE;
 }