function FM_CallFunction($s_func, $a_params, &$m_return, &$s_mesg, &$a_debug, &$a_alerts)
 {
     switch ($s_func) {
         case "FMFatalError":
             SendComputeAlerts();
             if (count($a_params) < 3) {
                 Error("fmcompute_call", GetMessage(MSG_CALL_PARAM_COUNT, array("FUNC" => $s_func, "COUNT" => count($a_params))), false, false);
             } else {
                 Error("fmcompute_error", $a_params[0], $a_params[1], $a_params[2]);
             }
             break;
         case "FMFatalUserError":
             SendComputeAlerts();
             if (count($a_params) < 1) {
                 Error("fmcompute_call", GetMessage(MSG_CALL_PARAM_COUNT, array("FUNC" => $s_func, "COUNT" => count($a_params))), false, false);
             } else {
                 UserError("fmcompute_usererror", $a_params[0]);
             }
             break;
         case "FMUserError":
             if (count($a_params) < 1) {
                 SendComputeAlerts();
                 Error("fmcompute_call", GetMessage(MSG_CALL_PARAM_COUNT, array("FUNC" => $s_func, "COUNT" => count($a_params))), false, false);
             } else {
                 global $FM_UserErrors;
                 $FM_UserErrors[] = $a_params[0];
             }
             break;
         case "FMSaveAllFilesToRepository":
             if (count($a_params) != 0) {
                 SendComputeAlerts();
                 Error("fmcompute_call", GetMessage(MSG_CALL_PARAM_COUNT, array("FUNC" => $s_func, "COUNT" => count($a_params))), false, false);
             } else {
                 $m_return = SaveAllFilesToRepository();
             }
             break;
         case "FMDeleteFileFromRepository":
             if (count($a_params) != 1) {
                 SendComputeAlerts();
                 Error("fmcompute_call", GetMessage(MSG_CALL_PARAM_COUNT, array("FUNC" => $s_func, "COUNT" => count($a_params))), false, false);
             } else {
                 $m_return = DeleteFileFromRepository($a_params[0]);
             }
             break;
         case "FMNextNum":
             if (count($a_params) != 2) {
                 SendComputeAlerts();
                 Error("fmcompute_call", GetMessage(MSG_CALL_PARAM_COUNT, array("FUNC" => $s_func, "COUNT" => count($a_params))), false, false);
             } else {
                 $i_pad = $a_params[0];
                 $i_base = $a_params[1];
                 if ($i_base < 2 || $i_base > 36) {
                     Error("fmcompute_call", GetMessage(MSG_CALL_INVALID_PARAM, array("FUNC" => $s_func, "PARAM" => 2, "CORRECT" => 2.0 . 0.36)), false, false);
                 }
                 $m_return = GetNextNum($i_pad, $i_base);
             }
             break;
         default:
             $s_mesg = GetMessage(MSG_CALL_UNK_FUNC, array("FUNC" => $s_func));
             return false;
     }
     return true;
 }
