Miva Merchant: E-commerce Solutions to Grow Online

866.284.9812

MivaScript Guide

MivaScript version: 4.0x
Guide Revision 1.0

This document and the software described by this document are copyright 2002 by Miva Merchant Corporation. All rights reserved. Use of the software described herein may only be done in accordance with the License Agreement provided with the software. This document may not be reproduced in full or partial form except for the purpose of using the software described herein in accordance with the License Agreement provided with the software. Information in this document is subject to change without notice. Companies, names and data used in the examples herein are fictitious unless otherwise noted.

Miva Merchant is s registered trademark of Miva Merchant Corporation. MivaScript, MivaScript Compiler, Miva Merchant Order, Miva Merchant, Miva Merchant Mia, Miva Merchant Empresa, the Miva Merchant "blades" logo, Miva Merchant Engine, and Miva Merchant Virtual Machine, are trademarks of Miva Merchant Corporation. Windows is the registered trademark of Microsoft Corporation. All other trademarks are the property of their respective owners. This document was developed and produced in San Diego, CA, USA.

MIVA MERCHANT CORPORATION WILL NOT BE LIABLE FOR (A) ANY BUG, ERROR, OMISSION, DEFECT, DEFICIENCY, OR NONCONFORMITY IN MERCHANT OR THIS DOCUMENTATION; (B) IMPLIED MERCHANTIBILITY OF FITNESS FOR A PARTICULAR PURPOSE; (C) IMPLIED WARRANTY RELATING TO COURSE OF DEALING, OR USAGE OF TRADE OR ANY OTHER IMPLIED WARRANTY WHATSOEVER; (D) CLAIM OF INFRINGEMENT; (E) CLAIM IN TORT, WHETHER OR NOT ARISING IN WHOLE OR PART FROM MIVA CORPORATION'S FAULT, NEGLIGENCE, STRICT LIABILITY, OR PRODUCT LIABILITY, OR (F) CLAIM FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, OR LOSS OF DATA, REVENUE, LICENSEES GOODWILL, OR USE. IN NO CASE SHALL MIVA MERCHANT CORPORATION'S LIABILITY EXCEED THE PRICE THAT LICENSEE PAID FOR MERCHANT.

MS1005-01 (Rev. 1.0) MivaScript 4.0x

Table of Contents

MivaScript Guide

MivaScript Tags List

Introduction
Expressions
Operators
Variables
Built-In System Variables
Functions
Built-in Functions
Assignment and Evaluation Tags
Configuration and Function Tags
Localization Tags
Database Tags
Email Tags
External File Tags
Flow Control Tags
HTTP and Commerce Server Tags

MivaScript Tags List

<MIVA>

<MvADD>

<MvASSIGN>

<MvASSIGNARRAY>

<MvCALL>

<MvCALLSTOP>

<MvCLOSE>

<MvCLOSEVIEW>

<MvCOMMERCE>

<MvCOMMERCESTOP>

<MvCREATE>

<MvDELETE>

<MvDIMENSION>

<MvDO>

<MvELSE>

<MvELSEIF>

<MvEVAL>

<MvEXIT>

<MvEXPORT>

<MvFILTER>

<MvFIND>

<MvFUNCTION>

<MvGO>

<MvHIDE>

<MvIF>

<MvIMPORT>

<MvIMPORTSTOP>

<MvLOCALIZED>

<MvLOCALIZED-TEXT>

<MvLOCALIZED-TOKEN>

<MvLOCKFILE>

<MvMAKEINDEX>

<MvMEMBER>

<MvOPEN>

<MvOPENVIEW>

<MvPACK>

<MvPOP>

<MvPOPDELETE>

<MvPOPSTOP>

<MvPRIMARY>

<MvQUERY>

<MvREINDEX>

<MvREVEALSTRUCTURE>

<MvSETINDEX>

<MvSKIP>

<MvSMTP>

<MvUNDELETE>

<MvUPDATE>

<MvWHILE>

<MvWHILESTOP>

Introduction

MivaScript programs are HTML documents that also contain tags (commands) from the MivaScript programming language. MivaScript is a server-side scripting language that is implemented by the Miva Merchant Virtual Machine, rather than by the browser. By contrast, a client-side language, such as JavaScript, is implemented by the browser. MivaScript programs are called scripts, active documents, or simply documents. MivaScript tags correspond to typical programming language constructs such as assignment statements, conditional expressions, loops, and input/output statements, as well as MivaScript's special database, mail, commerce, configuration, and external database functionality.

MivaScript tags are XML-based: they have the same format as HTML tags; the element names (for example, <MvASSIGN>) indicate their function; and the attributes specify values that the tags operate on. MivaScript tags can be freely mixed with HTML tags.

MivaScript programs are compiled by the MivaScript Compiler, then run under the Miva Merchant Virtual Machine. (Either the Windows desktop version, Miva Merchant Mia, or the server version, Miva Merchant Empresa.)

When a browser requests a MivaScript document (.mvc), the Miva Merchant Virtual Machine executes the contents of the document before passing it on to the browser.

About This Guide

This MivaScript Guide contains the names and syntax for tags, variables, expressions, literals, operators, arrays and structures, functions, and system variables, with only brief descriptions, if any. For detailed information, examples, full descriptions, and explanations, see the MivaScript Reference Guide or the MivaScript User's Guide at http://www.miva.com/support/docs/api.

Expressions

Expressions can contain variables, literal values (text or numbers), functions, and operators, which indicate how the other components in the expression are to be evaluated.

In general, MivaScript expressions are used to:

  • create a new value. (See "<MvASSIGN>".)
  • evaluate an expression's logical "truthfulness."
    For example, an expression can evaluate a condition, and take an action based on the results. See "Flow Control Tags."
    • Any expression that is equal to 0 (zero) or a null string is considered false.
    • All others are considered true. True is often represented by 1 (one).

Expression Syntax

Expressions are enclosed within double quotes, and when it is an attribute value, curly brackets must immediately precede and follow the quotes.

<MvASSIGN NAME="field" VALUE="{field + 10}">
Spaces

Inside an expression, spaces are not significant (that is, they do not affect how the expression is evaluated) except in the following ways:

  • If an operator contains characters that can also occur in a variable name, then it must be separated from the other components by one or more spaces.
  • Spaces inside literal strings are significant.
Literal

An expression consisting of only a literal string does not require curly brackets. If a literal string is inside curly brackets, it must be surrounded by single quotes. For example:

<MvASSIGN NAME="boss" VALUE="{'Fred ' $ 'Flintstone')">
Null

You should represent a null string in an expression as two single quotes (' '):

<MvIF EXPR="{entry EQ ''}">

The expression {0 EQ ' '} ("does zero equal the null string?") returns 1 (true).

Note: To enter a double quote within an expression, use the asciichar() function. (See "Other String Functions.")

See the MivaScript Reference Guide for detailed descriptions and examples of expressions containing literal text, numbers, variables, functions, and operators.

Operators

Order of Precedence

You can also override the built-in precedence by surrounding sub-expressions with parentheses, '(' and ')'.

  1. Sub-expressions inside parentheses, '(' and ')', are evaluated first.
  2. Each operator is assigned a precedence, and if there is a choice of which operator to evaluate first, the operator with higher precedence is evaluated.
  3. If two operators have the same precedence, the left most one is evaluated first.
Operator Precedence

From highest to lowest MivaScript Operators:

  • NOT
  • ROUND, CRYPT, MOD, SUBSTR, POW
  • /, *
  • +,-,$
  • IN, CIN, EIN, ECIN, EQ, NE, GE, LE, LT, GT
  • AND, OR

Arithmetical Operators

A minus sign can precede a literal number to make it negative (for example, -3.14), but, otherwise, must be used strictly as a binary operator: {-x} evaluates to the literal string
'-x'; to express the negative of a value, use {-1*x} or {0-x}. Using +, /, or * as a unary operator results in an expression error.
Operator
Name
Description
+
Addition
expr1 + expr2
-
Subtraction
expr1 - expr2
*
Multiplication
expr1 * expr2
/
Division
expr1 / expr2
POW

POWer
expr1 POW expr2
Raise expr1 to the power expr2
Example: 3 POW 4 is 34, or 81. See also the built-in function power().
MOD

MODulu
expr1 MOD expr2
Returns the integer remainder from expr1/expr2
Example: 26 MOD 7 is 5. See also the built-in function fmod(), which returns floating point remainders.
ROUND
Number
rounding

number ROUND places
Rounds number up or down to places decimal places.
Example: 123.45676 ROUND 2 is 123.46 See also the built-in function.

Comparison Operators

These operators are used to compare two numbers or two text strings. In text string comparisons, lowercase letters are considered to be greater than uppercase letters. Two strings are equal only if the case (upper or lower) matches letter-by-letter. These operators all give a value of 1 (true) or 0 (false).
Operator
Name
Description
GT
Greater Than
expr_a GT expr_b
Tests whether expr_a is greater than expr_b
LT
Less Than
expr_a LT expr_b
Tests whether expr_a is less than expr_b
EQ
EQual To
expr_a EQ expr_b
Tests whether expr_a is equal to expr_b
Two strings are equal only if the case (upper or lower) matches letter-by-letter.
NE
Not Equal To
expr_a NE expr_b
Tests whether expr_a is not equal to expr_b
GE
Greater Than or Equal To
expr_a GE expr_b
Tests whether expr_a is greater than or equal to expr_b
LE
Less Than or
Equal To
expr_a LE expr_b
Tests whether expr_a is less than or equal to expr_b

Note: The expression {0 EQ ''} ("does zero equal the null string?") returns 1 (true).

Logical Operators

These operators are used with 'true' or 'false' expressions. For example:

<MvIF EXPR="{age GE 17 AND age LT 80}">

This expression is true if both expressions '{age GE 17}' and '{age LT 80}' are true.
Operator
Name
Description
NOT
Logical NOT
NOT expr
Returns the opposite of expr (if expr is false, NOT expr is true, and vice versa). Notice that this operator is unary: it acts on one expression, not two.
AND
Logical AND
expr_a AND expr_b
This expression is true if both expr_a and expr_b are true.
OR
Logical OR
expr_a OR expr_b
This expression is true if either of expr_a and expr_b is true.

Text String Operators

MivaScript also supports a number of built-in string functions.
Operator
Name
Description
$
Concatenate strings
expr_a $ expr_b
Concatenates (joins) the strings expr_a and expr_b together.
For example, {'fred' $ 'flintstone'} would result in 'fredflintstone'.
IN / CIN
Beginning position
expr_a IN expr_b
expr_a CIN expr_b
Returns the beginning position of expr_a contained in expr_b.
For example, {'da' IN 'canada'} returns 5, because 'da' begins at the fifth letter in 'canada'. IN is case-sensitive: it will find matches only if the matched sub-string in expr_b has the same case, letter-by-letter, as expr_a. Use the CIN operator if you want to make your comparison case-insensitive. Notice that if you use literal strings in this expression you have to surround them with single quotes.
EIN / ECIN
End position
expr_a EIN expr_b
expr_a ECIN expr_b
Returns the end position of expr_a contained in expr_b.
For example, {'dia' IN 'canadian'} returns 7, because 'dia' ends at the seventh letter in 'canadian'. EIN/ECIN returns 0 when the left operand is NULL. This fixes backward compatibility with MivaScript v3.57 and earlier "Htmlscript" versions. ECIN is the case-insensitive version of EIN.
CRYPT
Encrypt a string
plaintext CRYPT key
Performs a one-way encryption, similar to that provided with the UNIX crypt command. The string plaintext is encrypted using the string key (this string is sometimes called a 'salt'). CRYPT always yields the same result when applied to a particular plaintext and key. FreeBSD applications can take advantage of crypt(3) features.

Bitwise Operators

These operators act on numbers at the binary or 'bit' level.
Operator
Name
Description
BITAND
Bitwise AND
expr_a BITAND expr_b
Perform a logical AND on the bits of expr_a and expr_b.
BITOR
Bitwise OR
expr_a BITOR expr_b
Perform a logical OR on the bits of expr_a and expr_b.
BITXOR
Bitwise Exclusive OR
expr_a BITXOR expr_b
Perform a logical exclusive OR on the bits of expr_a and expr_b (return the number whose bits are equal to 1 in either, but not both, of the original numbers).
BITOC
Bitwise ones complement
BITOC expr
Flip the bits of expr (including the 'sign bit'). This operator is unary: it acts on one number, not two. Example: {BITOC 9}. 9 in binary form is '1001'; including the 'sign bit' (left most bit), which indicates that the number is positive, it is '01001'. Flipping these bits gives '10110'. Since the sign bit is now '1', the number is negative. According to the rules of binary arithmetic, '0110' interpreted as a negative number is '-10'.
BITSL
Bitwise shift-left
expr_a BITSL expr_b
Shift the bits of expr_a to the left by expr_b places. The leftmost bits are lost, and the rightmost bits are replaced by zeroes.'{23 BITSL 2}' is interpreted as follows: 23 is 00010111 in binary form; shifting these bits left two places gives 01011100, or 92 in decimal format.
BITSR
Bitwise shift-right
expr_a BITSR expr_b
Shift the bits of expr_a to the right by expr_b places. The rightmost bits are lost, and the leftmost bits are replaced by zeroes.

Variables

Prefixes and Scope

Prefixes in the variable name define its scope in the current program. The variable scopes available in MivaScript are:

  • Local
    (prefix local or l): Scope is only inside the <MvFUNCTION> block.
  • Database
    (dbname.database.var or dbname.d.var): Scope is named database.
  • System
    (prefix system.varname or s.varname): Used when a built-in system variable or a variable that is generated by an <MvSMTP>, <MvPOP>, or <MvCALL> loop is named.
  • Global
    (prefix global or g): Scope is the entire program

If scope is not defined, the Virtual Machine checks to see if a previously scoped variable of same name exists and has scope in current location, in the following order:

    • system variable (s.var or system.var)
    • local variable (l.var or local.var)
    • database variable (d.var or database.var)
    • global variable (g.var or global.var or var)
    • if no variable var (with any prefix) exists, then, var is created as a global variable
Note: Use miva_getvarlist(scope) to see currently defined variables with the scope.

If the variable will be used in an expression, the variable name must start with a letter or an underscore.

Built-In System Variables

System variables are automatically initialized when a MivaScript program begins execution. There are two types of system variables:

  • Static system variables
    values are set only when script begins execution.
  • Dynamic system variables
    values are set each time they are used in an expression.

All of the time-related variables (except for dyn_time_remaining and globaltimeout) have both static and dynamic versions: the dynamic variables start with the dyn_ prefix. With the exception of recno, all other system variables are static.

Time Variables

Dynamic
Static
Return value
dyn_time_t
time_t
Number of seconds since 1 Jan. 1970 (numeric)
dyn_tm_hour
tm_hour
Hour in current day (numeric)
dyn_tm_isdst
tm_isdst
Has the value true (1) if daylight time is in effect in this time zone (boolean)
dyn_tm_mday
tm_mday
Day of the month (numeric)
dyn_tm_min
tm_min
Minutes in current hour (numeric)
dyn_stm_mon
stm_mon
Month of the year (string)
dyn_tm_mon
tm_mon
Month of the year (numeric)
dyn_tm_sec
tm_sec
Seconds in current minute (numeric)
dyn_tm_usec
tm_usec
The current microsecond, relative to dyn_tm_sec or tm_sec. (On Windows, this value is updated only in 50-millisecond increments).
dyn_stm_wday
stm_wday
Day of the week (string)
dyn_tm_wday
tm_wday
Day of the week (numeric)
dyn_tm_yday
tm_yday
Day in year (numeric)
dyn_tm_year
tm_year
Year (numeric)
dyn_stm_zone
stm_zone
The time zone (string)
---
globaltimeout
Maximum total number of seconds that this script can execute.
dyn_time_remaining
---
Number of seconds before the current script will time out.
Note: The values returned by the dyn_tm_ variables are not zero-padded; for example, if the time is 12:04, dyn_tm_min returns '4', not '04'. You can use the padl() function to perform padding, if required.

CGI, HTTP, and Other Variables

All available CGI environment variables are automatically converted into static MivaScript system variables upon start-up. All HTTP headers are saved in environment variables and therefore are also converted to MivaScript static variables. The availability of environment variables depends on the server software; the availability of HTTP headers also depends on the browser; therefore, not all variables listed here are guaranteed to be available in all circumstances. For more information on HTTP headers and environment variables, consult a CGI reference and/or your server documentation.

Note: HTTP servers convert HTTP headers into environment variables in which '-' is converted to '_', and to which the prefix 'HTTP' is added.
Accessibility Codes

Origin:

S: generated by Miva Merchant Virtual Machine, Miva Merchant Mia

E: if available, inherited from environment

H: if available, inherited from HTTP header (via the environment)

Platform:

C: accessible with CGI version of Miva Merchant Virtual Machine

N: accessible with NSAPI version of Miva Merchant Virtual Machine

P: accessible with Miva Merchant Mia

For example, E: C,N means that the variable in question is inherited from the environment and is accessible in the CGI and NSAPI versions of Miva Merchant Virtual Machine.

Variable
Return Value
Accessibility
apitype
Platform: 'CGI', 'NSAPI', or 'Mia' (Miva Merchant Mia)
S: C,N,P
argN
If a list of values is passed to a MivaScript program, argN is the value of the Nth argument on the URL used to call the script. arg1 always contains the program file name. The first argument after the file name will be arg2, and so forth.
S: C,N,P
auth_type
Authentication method user by the server
E: C,N
callerid
Each time a cookie-enabled browser accesses a MivaScript document, MivaScript creates a 32-character cookie that is unique to that browser and URL. The cookie lasts for one year after being set. Cookies can be turned off in Miva Merchant Virtual Machine; contact your server administrator.
S: C,N,P
content_length
Length of any attached (POST) information
E: C
content_type
Type of data for POST
E: C
documenturl
Contains URL of the currently running MivaScript program. This URL also contains the character between the program name and the command line arguments ('+' for NSAPI and Miva Merchant Mia, and '?' for CGI).
S: C,N,P
gateway_interface
Version of CGI used
E: C
globaltimeout
Maximum total number of seconds that this script can execute.
S: C,N,P
http_accept
Comma-separated list of MIME types (type/subtype) that the browser will accept. This list is very incomplete on most browsers.
H: C,N,P
http_accept_charset
Character sets preferred by the browser (other than the default ASCII or ISO Latin-1)
H: C,N,P
http_accept_language
ISO codes for the languages preferred by the browser
H: C,N,P
http_connection
String that browser sends to the server to preserve a TCP connection (also called a "keep-alive" string). Not supported by all browsers and servers.
H: C,N,P
http_cookie
Contents of all the cookies set for the document.
H: C,N,P
http_host
Remote host name (usually same as server_name)
H: C,N,P
http_pragma
Mode client is running under
H: C,P
http_referer
The document that the current document was accessed from.
H: C,P
http_user_agent
Browser name, platform, version, and library
H: C,N,P
mivaversion
new in 4.00
Version of the MivaScript language preprocessor
(Replaces the previous s.version)
S: C,N,P
miva_defaultlanguage
Retrieves the current default language setting

miva_language
Retrieves the current language setting

miva_sslavailable
new in 4.00
Whether OpenSSL is available for use by <MvCALL>
S: C,N,P
nargs
If a list of values is passed to a MivaScript program, nargs is the number of arguments on the URL, including the program file name.
S: C,N,P
path_info
Extra path information in the URL (a directory path that occurs immediately after the name of the CGI program in the URL)
E: C,N
path_translated
path_info, translated to a physical location by prepending the server document directory to its value
E: C
process_id
Currently running process number
S: C,N,P
query_string
Information passed after a URL and a "?" via the GET method
E: C
remote_addr
IP address of remote host
E: C,N,P
remote_host
The domain name of the remote host
E: C,N,P
remote_ident
Remote user name, from servers that support RFC 931 identification
E: C
remote_user
User name associated with protected script, on servers that support user authentication
E: C,N
request_method
GET, POST, or HEAD
E: C,N,P
script_name
Virtual path to CGI script; not mapped locally to actual path
E: C
server_hostname
The name of the server
E: C,N
server_name
Same as server_hostname
E: C,N,P
server_port
Port under which server is running
E: C,P
server_port_secure
Whether the port is secure (boolean)
E: C
server_protocol
Name and revision of protocol used
E: C,N,P
server_software
HTTP server and version number that processed the request
E: C,P
server_url
server_hostname, in URL format
E: C,N
server_version
Version of the server
E: C,N
user_agent
Same as http_user_agent
H: N

MivaScript also allows site administrators to define their own system variables. Check with your administrator to find out whether any have been added to your site.

Note: Miva Merchant does not give scripts direct access to standard input (STDIN).

Functions

  • Define functions using <MvFUNCTION> tag.
  • Use <MvEVAL> to display the function's returning value.
  • Use <MvASSIGN> to return a function's value(s) with no display, and store the function's value.

Passing Variables by Reference

Parameters are variables whose scope is usually the body of the function. But, a parameter may have an optional "VAR" after the variable name, signifying that the parameter would be passed by reference. Any changes to the variable within the function will be reflected in the variable used in calling the function, and any array elements or structure members will be preserved.

For example:

<MvFUNCTION NAME="functionname" PARAMETERS="varname1,varname2 VAR, varname3">
...
</MvFUNCTION>

Built-in Functions

Time Functions

Note: These functions cannot be used to process dates earlier than January 1, 1970, or later than January 19, 2038.
Function Name (parameters)
Action
ftime ( path )
(new in 4.00)
Returns time_t since a file in the data directory was last modified.
See "Time Variables" for time_t definition.
stime( path )
(new in 4.00)
Returns time_t since a file in the script directory was last modified.
See "Time Variables" for time_t definition.
time_t_month(time_t, time_zone)
Returns the current month as a number
time_t_year(time_t, time_zone)
Returns the current year
time_t_hour(time_t, time_zone)
Returns current hour (using a 24-hour clock)
time_t_min(time_t, time_zone)
Returns the current minute in the hour
time_t_sec(time_t, time_zone)
Returns the current second in the minute
time_t_dayofmonth(time_t, time_zone)
Returns the current day of the month
time_t_dayofweek(time_t, time_zone)
Returns the current day of the week as a number (Sunday=1)
time_t_dayofyear(time_t, time_zone)
Returns the number of days since the beginning of the year, including today
timezone()
Returns an integer which is the number of hours behind or ahead of GMT (not accounting for Daylight Time)
mktime_t(year, month, dayofmonth, hours, minutes, seconds, time_zone)
Returns the time_t value for the time specified

