Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.86 KB | None | 0 0
  1. <?php
  2. /**
  3.  * FileMaker API for PHP
  4.  *
  5.  * @package FileMaker
  6.  *
  7.  * Copyright © 2005-2007, FileMaker, Inc. All rights reserved.
  8.  * NOTE: Use of this source code is subject to the terms of the FileMaker
  9.  * Software License which accompanies the code. Your use of this source code
  10.  * signifies your agreement to such license terms and conditions. Except as
  11.  * expressly granted in the Software License, no other copyright, patent, or
  12.  * other intellectual property license or right is granted, either expressly or
  13.  * by implication, by FileMaker.
  14.  */
  15.  
  16. /**#@+
  17.  * @ignore Always load the error class and the implementation delegate.
  18.  */
  19. require_once dirname(__FILE__) . '/FileMaker/Error.php';
  20. require_once dirname(__FILE__) . '/FileMaker/Implementation/FileMakerImpl.php';
  21. /**#@-*/
  22.  
  23. /**#@+
  24.  * Find constants.
  25.  */
  26. define('FILEMAKER_FIND_LT', '<');
  27. define('FILEMAKER_FIND_LTE', '<=');
  28. define('FILEMAKER_FIND_GT', '>');
  29. define('FILEMAKER_FIND_GTE', '>=');
  30. define('FILEMAKER_FIND_RANGE', '...');
  31. define('FILEMAKER_FIND_DUPLICATES', '!');
  32. define('FILEMAKER_FIND_TODAY', '//');
  33. define('FILEMAKER_FIND_INVALID_DATETIME', '?');
  34. define('FILEMAKER_FIND_CHAR', '@');
  35. define('FILEMAKER_FIND_DIGIT', '#');
  36. define('FILEMAKER_FIND_CHAR_WILDCARD', '*');
  37. define('FILEMAKER_FIND_LITERAL', '""');
  38. define('FILEMAKER_FIND_RELAXED', '~');
  39. define('FILEMAKER_FIND_FIELDMATCH', '==');
  40. /**#@-*/
  41.  
  42. /**#@+
  43.  * Find logical operator constants.
  44.   * Use with the {@link FileMaker_Command_Find::setLogicalOperator()}  
  45.  * method.
  46. */
  47. define('FILEMAKER_FIND_AND', 'and');
  48. define('FILEMAKER_FIND_OR', 'or');
  49. /**#@-*/
  50.  
  51. /**#@+
  52.  * Pre-validation rule constants.
  53.  */
  54. define('FILEMAKER_RULE_NOTEMPTY', 1);
  55. define('FILEMAKER_RULE_NUMERICONLY', 2);
  56. define('FILEMAKER_RULE_MAXCHARACTERS', 3);
  57. define('FILEMAKER_RULE_FOURDIGITYEAR', 4);
  58. define('FILEMAKER_RULE_TIMEOFDAY', 5);
  59. define('FILEMAKER_RULE_TIMESTAMP_FIELD', 6);
  60. define('FILEMAKER_RULE_DATE_FIELD', 7);
  61. define('FILEMAKER_RULE_TIME_FIELD', 8);
  62. /**#@-*/
  63.  
  64. /**#@+
  65.  * Sort direction constants.
  66.  * Use with the {@link FileMaker_Command_Find::addSortRule()} and
  67.  * {@link FileMaker_Command_CompoundFind::addSortRule()} methods.
  68.  */
  69. define('FILEMAKER_SORT_ASCEND', 'ascend');
  70. define('FILEMAKER_SORT_DESCEND', 'descend');
  71. /**#@-*/
  72.  
  73. /**#@+
  74.  * Logging level constants.
  75.  */
  76. define('FILEMAKER_LOG_ERR', 3);
  77. define('FILEMAKER_LOG_INFO', 6);
  78. define('FILEMAKER_LOG_DEBUG', 7);
  79. /**#@-*/
  80.  
  81. /**
  82.  * Base FileMaker class. Defines database properties, connects to a database,
  83.  * and gets information about the API.
  84.  *
  85.  * @package FileMaker
  86.  */
  87. class FileMaker
  88. {
  89.     /**
  90.      * Implementation. This is the object that actually implements the API.
  91.      *
  92.      * @var FileMaker_Implementation
  93.      * @access private
  94.      */
  95.     var $_impl;
  96.  
  97.     /**
  98.      * Tests whether a variable is a FileMaker API Error.
  99.      *
  100.      * @param mixed $variable Variable to test.
  101.      * @return boolean TRUE, if the variable is a {@link FileMaker_Error} object.
  102.      * @static
  103.      *
  104.      */
  105.     static function isError($variable)
  106.     {
  107.         return is_a($variable, 'FileMaker_Error');
  108.     }
  109.  
  110.     /**
  111.      * Returns the version of the FileMaker API for PHP.
  112.      *
  113.      * @return string API version.
  114.      * @static
  115.      */
  116.     function getAPIVersion()
  117.     {
  118.         return FileMaker_Implementation::getAPIVersion();
  119.     }
  120.  
  121.     /**
  122.      * Returns the minimum version of FileMaker Server that this API works with.
  123.      *
  124.      * @return string Minimum FileMaker Server version.
  125.      * @static
  126.      */
  127.     static function getMinServerVersion()
  128.     {
  129.         return FileMaker_Implementation::getMinServerVersion();
  130.     }
  131.  
  132.     /**
  133.      * FileMaker object constructor.
  134.      *
  135.      * If you want to use the constructor without specifying all the
  136.      *  parameters, pass in NULL for the parameters you want to omit.
  137.      * For example, to specify only the database name, username, and
  138.      * password, but omit the hostspec, call the constructor as follows:
  139.      *  
  140.      * <samp>
  141.      * new FileMaker('DatabaseName', NULL, 'username', 'password');
  142.      * </samp>
  143.      *
  144.      * @param string $database Name of the database to connect to.
  145.      * @param string $hostspec Hostspec of web server in FileMaker Server
  146.      *        deployment. Defaults to http://localhost, if set to NULL.
  147.      * @param string $username Account name to log into database.
  148.      * @param string $password Password for account.
  149.      */
  150.     function FileMaker($database = NULL, $hostspec = NULL, $username = NULL, $password = NULL)
  151.     {
  152.         $this->_impl = new FileMaker_Implementation($database, $hostspec, $username, $password);
  153.     }
  154.  
  155.     /**
  156.      * Sets a property to a new value for all API calls.
  157.      *
  158.      * @param string $prop Name of the property to set.
  159.      * @param string $value Property's new value.
  160.      */
  161.     function setProperty($prop, $value)
  162.     {
  163.         $this->_impl->setProperty($prop, $value);
  164.     }
  165.  
  166.     /**
  167.      * Returns the current value of a property.
  168.      *
  169.      * @param string $prop Name of the property.
  170.      *
  171.      * @return string Property's current value.
  172.      */
  173.     function getProperty($prop)
  174.     {
  175.         return $this->_impl->getProperty($prop);
  176.     }
  177.  
  178.     /**
  179.      * Returns an associative array of property name => property value for
  180.      * all current properties and their current values.
  181.      *
  182.      * This array enables PHP object introspection and debugging when necessary.
  183.      *
  184.      * @return array All current properties.
  185.      */
  186.     function getProperties()
  187.     {
  188.         return $this->_impl->getProperties();
  189.     }
  190.  
  191.     /**
  192.      * Associates a PEAR Log object with the API for logging requests
  193.      * and responses.
  194.      *
  195.      * @param Log &$logger PEAR Log object.
  196.      */
  197.     function setLogger(&$logger)
  198.     {
  199.         $this->_impl->setLogger($logger);
  200.     }
  201.  
  202.     /**
  203.      * Creates a new FileMaker_Command_Add object.
  204.      *
  205.      * @param string $layout Layout to add a record to.
  206.      * @param array $values Associative array of field name => value pairs.
  207.      *        To set field repetitions, use a numerically indexed array for
  208.      *        the value of a field, with the numeric keys corresponding to the
  209.      *        repetition number to set.
  210.      *
  211.      * @return FileMaker_Command_Add New Add command object.
  212.      */
  213.     function &newAddCommand($layout, $values = array())
  214.     {
  215.         return $this->_impl->newAddCommand($layout, $values);
  216.     }
  217.  
  218.     /**
  219.      * Creates a new FileMaker_Command_Edit object.
  220.      *
  221.      * @param string $layout Layout that the record is part of.
  222.      * @param string $recordId ID of the record to edit.
  223.      * @param array $updatedValues Associative array of field name => value
  224.      *        pairs that contain the updated field values. To set field
  225.      *        repetitions, use a numerically indexed array for the value of a
  226.      *        field, with the numeric keys corresponding to the repetition
  227.      *        number to set.
  228.      *
  229.      * @return FileMaker_Command_Edit New Edit command object.
  230.      */
  231.     function &newEditCommand($layout, $recordId, $updatedValues = array())
  232.     {
  233.         return $this->_impl->newEditCommand($layout, $recordId, $updatedValues);
  234.     }
  235.  
  236.     /**
  237.      * Creates a new FileMaker_Command_Delete object.
  238.      *
  239.      * @param string $layout Layout to delete record from.
  240.      * @param string $recordId ID of the record to delete.
  241.      *
  242.      * @return FileMaker_Command_Delete New Delete command object.
  243.      */
  244.     function &newDeleteCommand($layout, $recordId)
  245.     {
  246.         return $this->_impl->newDeleteCommand($layout, $recordId);
  247.     }
  248.  
  249.     /**
  250.      * Creates a new FileMaker_Command_Duplicate object.
  251.      *
  252.      * @param string $layout Layout that the record to duplicate is in.
  253.      * @param string $recordId ID of the record to duplicate.
  254.      *
  255.      * @return FileMaker_Command_Duplicate New Duplicate command object.
  256.      */
  257.     function &newDuplicateCommand($layout, $recordId)
  258.     {
  259.         return $this->_impl->newDuplicateCommand($layout, $recordId);
  260.     }
  261.  
  262.     /**
  263.      * Creates a new FileMaker_Command_Find object.
  264.      *
  265.      * @param string $layout Layout to find records in.
  266.      *
  267.      * @return FileMaker_Command_Find New Find command object.
  268.      */
  269.     function &newFindCommand($layout)
  270.     {
  271.         return $this->_impl->newFindCommand($layout);
  272.     }
  273.  
  274.     /**
  275.      *
  276.      * Creates a new FileMaker_Command_CompoundFind object.
  277.      *
  278.      * @param string $layout Layout to find records in.
  279.      *
  280.      * @return FileMaker_Command_CompoundFind New Compound Find Set command
  281.      *         object.
  282.      */
  283.     function &newCompoundFindCommand($layout)
  284.     {
  285.         return $this->_impl->newCompoundFindCommand($layout);
  286.     }
  287.    
  288.      /**
  289.      *
  290.      * Creates a new FileMaker_Command_FindRequest object. Add one or more
  291.      * Find Request objects to a {@link FileMaker_Command_CompoundFind} object,
  292.      * then execute the Compound Find command.
  293.      *
  294.      * @param string $layout Layout to find records in.
  295.      *
  296.      * @return FileMaker_Command_FindRequest New Find Request command object.
  297.      */
  298.     function &newFindRequest($layout)
  299.     {
  300.         return $this->_impl->newFindRequest($layout);
  301.     }
  302.    
  303.     /**
  304.      * Creates a new FileMaker_Command_FindAny object.
  305.      *
  306.      * @param string $layout Layout to find one random record from.
  307.      *
  308.      * @return FileMaker_Command_FindAny New Find Any command object.
  309.      */
  310.     function &newFindAnyCommand($layout)
  311.     {
  312.         return $this->_impl->newFindAnyCommand($layout);
  313.     }
  314.  
  315.     /**
  316.      * Creates a new FileMaker_Command_FindAll object.
  317.      *
  318.      * @param string $layout Layout to find all records in.
  319.      *
  320.      * @return FileMaker_Command_FindAll New Find All command object.
  321.      */
  322.     function &newFindAllCommand($layout)
  323.     {
  324.         return $this->_impl->newFindAllCommand($layout);
  325.     }
  326.  
  327.     /**
  328.      * Creates a new FileMaker_Command_PerformScript object.
  329.      *
  330.      * @param string $layout Layout to use for script context.
  331.      * @param string $scriptName Name of the ScriptMaker script to run.
  332.      * @param string $scriptParameters Any parameters to pass to the script.
  333.      *
  334.      * @return FileMaker_Command_PerformScript New Perform Script command
  335.      *         object.
  336.      */
  337.     function &newPerformScriptCommand($layout, $scriptName, $scriptParameters = null)
  338.     {
  339.         return $this->_impl->newPerformScriptCommand($layout, $scriptName, $scriptParameters);
  340.     }
  341.  
  342.     /**
  343.      * Creates a new FileMaker_Record object.
  344.      *
  345.      * This method does not save the new record to the database.
  346.      * The record is not created on the Database Server until you call
  347.      * this record's commit() method. You must specify a layout name,
  348.      * and you can optionally specify an array of field values.
  349.      * Individual field values can also be set in the new record object.
  350.      *
  351.      *
  352.      * @param string $layout Layout to create a new record for.
  353.      * @param array $fieldValues Initial values for the new record's fields.
  354.      *
  355.      * @return FileMaker_Record New Record object.
  356.      */
  357.     function &createRecord($layout, $fieldValues = array())
  358.     {
  359.         return $this->_impl->createRecord($layout, $fieldValues);
  360.     }
  361.  
  362.     /**
  363.      * Returns a single FileMaker_Record object matching the given
  364.      * layout and record ID, or a FileMaker_Error object, if this operation
  365.      * fails.
  366.      *
  367.      * @param string $layout Layout that $recordId is in.
  368.      * @param string $recordId ID of the record to get.
  369.      *
  370.      * @return FileMaker_Record|FileMaker_Error Record or Error object.
  371.      */
  372.     function &getRecordById($layout, $recordId)
  373.     {
  374.         return $this->_impl->getRecordById($layout, $recordId);
  375.     }
  376.  
  377.     /**
  378.      * Returns a Layout object that describes the specified layout.
  379.      *
  380.      * @param string $layout Name of the layout to describe.
  381.      *
  382.      * @return FileMaker_Layout|FileMaker_Error Layout or Error object.
  383.      */
  384.     function &getLayout($layout)
  385.     {
  386.         return $this->_impl->getLayout($layout);
  387.     }
  388.  
  389.     /**
  390.      * Returns an array of databases that are available with the current
  391.      * server settings and the current user name and password
  392.      * credentials.
  393.      *
  394.      * @return array|FileMaker_Error List of database names or an Error object.
  395.      */
  396.     function listDatabases()
  397.     {
  398.         return $this->_impl->listDatabases();
  399.     }
  400.  
  401.     /**
  402.      * Returns an array of ScriptMaker scripts from the current database that
  403.      * are available with the current server settings and the current user
  404.      * name and password credentials.
  405.      *
  406.      * @return array|FileMaker_Error List of script names or an Error object.
  407.      */
  408.     function listScripts()
  409.     {
  410.         return $this->_impl->listScripts();
  411.     }
  412.  
  413.     /**
  414.      * Returns an array of layouts from the current database that are
  415.      * available with the current server settings and the current
  416.      * user name and password credentials.
  417.      *
  418.      * @return array|FileMaker_Error List of layout names or an Error object.
  419.      */
  420.     function listLayouts()
  421.     {
  422.         return $this->_impl->listLayouts();
  423.     }
  424.  
  425.     /**
  426.      * Returns the data for the specified container field.
  427.      * Pass in a URL string that represents the file path for the container
  428.      * field contents. For example, get the image data from a container field
  429.      * named 'Cover Image'. For a FileMaker_Record object named $record,
  430.      * URL-encode the path returned by the getField() method.  For example:
  431.      *
  432.      * <samp>
  433.      * <IMG src="img.php?-url=<?php echo urlencode($record->getField('Cover Image')); ?>">
  434.      * </samp>
  435.      *
  436.      * Then as shown below in a line from img.php, pass the URL into
  437.      * getContainerData() for the FileMaker object named $fm:
  438.      *
  439.      * <samp>
  440.      * echo $fm->getContainerData($_GET['-url']);
  441.      * </samp>
  442.      *
  443.      * @param string $url URL of the container field contents to get.
  444.      *
  445.      * @return string Raw field data|FileMaker_Error if remote container field.
  446.      */
  447.     function getContainerData($url)
  448.     {
  449.         return $this->_impl->getContainerData($url);
  450.     }
  451.  
  452.     /**
  453.      * Returns the fully qualified URL for the specified container field.
  454.      * Pass in a URL string that represents the file path for the container
  455.      * field contents. For example, get the URL for a container field
  456.      * named 'Cover Image'.  For example:
  457.      *
  458.      * <samp>
  459.      * <IMG src="<?php echo $fm->getContainerDataURL($record->getField('Cover Image')); ?>">
  460.      * </samp>
  461.      *
  462.      * @param string $url URL of the container field contents to get.
  463.      *
  464.      * @return string Fully qualified URL to container field contents
  465.      */
  466.     function getContainerDataURL($url)
  467.     {
  468.         return $this->_impl->getContainerDataURL($url);
  469.     }
  470. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement