$configuration->MoveNext();
    }
    // Define the project version  (must come after db class is loaded)
    require DIR_FS_INCLUDES . 'version.php';
    // Determine the DATABASE patch level
    $project_db_info = $db->Execute("select * from " . TABLE_PROJECT_VERSION . " WHERE project_version_key = 'PhreeBooks Database' ");
    define('PROJECT_DB_VERSION_MAJOR', $project_db_info->fields['project_version_major']);
    define('PROJECT_DB_VERSION_MINOR', $project_db_info->fields['project_version_minor']);
    if (PROJECT_VERSION_MAJOR . PROJECT_VERSION_MINOR != PROJECT_DB_VERSION_MAJOR . PROJECT_DB_VERSION_MINOR) {
        // run the upgrade script if necessary
        $filepath = DIR_FS_MODULES . 'install/updater.php';
        if (file_exists($filepath)) {
            // execute the sql
            require_once DIR_FS_MODULES . 'general/language/' . $_SESSION['language'] . '/language.php';
            require $filepath;
            execute_upgrade();
        } else {
            die('Trying to upgrade to Release ' . PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR . ' but the upgrade file could not be found!');
        }
    }
    // load currency classes
    require DIR_FS_CLASSES . 'currencies.php';
    $currencies = new currencies();
}
// initialize the message stack for output messages, must be after session starts and configuration variables load
require DIR_FS_CLASSES . 'message_stack.php';
$messageStack = new messageStack();
$messageStack->debug("\nGET Vars = " . arr2string($_GET));
$messageStack->debug("\nPOST Vars = " . arr2string($_POST));
// pull in the custom language over-rides for this module (to pre-define the standard language)
$custom_path = DIR_FS_MY_FILES . 'custom/' . $cat . '/' . $module . '/extra_defines.php';
示例#2
0
 function update($module)
 {
     global $db, $messageStack;
     $error = false;
     $db_version = defined('MODULE_PHREEBOOKS_STATUS') ? MODULE_PHREEBOOKS_STATUS : false;
     if (!$db_version || $db_version < 2.1 || $db_version < '2.1') {
         // For PhreeBooks release 2.1 or lower to update to Phreedom structure
         require DIR_FS_MODULES . 'phreebooks/functions/updater.php';
         if (db_table_exists(TABLE_PROJECT_VERSION)) {
             $result = $db->Execute("select * from " . TABLE_PROJECT_VERSION . " WHERE project_version_key = 'PhreeBooks Database'");
             $db_version = $result->fields['project_version_major'] . '.' . $result->fields['project_version_minor'];
             if ($db_version < 2.1) {
                 $error = execute_upgrade($db_version);
             }
             $db_version = 2.1;
         }
     }
     if ($db_version == 2.1 || $db_version == '2.1') {
         $db_version = $this->release_update($module, 3.0, DIR_FS_MODULES . 'phreebooks/updates/R21toR30.php');
         if (!$db_version) {
             return true;
         }
         // remove table project_version, no longer needed
         if (!$error) {
             $db->Execute("DROP TABLE " . TABLE_PROJECT_VERSION);
         }
     }
     if ($db_version == 3.0 || $db_version == '3.0') {
         $db_version = $this->release_update($module, 3.1, DIR_FS_MODULES . 'phreebooks/updates/R30toR31.php');
         if (!$db_version) {
             return true;
         }
     }
     if ($db_version == 3.1 || $db_version == '3.1') {
         if (!file_exists($path . $dir)) {
             mkdir(DIR_FS_MY_FILES . $_SESSION['company'] . '/phreebooks/orders/', 0755, true);
         }
         write_configure('ALLOW_NEGATIVE_INVENTORY', '1');
         $db_version = 3.2;
     }
     if ($db_version == 3.2 || $db_version == '3.2') {
         write_configure('APPLY_CUSTOMER_CREDIT_LIMIT', '0');
         // flag for using credit limit to authorize orders
         $db->Execute("ALTER TABLE " . TABLE_JOURNAL_MAIN . " CHANGE shipper_code shipper_code VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''");
         require_once DIR_FS_MODULES . 'phreebooks/defaults.php';
         if (is_array(glob(DIR_FS_ADMIN . 'PHREEBOOKS_DIR_MY_ORDERS*.zip'))) {
             foreach (glob(DIR_FS_ADMIN . 'PHREEBOOKS_DIR_MY_ORDERS*.zip') as $file) {
                 $newfile = str_replace('PHREEBOOKS_DIR_MY_ORDERS', '', $file);
                 $newfile = str_replace(DIR_FS_ADMIN, '', $newfile);
                 rename($file, PHREEBOOKS_DIR_MY_ORDERS . $newfile);
             }
         }
         $db_version = 3.3;
     }
     if ($db_version < 3.4 || $db_version < '3.4') {
         if (!db_field_exists(TABLE_JOURNAL_ITEM, 'item_cnt')) {
             $db->Execute("ALTER TABLE " . TABLE_JOURNAL_ITEM . " ADD item_cnt INT(11) NOT NULL DEFAULT '0' AFTER ref_id");
         }
         $db_version = 3.4;
     }
     if ($db_version < 3.51 || $db_version < '3.51') {
         $result = $db->Execute("SELECT id, so_po_ref_id FROM " . TABLE_JOURNAL_MAIN . " WHERE journal_id = 16 AND so_po_ref_id > 0");
         while (!$result->EOF) {
             // to fix transfers to store 0 from any other store
             if ($result->fields['so_po_ref_id'] > $result->fields['id']) {
                 $db->Execute("UPDATE " . TABLE_JOURNAL_MAIN . " SET so_po_ref_id = -1 WHERE id=" . $result->fields['id']);
             }
             $result->MoveNext();
         }
         if (!db_field_exists(TABLE_JOURNAL_ITEM, 'purch_package_quantity')) {
             $db->Execute("ALTER TABLE " . TABLE_JOURNAL_ITEM . " ADD purch_package_quantity float default NULL AFTER project_id");
         }
     }
     if (MODULE_PHREEBOOKS_STATUS < 3.7) {
         $db->Execute("ALTER TABLE " . TABLE_JOURNAL_ITEM . "\n\t\t\tCHANGE qty qty DOUBLE NOT NULL DEFAULT '0',\n\t\t\tCHANGE purch_package_quantity purch_package_quantity DOUBLE NOT NULL DEFAULT '0'");
     }
     if (!$error) {
         write_configure('MODULE_' . strtoupper($module) . '_STATUS', constant('MODULE_' . strtoupper($module) . '_VERSION'));
         $messageStack->add(sprintf(GEN_MODULE_UPDATE_SUCCESS, $module, constant('MODULE_' . strtoupper($module) . '_VERSION')), 'success');
     }
     return $error;
 }