Text String Functions

Note: Literal strings or characters used as arguments to these functions must be surrounded by single quotes, '...'. For example: isalpha('r2d2'). These functions do not modify their arguments; they return values based on those arguments.
Boolean-valued String Functions

These functions all start with is and return a true (1) or false (0) value depending on the composition of the string. Each of these functions is based on the C language function of the same name, but is applied to the whole string: isdigit(string) will return true if every character in the string is a digit or null, and false otherwise.

Note: For all functions except isdigit() and isxdigit(), the set of characters understood to be alphabetic is inherited from the setlocale() setting used on the system running the Miva Merchant Virtual Machine. For this reason, these functions are not guaranteed to return the same results on all machines.

Function Name (parameters)
Action
isalnum(string)
Returns true (1) if all characters in string are either alphabetic or digits, and false (0) otherwise.
isalpha(string)
Returns true (1) if all characters in string are alphabetic and false (0) otherwise.
isascii(string)
Returns true (1) if all characters in string are ASCII characters (those with decimal value between 0 and 127), and false (0) otherwise.
iscntrl(string)
Returns true (1) if all characters in string are control characters (those with decimal value between 0 and 31, or 127), and false (0) otherwise.
isdigit(string)
Returns true (1) if all characters in string are digits in the range 0-9, and false (0) otherwise.
isgraph(string)
Returns true (1) if all characters in string are graphic characters (those with decimal value between 33 and 127), and false (0) otherwise.
islower(string)
Returns true (1) if all characters in string are lowercase letters, and false (0) otherwise.
isprint(string)
Returns true (1) if all characters in string are printable characters (same as graphic characters, with the addition of the space character), and false (0) otherwise.
ispunct(string)
Returns true (1) if all characters in string are punctuation characters (non-alphanumeric graphics characters), and false (0) otherwise.
isspace(string)
Returns true (1) if all characters in string are whitespace (space, tab, vertical tab, newline, form feed) characters, and false (0) otherwise.
isupper(string)
Returns true (1) if all characters in string are uppercase letters, and false (0) otherwise.
isxdigit(string)
Returns true (1) if all characters in string are hexadecimal digits (a-f, A-F, 0-9), and false (0) otherwise.

Other String Functions

Function Name
(parameters)
Action
asciichar
(number)
Returns the character corresponding to number (number must be less than 255).
asciivalue
(character)
Returns the ASCII numeric value for character (character must be a single character).
decodeattribute
(string)
Returns a copy of string (which is usually a URL) converted from URL-encoded format to ordinary text. This function is the opposite of encodeattribute.
decodeentities
(string)
Returns a copy of string in which all HTML entities have been converted to their plain text equivalents (for example, '&lt;' is converted to '<'). This function is the opposite of encodeentities.
encodeattribute
(string)
Returns a copy of string (which is usually a URL) in URL-encoded format. Special characters such as space, tilde (~), and the plus sign are converted to hexadecimal %nn format. This function is the opposite of decodeattribute.
encodeentities
(string)
Returns a copy of string in which all characters have been converted to their HTML entity equivalents, where applicable (for example, '<' is converted to '&lt;'). This function is the opposite of decodeentities.
gettoken(string, separators, n)
Tokenizes string, using any of the characters in separators as token separators, and returns the nth token. A null string is returned if there is no nth token.
glosub_array( string, search, replace )
(new in 4.00)
Works like glosub(), but search and replace are arrays that are iterated through, each value in the search array found in the string is replaced by the corresponding replace array value.
glosub(string, search, replace)
Global substitution; returns a copy of string in which all instances of string search have been replaced by string replace. (Note: to represent a backslash (\) in replace, use '\\').
len(string)
Returns the number of characters in string.
ltrim(string)
Returns a copy of string with all space characters removed from the left end.
padl(string, length, padcharacter)
Returns a string length characters long, consisting of string padded on the left with as many instances of padcharacter as are needed to make up the full length.
padr( string, length, padcharacter)
Returns a string length characters long, consisting of string padded on the right with as many instances of padcharacter as are needed to make up the full length.
rtrim(string)
Returns a copy of string with all space characters removed from the right end.
substring(string, start, length)
Returns the substring of string, beginning at position start, length characters long.
tokenize( string, replacements )
(new in 4.00)
Returns the string, concatenated with the value of each token contained in replacements. Replacements is an array of structures, each with a token and a value.

Example:
<MvASSIGN NAME = "l.replacements" INDEX = "{1}" MEMBER = "token" VALUE = "token1">
<MvASSIGN NAME = "l.replacements" INDEX = "{1}" MEMBER = "value" VALUE = "value">
<MvASSIGN NAME = "l.replacements" INDEX = "{1}" MEMBER = "token" VALUE = "token2">
<MvASSIGN NAME = "l.replacements" INDEX = "{1}" MEMBER = "value" VALUE = "works">
<MVASSIGN NAME = "l.tokens" VALUE = "{ tokenize( 'This is a %token1% that %token2%.' , l.replacements ) }">
<MvEVAL EXPR="{ l.tokens }">
tolower(string)
Returns a copy of string in lower case.
toupper(string)
Returns a copy of string in upper case.
trim( string )
(new in 4.00)
Returns the value of string with leading and trailing spaces removed

Note: The asciichar(n) function puts out a single byte whose value is n. It is up to the client application (such as a browser) to render this value as a character. Almost all HTML browsers support the ISO Latin-1 character encoding, and will display asciichar(n) as the character whose ISO Latin-1 (decimal) encoding is n. The rendering of non-printable characters, and values of asciichar(n) where n is not associated with a character in ISO Latin-1, is undefined. In particular, the rendering of asciichar(n) where n is in the decimal range 129-160, is undefined, though many browsers will display the corresponding ANSI character. The rendering of the output of asciichar(n) by an arbitrary application follows the character encoding used by that application, and is in general platform-specific.

Numerical Functions

The arguments of the trigonometric functions sin, cos, tan, sinh, cosh, and tanh should be expressed in radians; the results of asin, acos, atan, and atan2 are expressed in radians. Function arguments in radians can be given in the range 0 to 2pi, or -pi to pi.

Function Name (parameters)
Action
acos(number)
Returns the arccosine of number.
asin(number)
Returns the arcsine of number.
atan(number)
Returns the arctangent of number.
atan2(y,x)
Returns the arctangent of y/x. This is similar to atan(), but the signs of y and x are taken into account when computing the quadrant of the result.
ceil(number)
Returns the smallest integer greater than or equal to number
cos(number)
Returns the cosine of number.
cosh(number)
Returns the hyperbolic cosine of number.
exp(number)
Returns the constant e (approximately 2.71828) raised to the power number.
floor(number)
Returns the largest integer less than or equal to number
fmod(number1,number2)
Returns the remainder of number1/number2; number1, number2, and the result are all floating point numbers.
int(number)
Returns integer portion of number (removes the decimal and any digits to the right of it)
log(number)
Returns the natural logarithm (base e, approximately 2.71828) of number.
log10(number)
Returns the base 10 logarithm of number
power(number, power)
Raises number to a a power (for example, power(12,2)=144)
random(maximum)
Returns a random number less than or equal to maximum
rnd(number, number_of_places)
Works like the ROUND operator, rounding number up or down to number_of_places after the decimal
sin(number)
Returns the sine of number.
sinh(number)
Returns the hyperbolic sine of number.
sqrt(number)
Returns the square root of number.
tan(number)
Returns the tangent of number.
tanh(number)
Returns the hyperbolic tangent of number.

