Esempio n. 1
0
// ============================================================================
// ####  Tables  ##############################################################
// ============================================================================
$select_client = "SELECT ClientID,   Name    FROM Clients    ORDER BY Name    ASC";
$select_trip = "SELECT TripID,     Title   FROM Trips      ORDER BY Title   ASC";
$select_country = "SELECT CountryID,  Name    FROM Countries  ORDER BY Name    ASC";
$select_currency = "SELECT CurrencyID, NameISO FROM Currencies ORDER BY NameISO ASC";
/**
 * Table keys should *not* contain:
 * * Forward slashes ('/') -- confuses AngularJS router arguments, even
 *   though this is not used at this time
 * * Pipes ('|') -- confuses automatically generated keys when table=*
 * * Newlines ('\n') or carriage returns ('\r') -- may confuse their
 *   usage in HTML/HTTP
 */
TableClass::$data_tables = array('clients' => array('source' => 'sqlite_demos', 'table' => "Clients", 'name' => "Customers", 'col_id' => 'ClientID', 'col_list' => array(array('Name', 'ContactPhone', 'ContactEmail'), array('Name')), 'col_name' => 'Name', 'col_names' => array('Name' => array("Name", "text"), 'Address' => array("Street address", "textaddr"), 'CountryID' => array("Country", "select", '', $select_country), 'TaxNumber' => array("Tax number", "text"), 'ContactPhone' => array("Telephone", "tel"), 'ContactEmail' => array("E-mail", "email"), 'PreferCurrencyID' => array("Preferred currency", "select", '', $select_currency)), 'editable' => TableClass::EDITABLE_ON_REQUEST | TableClass::CAN_INSERT, 'buttons' => array(array('Purchases', 'list:sales', 'Purchases made by this client', array('ClientID', 'ClientID')))), 'client-sales' => array('unlisted' => true, 'source' => 'sqlite_demos', 'table' => "Clients", 'name' => "Customers", 'col_id' => 'ClientID', 'col_list' => array(array('Name', 'ContactPhone', 'ContactEmail'), array('Name')), 'col_name' => 'Name', 'col_names' => array('Name' => array("Name", "text"), 'Address' => array("Street address", "textaddr"), 'CountryID' => array("Country", "select", '', $select_country), 'TaxNumber' => array("Tax number", "text"), 'ContactPhone' => array("Telephone", "tel"), 'ContactEmail' => array("E-mail", "email"), 'PreferCurrencyID' => array("Preferred currency", "select", '', $select_currency)), 'editable' => TableClass::EDITABLE_ON_REQUEST | TableClass::CAN_INSERT, 'buttons' => array(array('Purchases', 'list:sales', 'Purchases made by this client', array('ClientID', 'ClientID'))), 'filter_list_before' => 'filter_clientsales_list_before'), 'sales' => array('source' => 'sqlite_demos', 'table' => "Sales", 'col_id' => 'SaleID', 'col_list' => array(array('ClientName', 'TripCountryName', 'OnDate'), array('-OnDate')), 'col_name' => 'OnDate', 'col_names' => array('ClientID' => array("Customer", "select", '', $select_client), 'TripID' => array("Trip package", "select", '', $select_trip), 'OnDate' => array("Date travelled", "date"), 'Description' => array("Special requests", "textarea", "Describe any special needs of the customer/trip."), 'Price' => array("Price to bill", "number"), 'PriceCurrencyID' => array("Price currency", "select", '', $select_currency)), 'editable' => TableClass::EDITABLE_ON_REQUEST | TableClass::CAN_INSERT | TableClass::CAN_DELETE, 'filter_list_before' => 'filter_sales_list_before', 'buttons' => array(array('Customer', 'read:clients', 'Show this customer', 'ClientID'), array('Trip package', 'read:trips', 'Show this trip package', 'TripID'))), 'trips' => array('source' => 'sqlite_demos', 'table' => "Trips", 'name' => "Trip Packages", 'col_id' => 'TripID', 'col_list' => array(array('TripCountryName', 'Title', 'UntilDate'), array('TripCountryName', 'Title', '-UntilDate')), 'col_name' => 'Title', 'col_names' => array('Title' => array("Package title", "text", "Title used to summarize this trip package in lists."), 'DestinationCountryID' => array("Trip to", "select", '', $select_country), 'Description' => array("Description", "textarea", "Describe the points of interest visited, provide some history and background, and describe what services this trip package consists of."), 'Price' => array("Price to bill", "number"), 'PriceCurrencyID' => array("Price currency", "select", '', $select_currency), 'UntilDate' => array("Available until", "date", "Date when this trip was/will be no longer available. Leave empty if not yet known.")), 'editable' => TableClass::EDITABLE_ON_REQUEST | TableClass::CAN_INSERT | TableClass::CAN_DELETE, 'filter_list_before' => 'filter_trips_list_before'), 'countries' => array('source' => 'sqlite_demos', 'table' => "Countries", 'name' => "Selectable Countries", 'col_id' => 'CountryID', 'col_list' => array(array('Name'), array('Name')), 'col_names' => array('Name' => array("Name", "text")), 'editable' => TableClass::EDITABLE_ON_REQUEST | TableClass::CAN_INSERT | TableClass::CAN_DELETE, 'buttons' => array(array('Customers living in this country', 'list:clients', 'Customers living in this country', array('CountryID', 'CountryID')), array('Customers traveled to this country', 'list:client-sales', 'Customers that have traveled to this country', array('CountryID', 'TripCountryID')), array('Trip packages to this country', 'list:trips', 'Available trips to this country', array('CountryID', 'DestinationCountryID')))), 'currencies' => array('source' => 'sqlite_demos', 'table' => "Currencies", 'name' => "Selectable Currencies", 'col_id' => 'CurrencyID', 'col_list' => array(array('NameISO', 'Name'), array('NameISO')), 'col_names' => array('NameISO' => array("3-letter 'ISO' name", "text"), 'Name' => array("Full name", "text")), 'editable' => TableClass::EDITABLE_ON_REQUEST | TableClass::CAN_INSERT | TableClass::CAN_DELETE, 'buttons' => array(array('Customers paying in this currency', 'list:clients', 'Customers that prefer to pay in this currency', array('CurrencyID', 'PreferCurrencyID')), array('Sales in this currency', 'list:sales', 'Sales made in this currency', array('CurrencyID', 'PriceCurrencyID')), array('Trip packages in this currency', 'list:trips', 'Available trips in this currency', array('CurrencyID', 'PriceCurrencyID')))));
// Reset the demo database every hour, on the hour (can be removed in production)
// ============================================================================
$browseStorage_demo = @TableClass::$data_sources['sqlite_demos']['file'];
if (is_string($browseStorage_demo)) {
    $browseStorage_demo_dir = dirname($browseStorage_demo) . PATH_SEPARATOR;
    $browseStorage_demo_file = basename($browseStorage_demo);
    $browseStorage_demo_ext = strrchr($browseStorage_demo_file, '.');
    $browseStorage_demo_file = substr($browseStorage_demo_file, 0, -strlen($browseStorage_demo_ext));
    $browseStorage_demo_original = $browseStorage_demo_dir . $browseStorage_demo_file . '-original' . $browseStorage_demo_ext;
    $browseStorage_demo_copy = $browseStorage_demo_dir . $browseStorage_demo_file . '-copy' . $browseStorage_demo_ext;
    if (file_exists($browseStorage_demo_original) && gmdate('YmdH', filemtime($browseStorage_demo_original)) != gmdate('YmdH') && !file_exists($browseStorage_demo_copy)) {
        touch($browseStorage_demo_original);
        // "atomic" duplication:
        copy($browseStorage_demo_original, $browseStorage_demo_copy);
        chmod($browseStorage_demo_copy, 0666);