Exemple #2
0
function ValueSpec($s_spec, $a_form_data, &$a_errors)
{
    global $lNow;
    $s_value = "";
    switch (trim($s_spec)) {
        case 'date':
            // "standard" date format: DD-MMM-YYYY
            $s_value = date('d-M-Y', $lNow);
            break;
        case 'time':
            // "standard" time format: HH:MM:SS
            $s_value = date('H:i:s', $lNow);
            break;
        case 'ampm':
            // am or pm
            $s_value = date('a', $lNow);
            break;
        case 'AMPM':
            // AM or PM
            $s_value = date('A', $lNow);
            break;
        case 'dom0':
            // day of month with possible leading zero
            $s_value = date('d', $lNow);
            break;
        case 'dom':
            // day of month with no leading zero
            $s_value = date('j', $lNow);
            break;
        case 'day':
            // day name (abbreviated)
            $s_value = date('D', $lNow);
            break;
        case 'dayname':
            // day name (full)
            $s_value = date('l', $lNow);
            break;
        case 'daysuffix':
            // day number suffix for English (st for 1st, nd for 2nd, etc.)
            $s_value = date('S', $lNow);
            break;
        case 'moy0':
            // month of year with possible leading zero
            $s_value = date('m', $lNow);
            break;
        case 'moy':
            // month of year with no leading zero
            $s_value = date('n', $lNow);
            break;
        case 'month':
            // month name (abbreviated)
            $s_value = date('M', $lNow);
            break;
        case 'monthname':
            // month name (full)
            $s_value = date('F', $lNow);
            break;
        case 'year':
            // year (two digits)
            $s_value = date('y', $lNow);
            break;
        case 'fullyear':
            // year (full)
            $s_value = date('Y', $lNow);
            break;
        case 'rfcdate':
            // date formatted according to RFC 822
            $s_value = date('r', $lNow);
            break;
        case 'tzname':
            // timezone name
            $s_value = date('T', $lNow);
            break;
        case 'tz':
            // timezone difference from Greenwich +NNNN or -NNNN
            $s_value = date('O', $lNow);
            break;
        case 'hour120':
            // hour of day (01-12) with possible leading zero
            $s_value = date('h', $lNow);
            break;
        case 'hour240':
            // hour of day (00-23) with possible leading zero
            $s_value = date('H', $lNow);
            break;
        case 'hour12':
            // hour of day (1-12) with no leading zero
            $s_value = date('g', $lNow);
            break;
        case 'hour24':
            // hour of day (0-23) with no leading zero
            $s_value = date('G', $lNow);
            break;
        case 'min':
            // minute of hour (00-59)
            $s_value = date('i', $lNow);
            break;
        case 'sec':
            // seconds of minute (00-59)
            $s_value = date('s', $lNow);
            break;
        default:
            if ($s_spec[0] == "'") {
                //
                // to get a quote, use 3 quotes:
                //      '''
                //
                if ($s_spec == "'''") {
                    $s_value = "'";
                } elseif (substr($s_spec, -1, 1) == "'") {
                    $s_value = substr($s_spec, 1, -1);
                } else {
                    //
                    // missing final quote is OK
                    //
                    $s_value = substr($s_spec, 1);
                }
            } elseif (strspn($s_spec, "0123456789ABCDEF") == 2) {
                //
                // insert the ASCII character corresponding to
                // the hexadecimal value
                //
                $i_val = intval(substr($s_spec, 0, 2), 16);
                $s_value = chr($i_val);
            } else {
                //
                // look for supported functions, start by getting all
                // the tokens
                //
                $a_toks = GetTokens($s_spec);
                if (count($a_toks) > 0) {
                    switch ($a_toks[0]) {
                        case "if":
                            //
                            // "if" function: test first field
                            //       if not empty, then use second field
                            //       else, use third field
                            //
                            // Example: if(fld1 ; fld2 ; fld3)
                            //
                            // tokens are:
                            //      1               (
                            //      2               the field name to test (first)
                            //      3               ;
                            //      4               the "then" spec (can be missing)
                            //      5               ;
                            //      6               the "else" spec (can be missing)
                            //      7               )
                            //
                            if (($n_tok = count($a_toks)) < 6 || $a_toks[1] != "(" || $a_toks[3] != ";" || $a_toks[$n_tok - 1] != ")") {
                                SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_IF_FMT))));
                            } else {
                                $b_ok = true;
                                $s_fld_name = $a_toks[2];
                                $s_then_spec = $s_else_spec = "";
                                for ($ii = 4; $ii < $n_tok && $a_toks[$ii] != ';'; $ii++) {
                                    $s_then_spec .= $a_toks[$ii];
                                }
                                if ($ii == $n_tok) {
                                    $b_ok = false;
                                } else {
                                    //
                                    // Concatenate tokens until the ')'.
                                    // This provides the "else" spec.
                                    //
                                    for (; ++$ii < $n_tok && $a_toks[$ii] != ')';) {
                                        $s_else_spec .= $a_toks[$ii];
                                    }
                                    if ($ii == $n_tok) {
                                        $b_ok = false;
                                    }
                                }
                                if ($b_ok) {
                                    if (!TestFieldEmpty($s_fld_name, $a_form_data, $s_mesg)) {
                                        $s_fld_spec = $s_then_spec;
                                    } else {
                                        $s_fld_spec = $s_else_spec;
                                    }
                                    $s_value = GetDerivedValue($a_form_data, $s_fld_spec);
                                } else {
                                    SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_IF_FMT))));
                                }
                            }
                            break;
                        case "size":
                            //
                            // "size" function: return size of uploaded file
                            //
                            // Example: size(fieldname)
                            //
                            // tokens are:
                            //      1               (
                            //      2               the field name for the file upload
                            //      3               )
                            //
                            if (count($a_toks) != 4 || $a_toks[1] != "(" || $a_toks[3] != ")") {
                                SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_SIZE_FMT))));
                            } elseif (($i_size = GetFileSize($a_toks[2])) !== false) {
                                $s_value = "{$i_size}";
                            }
                            break;
                        case "ext":
                            //
                            // "ext" function: return filename extension of uploaded file
                            //
                            // Example: ext(fieldname)
                            //
                            // tokens are:
                            //      1               (
                            //      2               the field name for the file upload
                            //      3               )
                            //
                            if (count($a_toks) != 4 || $a_toks[1] != "(" || $a_toks[3] != ")") {
                                SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_EXT_FMT))));
                            } elseif (($s_name = GetFileName($a_toks[2])) !== false) {
                                if (($i_pos = strrpos($s_name, ".")) !== false) {
                                    $s_value = substr($s_name, $i_pos + 1);
                                }
                            }
                            break;
                        case "ucase":
                        case "lcase":
                            //
                            // "ucase" and "lcase" functions: return field
                            // converted to upper or lower case
                            //
                            // Example: lcase(fieldname)
                            //
                            // tokens are:
                            //      1               (
                            //      2               the field name to convert
                            //      3               )
                            //
                            if (count($a_toks) != 4 || $a_toks[1] != "(" || $a_toks[3] != ")") {
                                SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC1_FMT, array("FUNC" => $a_toks[0])))));
                            } elseif ($a_toks[0] == "ucase") {
                                $s_value = strtoupper(GetFieldValue($a_toks[2], $a_form_data));
                            } else {
                                $s_value = strtolower(GetFieldValue($a_toks[2], $a_form_data));
                            }
                            break;
                        case "ltrim":
                        case "rtrim":
                        case "trim":
                            //
                            // trim functions: return field with whitespace removed
                            // from left (ltrim), right (rtrim), or both (trim)
                            // ends.
                            //
                            // Example: ltrim(fieldname)
                            //
                            // tokens are:
                            //      1               (
                            //      2               the field name to trim
                            //      3               )
                            //
                            if (count($a_toks) != 4 || $a_toks[1] != "(" || $a_toks[3] != ")") {
                                SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC1_FMT, array("FUNC" => $a_toks[0])))));
                            } else {
                                $s_value = $a_toks[0](GetFieldValue($a_toks[2], $a_form_data));
                            }
                            break;
                        case "ltrim0":
                            //
                            // ltrim0 function: return field with blanks and
                            // leading 0's removed from the left.
                            //
                            // Example: ltrim0(fieldname)
                            //
                            // tokens are:
                            //      1               (
                            //      2               the field name to trim
                            //      3               )
                            //
                            if (count($a_toks) != 4 || $a_toks[1] != "(" || $a_toks[3] != ")") {
                                SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC1_FMT, array("FUNC" => $a_toks[0])))));
                            } else {
                                $s_value = GetFieldValue($a_toks[2], $a_form_data);
                                $s_value = ltrim($s_value);
                                // trim blanks on left
                                $i_len = strspn($s_value, "0");
                                //
                                // if the whole string is zeroes, make sure we leave
                                // one of them!
                                //
                                if ($i_len == strlen($s_value)) {
                                    if (--$i_len < 0) {
                                        $i_len = 0;
                                    }
                                }
                                $s_value = substr($s_value, $i_len);
                            }
                            break;
                        case "nextnum":
                            //
                            // "nextnum" function: return a unique number (next number)
                            //
                            // Usage: nextnum[(pad[,base])]
                            //
                            // Examples:
                            //      %nextnum%
                            //      %nextnum(8)%
                            //      %nextnum(5;16)%
                            //
                            // You can provide a padding amount. In this case, the
                            // number is padded on the left with zeroes to the number
                            // of digits specified.
                            //
                            // You can also provide a base for your numbers.  Valid
                            // values for base are 2 to 36, inclusive.
                            //
                            // tokens are:
                            //      1               (
                            //      2               the padding amount
                            //      3               ;
                            //      4               the base
                            //      5               )
                            //
                            $i_pad = 0;
                            // no padding
                            $i_base = 10;
                            // base 10
                            if (($n_tok = count($a_toks)) > 1) {
                                if ($n_tok != 4 && $n_tok != 6 || $a_toks[1] != "(" || $a_toks[$n_tok - 1] != ")") {
                                    SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_NEXTNUM_FMT) . " (T1)")));
                                }
                                if ($n_tok == 6 && $a_toks[3] != ";") {
                                    SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_NEXTNUM_FMT) . " (T2)")));
                                }
                                if (!is_numeric($a_toks[2]) || $n_tok == 6 && !is_numeric($a_toks[4])) {
                                    SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_NEXTNUM_FMT) . " (T3)")));
                                }
                                $i_pad = intval($a_toks[2]);
                                if ($n_tok == 6) {
                                    $i_base = intval($a_toks[4]);
                                    if ($i_base < 2 || $i_base > 36) {
                                        SendAlert(GetMessage(MSG_DER_FUNC_ERROR, array("SPEC" => $s_spec, "MSG" => GetMessage(MSG_DER_FUNC_NEXTNUM_FMT) . " (T4)")));
                                        $i_base = 10;
                                    }
                                }
                                $s_value = GetNextNum($i_pad, $i_base);
                            } else {
                                $s_value = GetNextNum($i_pad, $i_base);
                            }
                            break;
                        default:
                            SendAlert(GetMessage(MSG_UNK_VALUE_SPEC, array("SPEC" => $s_spec, "MSG" => "")));
                            break;
                    }
                } else {
                    SendAlert(GetMessage(MSG_UNK_VALUE_SPEC, array("SPEC" => $s_spec, "MSG" => "")));
                }
            }
            break;
    }
    return $s_value;
}