File System Functions

  • These functions operate on files in the Miva Merchant data directory (for f-functions) and the Miva Merchant Script directory (for s-functions)
  • fs- and sf functions operate on both directories. (The first character, f or s, is the source, second is the destination.)
  • Literal filenames and paths must be surrounded by single quotes.
    ... <MvIF EXPR="{fexists('mondo.dat')}">...
  • Forward slash (on Windows and Unix) separates folders/directories.
  • Except as indicated, all file system functions return a value of '1' (true) if they succeed, and '0' (false) if they fail.

Function Name(parameters)
Action
fchmod(source_path, mode_number) schmod(source_path, mode_number)
fchmod() works like UNIX chmod and changes permissions to mode_number on the file named by source_path in the data directory. schmod() does the same in the script directory. The mode number must be in the format nnnn (decimal) or 0nnnn (octal).
New in 4.01: Literal Octal requires single quotes. Example:
<MvASSIGN NAME = "varname" VALUE = "{ fchmod( source_path,'0755') }">
fcopy(source_path, destination_path) scopy(source_path, destination_path)
fcopy() work like UNIX cp to copy the file named by source_path to the file named by destination_path, both within the data directory; scopy() does the same in the script directory.
fscopy(source_path, destination_path) sfcopy(source_path, destination_path)
fscopy() works like UNIX cp to copy the file named by source_path in the data directory to the file named by destination_path in the script directory; sfcopy() does the same thing in the reverse direction.
fdelete(path), sdelete(path)
fdelete() works like UNIX rm to delete the file named by path in the data directory.
sdelete() deletes the file or directory named by path in the script directory.
fexists(path), sexists(path)
fexists() returns a boolean true (1) or false (0) testing if the file named by path exists in the data directory; sexists() does the same for the script directory.
fmkdir(path), smkdir(path)
fmkdir() works like UNIX mkdir to create a directory specified by path in the data directory; smkdir() does the same in the script directory.
fmode(path), smode(path)
Returns the permissions mode of the file named by path in the data directory (returns -1 if the file does not exist). smode() does the same in the script directory.
frename(source_path, destination_path), srename(source, destination)
frename() works like UNIX mv to rename the file named by source_path to be the file named by destination_path, both within the data directory. srename() does the same in the script directory.
fsrename(source_path, destination_path), sfrename(source_path, destination_path)
fsrename() works like UNIX mv to rename the file named by source_path in the data directory to be the file named by destination_path in the script directory. sfrename() does the same in the opposite direction.
fsize(path), ssize(path)
fsize() returns the number of bytes in the file named by path in the data directory (returns -1 if the file does not exist). ssize() does the same in the script directory.
fsymlink(file, lnk)
(Unix only)
Creates a symbolic link to the file in the data directory.
file - path name of the file relative to the Miva Merchant data directory.
lnk - path name of the link relative to the Miva Merchant data directory.
ssymlink(file, lnk)
(Unix only)
Creates a symbolic link to the file in the scripts directory.
file - path name of the file relative to the Miva Merchant scripts directory.
lnk - path name of the link relative to the Miva Merchant scripts directory

Language Functions

Function Name (parameters)
Action
miva_setlanguage (language)
sets the current language.
Language has two parts: language-country, such as en-US for English-United States.
miva_setdefaultlanguage (language)
sets the current default language.

System Functions

Function Name (parameters)
Action
makesessionid( )
Returns a 128-bit unique ID.
miva_array_collapse(array)
(new in 4.00)
Returns a copy of the array with the indices sequential from one to the number of elements in the source array. (So, array[1], array[50], array[100] would be resultarray[1], resultarray[2], resultarray[3].)
miva_array_elements
This function returns the number of elements in the array that were actually used.
miva_array_max
This function will return the maximum array element used.
Example:
<MvASSIGN NAME="l.array" INDEX="1" VALUE="n">
<MvASSIGN NAME="l.array" INDEX="100" VALUE="m">
<MvASSIGN NAME="max" value="{miva_array_max(l.array)}">
MIVA_ARRAY_MAX returns the value of 100.
miva_array_serialize
miva_array_deserialize
miva_array_serialize returns a string representation of the array and any subarrays. miva_array_deserialize is passed a string in the format returned from miva_array_serialize, and returns an aggregate repopulated to match the original aggregate.
miva_getvarlist
(scope)
Returns a comma-separated list of the names of all currently defined variables with the given scope. scope must be a literal string: 'l', 'local', 'g', 'global', 's', 'system'. ( Note: For xBase3 databases, use <MvREVEALSTRUCTURE>.)
miva_output_flush( )
new in 4.00
Writes the HTTP headers and any other output to the browser. Second and subsequent calls will write the output, but not rewrite the headers.
miva_output_header( name, value)
new in 4.00
Sets an HTTP header name-value pair.
miva_variable_value
(varname)
Takes a variable name and returns the value of the variable to which the value of varname is referring.

Encryption Functions

Function Name (parameters)
Action
rsa_generate_keypair(pubkey_file, privkey_file, bits, e, passphrase)
Generates an RSA keypair, saving the public key in "pubkey_file", the private key in "privkey_file", and encrypting the private key with "passphrase".
Returns 1 on success, 0 on error.
rsa_load_publickey(pubkey_file, rsa VAR)
Load an RSA public key from a PKCS#1 file specified by "pubkey_file".
Returns 1 on success, 0 on error.
rsa_load_privatekey(privkey_file, rsa VAR, passphrase)
Load an encrypted RSA private key from a PKCS#8 file specified by "privkey_file", and decrypt it using "passphrase".
Returns 1 on success, 0 on error.
rsa_public_encrypt(rsa, plaintext, encrypted VAR)
Encrypt the data in "plaintext", storing the result in "encrypted", using the public key portion of the RSA structure specified by "rsa".
Returns 1 on success, 0 on error.
rsa_public_decrypt(rsa, encrypted, plaintext VAR)
Decrypt the data in "encrypted", storing the result in "plaintext", using the public key portion of the RSA structure specified by "rsa".
Returns 1 on success, 0 on error.
rsa_private_encrypt(rsa, plaintext, encrypted VAR)
Encrypts the data in "plaintext", storing the result in "encrypted", using the private key portion of the RSA structure specified by "rsa".
Returns 1 on success, 0 on error.
rsa_private_decrypt(rsa, encrypted, plaintext VAR)
Decrypts the data in "encrypted", storing the result in "plaintext", using the private key portion of the RSA structure specified by "rsa".
Returns 1 on success, 0 on error.
rsa_free(rsa VAR)
Frees the RSA indicated by "rsa".
Returns 1 on success, 0 on error.
crypto_rand_bytes(n)
Generates "n" random bytes, and returns them.
crypto_base64_encode(data)
Base-64 encodes "data", returning the encoded result.
crypto_base64_decode(data)
Base-64 decodes "data", returning the decoded result.
crypto_md5(data)
Calculates the MD5 hash of "data", returning the result.
bf_encrypt(key, plaintext, encrypted VAR)
Blowfish encrypts "plaintext" using the key "key" in ECB mode, storing the result in "encrypted".
Returns 1 on success, 0 on error.
bf_decrypt(key, encrypted, plaintext VAR)
Blowfish decrypts "encrypted" using the key "key" in ECB mode, storing the result in "plaintext".
Returns 1 on success, 0 on error.

Assignment and Evaluation Tags

<MvASSIGN>

Attributes
Comments
NAME ="{expression} | literal"
VALUE="{expression} | literal"
MEMBER="member:submember"
INDEX="{expression} | literal"

Syntax:
. Empty tag.
NOTE: If a value is assigned to an array without specifying an index, the array will be destroyed
<MvASSIGN NAME="var" VALUE="{expression}|literal">
<MvASSIGN NAME ="array[3]" value="{xxx}"
<MvASSIGN NAME="l.structure" MEMBER="member:submember" VALUE="2">
<MvASSIGN NAME="varname:membername" INDEX="3" VALUE="{xxx}">

<MvASSIGNARRAY>

Attributes
Comments
NAME ="{expression} | literal"

Syntax:
<MvASSIGNARRAY NAME="l.array" VALUE="123">
<MvDIMENSION INDEX="1">
<MvDIMENSION INDEX="2">
<MvDIMENSION INDEX="7">
</MvASSIGNARRAY>
(Accessed in an expression as "l.array[1][2][7]" )
. Closed tag.
. Defines a multi-dimension array
. Only <MvDIMENSION> and <MvMEMBER> tags allowed within <MvASSIGNARRAY> block.

<MvDIMENSION>
Attributes
Comments
INDEX="{expression} | literal"

Syntax:
<MvASSIGNARRAY NAME="varname" VALUE="vvv">
<MvDIMENSION INDEX="4">
<MvDIMENSION INDEX="5">
<MvDIMENSION INDEX="6">
</MvASSIGNARRAY>
. Empty tag.
. Defines Multi Dimension Array Index within <MvASSIGNARRAY> block.
. MvDIMENSION and MvMEMBER tags may be intermixed
NOTE: Must be within the <MvASSIGNARRAY> block.
<MvMEMBER>
Attributes
Comments
NAME="{expression} | literal"

Syntax:
<MvASSIGNARRAY NAME="l.array" VALUE="123">
<MvMEMBER NAME="one">
<MvMEMBER NAME="two">
<MvMEMBER NAME="seven">
</MvASSIGNARRAY>
. Empty tag.
. Defines a Multi-dimension Array Index within <MvASSIGNARRAY> block.
. Additional member attributes can be included in the MEMBER attribute of MvASSIGN.
. MvDIMENSION and MvMEMBER tags may be intermixed.

<MvEVAL>

Attributes
Comments
EXPR="{expression}"
EXPRESSION="{expression}"
Syntax:
. Empty tag.
. Displays expression results to browser.
.
<MvEVAL EXPR = "{var1 + var2}">
<MvEVAL EXPR="{'The answer: ' $ func1(42)}">

Configuration and Function Tags

<MIVA>

Attributes
Comments
INTERPRET="html_expressions
STANDARDOUTPUTLEVEL="html, text, compresswhitespace"
ERROROUTPUTLEVEL="syntax,expression,runtime"
ERRORMESSAGE="text_of_error_message"
MvTAGNAME_ERROR="fatal/nonfatal,display/nodisplay">

Syntax:
. Empty tag.
. INTERPRET has no behavior for compiled MivaScript.
. STANDARDOUTPUTLEVEL specifies what displays in browser
. Runtime value for ERROROUTPUTLEVEL is the only useful flag for Compiled MivaScript. (Syntax and Expression errors are flagged by the compiler .)
. MvTAGNAME is a MivaScript tag
. fatal causes runtime error for tag to terminate script
. display causes runtime error for named tag to display.
<MIVA STANDARDOUTPUTLEVEL = "text, html, compresswhitespace">

<MvCOMMENT>

Attributes
Comments
(none)

Syntax:
. Closed tag.
<MvCOMMENT>This is a comment to explain my code.</MvCOMMENT>

<MvFUNTIONRETURN>

Attributes
Comments
VALUE="{expression} | literal"

Syntax:
<MvFUNCRETURN VALUE="{expression}">
. Empty tag.
. Returns a value back to the tag that called the function.
Equivalent name: <MvFUNCRETURN>

<MvFUNCTION>

Attributes
Comments
NAME="{expression} | literal"
PARAMETERS="var1,var2 VAR,var3..."
STANDARDOUTPUTLEVEL="html,text,
compresswhitespace"
ERROROUTPUTLEVEL="syntax,expression,runtime"

Syntax:
<MvFUNCTION NAME="functionname" PARAMETERS="var1,var2 VAR, var3">
...
</MvFUNCTION>
. Empty tag.
. NAME is required.
. Parameters are optional.
. Runtime value for ERROROUTPUTLEVEL is the only useful flag for Compiled MivaScript. (Syntax and Expression errors are flagged by the compiler .)
. Parameter may be passed by reference entering VAR after variable. (changes to variable within this function will be reflected in the variable used in calling this function.)

<MvHIDE>

Attributes
Comments
FIELDS="var1,var2,var3"

Syntax:
<MvHIDE FIELDS="v1,v2,v3">
. Empty tag.
. Use only inside FORM
. Passes hidden fields on the fly, when a form is submitted.
. Variables and values passed as name/value pairs (specified by the <FORM>'s ACTION attribute) or in the standard input if METHOD is POST.
. Converts into one or more hidden <INPUT> tags, corresponding to each variable specified by FIELDS.

Localization Tags

<MvLOCALIZED>

Attributes
Comments
NAME="var" (optional)
ID="id-001"
STANDARDOUTPUTLEVEL="html,text,
compresswhitespace" (or null)

. Closed tag.
. Starts and ends Localization block.
. If NAME specified, output is stored in named variable, instead of output to the browser.
NOTE: Built-in language functions set the current and default language. See "Language Functions" on pageÝ20.

<MvLOCALIZED-TOKEN>

Attributes
Comments
NAME = "token_name"
VALUE="{EXPR} | literal"

Syntax:
. Empty tag.
. Must be inside <MvLOCALIZED> block.
. Must precede <MvLocalized-Text> block(s) that use token.
<MvLOCALIZED-TOKEN NAME="token" VALUE="xxx">

<MvLOCALIZED-TEXT>

Attributes
Comments
LANGUAGE="language_id"

Syntax:
<MvLOCALIZED-TEXT LANGUAGE = "en-US">
<P>Note the new rates of 5%%.</P>
</MvLOCALIZED-TEXT>

. Closed tag.
. The text for the language specified by the LANGUAGE attribute.
. HTML allowed within block.
. MivaScript tags not allowed within block.

Note: The percent character, %, is used to identify a token. Therefore, to use it within the localized text, enter two in a row, as shown in the sample above.

Database Tags

<MvADD>

Attributes
Comments
NAME = "database alias" (optional)
View = "viewname" (optional)
Syntax:
<MvADD> NAME = "Alias"
. Empty tag.
. Adds record of defined fields to database.
. If name omitted, record is added to primary database.

<MvCLOSE>

Attributes
Comments
NAME="database alias" (optional)

Syntax:
<MvCLOSE NAME = "Products">

. Empty tag.
. Closes the database alias. If name omitted, primary database alias is closed.

NOTE: Database might continue to be open under a different alias.

<MvCLOSEVIEW>

Attributes
Comments
NAME = "database alias"
VIEW = "viewname"

Syntax:
<MvCLOSEVIEW NAME="db_alias"
VIEW="viewname">
. Empty tag.
. Closes the specified SQL view.

<MvCREATE>

Attributes
Comments
NAME = "database alias"
DATABASE = "db_file | {exp}"
FIELDS = "fieldname1 CHAR(max_chars),
fieldname2 NUMBER (digits_before.digits_after),
fieldname3 DATE,
fieldname4 BOOL,
fieldname5 MEMO "
TYPE="xbase3" (optional, defaults to xBase3)
. Empty tag.
. Creates new database file, with specified name and fields.

NOTE: An alias becomes the primary alias automatically when it is created or opened (subsequent create or open operations override this).

<MvDELETE>

Attributes
Comments
NAME = "database alias"
VIEW = "viewname" (optional for xBase3)

Syntax:
<MvDELETE NAME = "Categories">
. Empty tag.
. Marks record for deletion.

<MvFILTER>

Attributes
Comments
NAME = "database alias"
FILTER_TYPE="expression | variable" (optional, defaults to expression)
FILTER="{expression}"
NAME = "database alias"


. Empty tag.
. Records not matching FILTER condition are invisible to navigation tags
. When FILTER_TYPE is variable, the FILTER attribute must be an expression that resolves to a variable name.
. Omit FILTER attribute to remove a filter.

NOTE: The variables totrec and recno continue to refer to the complete, unfiltered database

<MvFIND>

Attributes
Comments
NAME="database alias"
VALUE="{expression} | literal"
EXACT (optional)
VIEW = viewname (optional for xBase3)


. Empty tag.
. Performs case sensitive search.
. Points to first matching record.
. If NAME is omitted, uses primary database's index.

<MvGO>

Attributes
Comments
NAME="database alias"
ROW="row_number | top | bottom"
VIEW="odbc_db_view" (not required for internal xBase3 databases)

Syntax:
<MvGO NAME = "Categories" ROW = "top">
. Empty tag.
. Row_number refers to physical order.
. Top and bottom refer to indexed order.

<MvOPEN>

Attributes
Comments
NAME="database alias"
DATABASE="{expression} | literal"
TYPE="xbase3 | odbc | user-defined" (optional for xbase3)
INDEXES="index1.mvx,index2.mvx,..." (optional)
username (non-xBase3)
password (non-xBase3)
. Empty tag.
. The same database file can be open more than once simultaneously with different aliases.

NOTE: An alias becomes the primary alias automatically when it is created or opened (subsequent create or open operations override this).

<MvOPENVIEW>

Attributes
Comments
NAME="database alias"
VIEW="view name"
QUERY="sqlquery
Fields="varlist"
Syntax:
<MvOPENVIEW NAME = "Example"
VIEW = "Products"
QUERY = "SELECT * FROM prod_table"
where id = :A"> (Oracle)
where id = ?" (ODBC)>

. Empty tag.
. <MvOPENVIEW> opens a view based on the results of the sqlquery.
. <MvGO> and <MvSKIP> can be used with views. Other tags that allow the VIEW attribute:
- <MvPRIMARY>
- <MvFIND>
- <MvSETINDEX>
- <MvUPDATE>
- <MvDELETE>
- <MvUNDELETE>
- <MvADD>
- <MvREVEALSTRUCTURE>

<MvPACK>

Attributes
Comments
NAME="database alias"

. Empty tag.
. Permanently removes all records that were marked for deletion (with <MvDELETE>).
. Physical record numbers are reset.
NOTE: All open index files are automatically updated after <MvPACK >is executed. (Use <MvREINDEX for closed indexes.)

<MvPRIMARY>

Attributes
Comments
NAME="database alias"
INDEX = "index1.mvx"
. Empty tag.
. Explicitly names the primary index.

<MvQUERY>

Attributes
Comments
NAME="database alias" (optional)
QUERY="SQL query"
FIELDS = "varlist"
Syntax:
. Empty tag.
. Must have an opened view for queries to return results.
. If name omitted, applies to primary database.
<MvQUERY NAME="my_db"
QUERY = "SELECT * FROM prod_table"
where id = :A"> (Oracle)
where id = ?" (ODBC)>

<MvREVEALSTRUCTURE>

Attributes
Comments
NAME="database alias"
DATABASE="path/filename.dbf""
VIEW= "viewname" (optional for xBase3 )
VARIABLE="varname"
. Creates new database, which is not open.
. Each record contains:
field_name:
field_type
field_len
field_dec
If variable is specified, variable is set to array of structures, with array index = field # and member names as above (listed in "Each record contains")

<MvSKIP>

Attributes
Comments
NAME="database alias"
ROWS="number"
VIEW="odbc_db_view" (optional for xBase3 )

Syntax:
. Empty tag.
. Moves the record pointer a specific number of records forward or backward relative to its current position.
. If name omitted, applies to primary database alias.
. ROWS defaults to one.

<MvIF EXPR = "{ NOT Categories.d.EOF }"> <MvSKIP NAME = "Categories" ROWS = "1">

<MvUNDELETE>

Attributes
Comments
NAME="database alias"
VIEW="viewname" (optional for xBase3)

. Empty tag.
. Removes mark for deletion set by <MvDELETE> from the current record in the named database alias.

<MvUPDATE>

Attributes
Comments
NAME="database alias"
VIEW="viewname" (optional for xBase3)

. Empty tag.
. Updates current record with the contents of variables corresponding to the database fields.
. If name omitted, applies to the primary database.
. Locks the record that is being updated.

Database Index Tags

<MvMAKEINDEX>

Attributes
Comments
NAME="database alias"
INDEXFILE="filename.mvx"
EXPR_TYPE ="{expression} | variable"
EXPR="{key_expr} | variablename"
FLAGS="[ascending | descending],
[unique | nounique], [string]"

. Empty tag.
. Creates index files for named database alias.
. If name omitted, applies to the primary database.
. Ordered by value of EXPR and FLAGS.
. By default, becomes the Primary Index for the named database alias.

NOTE: The key expression may not exceed 500 characters in length, and may not evaluate to more than 100 characters.

<MvREINDEX>

Attributes
Comments
NAME="database alias" (optional)
. Empty tag.
. Recreates all open index files for named database alias.
. If name omitted, primary database index files are reindexed.

<MvSETINDEX>

Attributes
Comments
NAME="database alias"
INDEXES="index1.mvx, index2.mvx

. Empty tag.
. The specified index file(s) become the index file(s) for the named database alias.
. First index file listed becomes the primary index for named database.
. If name omitted, applies to primary database.

Database Implicit Fields

Remember that the physical record number of a record may change if the database is packed (that is, some records are physically deleted using <MvPACK>).

Function Name (parameters)
Action
deleted

Works with: xbase3

Does NOT Work with: ODBC, Oracle
If the current record has been marked for deletion, the boolean variable db_alias.d.deleted is set to true (deleted or d.deleted can be used when referring to the primary database).

Example:
db_alias.d.deleted
eof
End of File. The boolean variable db_alias.d.eof is true if the end of the database with alias db_alias has been reached.

Example:
<MvWHILE EXPR="{NOT worker_db.d.eof}"
<MvEVAL EXPR="{worker_db.d.employee}"
...
recno

Works with: ODBC, Oracle, xBase3
Current physical record number in a database or query.

Example:
db_alias.d.recno

Note: <MvIMPORT> uses recno
totrec

Works with: xbase3

Does NOT Work with: ODBC, Oracle
Total number of records in the database.

Example:
db_alias.d.totrec

Email Tags

<MvPOP>

Attributes
Comments
MAILHOST="host"
LOGIN="login_name"
PASSWORD="password"
DIRECTORY="directory"


. Closed tag.
. MivaScript documents can receive email by becoming POP3 clients.
. Stores received data in special variables:
- messagesubject
- messagedate
- messagesender
- messagereplyto
- messagebody

<MvPOPDELETE>

Attributes
Comments
(none)

. Empty tag.
. Deletes the current email message on the server.
. Must be executed inside the <MvPOP> loop. The message will still be processed by the application in this iteration of the <MvPOP> loop.

Note: Since some servers do not remove their temp files, make sure you delete the temp files, where present.

<MvPOPSTOP>

Attributes
Comments
(none)

. Empty tag.
. Terminates the current <MvPOP>.
. Must be executed inside the <MvPOP> loop.

<MvSMTP>

Attributes
Comments
TO= "to_address1,to_address2,..."
SUBJECT="expression" (optional)
CC="cc_address1,cc_address2,..." (optional)
MAILHOST="mailhost"
FROM="from_address">
[optional headers]
[blank line]
... message body (text/tags)...

. Closed tag.
. SMTP is used to send mail from any valid mail server
. Optional headers are, Reply-To, Return-Path, and Sender.

External File Tags

<MvDO>

Attributes
Comments
FILE="filename" (.mvc only)
NAME="var" (optional)
VALUE="{func(args)}" (optional)

NOTE: A .txt or .html file may be renamed to .mvc, then compiled. (Remember to rename the file name in the originating script file.) Also see: "<MvCALL>".
. Empty tag.
. <MvDO>tags can be nested.
. If NAME and VALUE specified, the named function is the only code in the external file that is executed.
. If NAME and VALUE are omitted, everything in the external file is executed, and the results of all <MvASSIGN> tags are available to subsequent code in the current file. However, any function definitions in the external file are not available after the <MvDO> has been processed.

<MvEXPORT>

Attributes
Comments
FILE="filename"
FIELDS="var1,var2,var3,..."
DELIMITER="chars">

. Empty tag.
. Writes a single line of data to an external output file, at the end of the output file, on a new line.
. Does not automatically loop. See "<MvWHILE>".

<MvIMPORT>

Attributes
Comments
FILE = "filename"
FIELDS = "var1,var2,var3,..."
DELIMITER = "chars"
FILTER_TYPE = "{expression" | variable" (optional)
FILTER = ""{expression} | variablename" (optional)
. Closed tag.
. Loops once through entire file, stopping on eof, </MvIMPORT>, or <MvIMPORTSTOP>.
. The variable, recno, is automatically created.
. <MvIMPORT> may be nested.

<MvIMPORTSTOP>

Attributes
Comments
(none)

. Empty tag.
. Stops <MvIMPORT>.
. Jumps to code that follows </IMPORT> tag.

<MvLOCKFILE>

Attributes
Comments
FILE="filename"
. Empty tag.
. Indicates to other processes that the current process has requested an exclusive lock on FILE.
. Multiple lock requests are queued.
. <MvLOCKFILE> tags can be nested.

Flow Control Tags

<MvELSE>

Attributes
Comments
(none)

. Empty tag.
. Alternative Script branch.
. Preceded by <MvIF>.

<MvELSEIF>

Attributes
Comments
EXPR="{expression}"

New in 4.00
. Empty tag.
. Use in place of nested <MvIF> tags.

<MvEXIT>

Attributes
Comments
(none)

. Empty tag.
. Causes the script in which the exit tag resides to terminate.

NOTE: An <MvEXIT> within a FUNCTION in a script called with <MvDO> also causes the script containing the <MvDO> to terminate. Therefore, to exit from a script called by <MvDO>, without exiting from the calling script, use <MvFUNCRETURN>.

<MvIF>

Attributes
Comments
EXPR="{conditional expression}"

Syntax:
<MvIF EXPR="{fexists('file.dat')}">
. Closed tag.
. Processes the code between the <MvIF> and </MvIF> tags if and only if condition is true.

<MvWHILE>

Attributes
Comments
EXPR="{expression}"

. Closed tag.
. Repeats code until condition is false, or, until <MvWHILESTOP> is encountered.

<MvWHILESTOP>

Attributes
Comments
(none)
. Empty tag.
. Terminates MvWHILE loop.

HTTP and Commerce Server Tags

<MvCALL>

Attributes
Comments
ACTION = "URL"
METHOD = "POST|GET|XML|RAW"
CONTENT-TYPE
FIELDS = "var1,var2,var3,..."
FILES = "fvar1,fvar2,fvar3,...">

(Methods "XML" and "RAW" new in 4.00)
. Closed tag.
. HTTP protocol emulates a browser and contacts a remote host.
. When Method = XML, POST content type will be "text/xml." FIELDS contain variables whose values pass in the header.
. When Method = POST, the FIELDS variables' values are sent to the URL.
. CONTENT-TYPE attribute available when the METHOD is XML or RAW.
- If not specified and METHOD is XML, POST will have content type "text/xml."
- If not specified and METHOD is RAW, will have content type "text/plain."
. The <MvCALL>...</MvCALL> loop terminates when the entire document has been received, or when an <MvCALLSTOP> is encountered.

MvCALL Variables

Call Object Type, Tag

If object returned is a start tag, it is separated into the following variables:

  • callvalue
    The whole tag, including angle brackets, tag name, any attributes and attribute values.
  • callobjectelement
    The tag name.
  • callobjectnumattributes
    The number of attributes specified for the tag.
  • callobjectattributeN or callobjectattribute[ ]
    If attributes have been specified, variables callobjectattribute1, callobjectattribute2, ... will be created, containing the names of the attributes as they appear in sequence.
    Accessible as arrays using the syntax callobjectattribute[1], which has the same value as callobjectattribute1.
  • callobjectvalueN and callobjectvalue[ ]
    If attributes have been specified for the tag, variables callobjectvalue1, callobjectvalue2, ... will be created, containing the values of the attributes as they appear in sequence.
    Accessible as arrays using the syntax callobjectvalue[1], which has the same value as callobjectvalue1.
Call Object Type, Text
Note: Sequences of white space between tags (such as new lines, spaces, and tabs) are returned as text objects by MvCALL.
  • callobjecttype
    Value: 'text'
    callvalue
  • actual string of text and white space
HTTP Header Information
  • callnumberofheaders
    This variable contains the number of headers that have been retrieved. The number and content of headers depends on the server software that is serving the document. The value of callnumberofheaders will not change during the iterations of the <MvCALL> loop through a particular document.
  • callreturnheaderN and callreturnheader[ ]
    The headers received are placed into a separate variables callreturnheader1, callreturnheader2, and so forth. The values of these variables do not change during the iterations of the <MvCALL> loop through a particular document. Accessible as arrays using the syntax callreturnheader[1], which has the same value as callreturnheader1.

<MvCALLSTOP>

Attributes
Comments
(no attributes)

. Empty tag.
. Terminates MvCALL.

<MvCOMMERCE>

Attributes
Comments
ACTION ="url_to_commerce_server"
METAMETHOD="name"
FIELDS="value1,value2,...">

. Closed tag.
. When encountered, the Virtual Machine consults registered commerce libraries list. If found, the Virtual Machine loads the corresponding commerce library.

<MvCOMMERCESTOP>

Attributes
Comments
(no attributes)

. Empty tag.
. Terminates <MvCOMMERCE>.