+// Adds a CREATE TABLE statement if the requested table is not there
+function addCreateTableSql ($tableName, $sql) {
+ // Is the table not there?
+ if (!isSqlTableCreated($tableName)) {
+ // Is not found, so add it
+ addExtensionSql('CREATE TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ' . $sql);
+ } else {
+ // Is already there, which should not happen
+ debug_report_bug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
+ }
+}
+
+// Adds a DROP TABLE statement if the requested tabled is there
+function addDropTableSql ($tableName) {
+ // Is the table there?
+ if (isSqlTableCreated($tableName)) {
+ // Then add it, non-existing tables can be ignored because it will
+ // happen with every newly installed extension.
+ addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
+
+ // Mark it as gone
+ $GLOBALS['isSqlTableCreated'][$tableName] = false;
+ } // END - if
+}
+
+// Adds an admin menu to the SQL queue of the menu entry is not found
+function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
+ // Now check if this menu is there
+ if (!isMenuActionValid('admin', $action, $what)) {
+ // Is what null?
+ if (is_null($what)) {
+ // Add main menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
+ $action,
+ $title,
+ $descr,
+ bigintval($sort)
+ );
+ } else {
+ // Add sub menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES('%s','%s','%s','%s',%s)",
+ $action,
+ $what,
+ $title,
+ $descr,
+ bigintval($sort)
+ );
+ }
+
+ // Add it to the queue
+ addExtensionSql($sql);
+ } elseif (isDebugModeEnabled()) {
+ // Double menus should be located and fixed!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
+ }
+}
+
+// Adds a guest menu to the SQL queue if the menu entry is not found
+function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
+ // Now check if this menu is there
+ if (!isMenuActionValid('guest', $action, $what)) {
+ // Is what null?
+ if (is_null($what)) {
+ // Add main menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
+ $action,
+ $title,
+ $visible,
+ $locked,
+ bigintval($sort)
+ );
+ } else {
+ // Add sub menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
+ $action,
+ $what,
+ $title,
+ $visible,
+ $locked,
+ bigintval($sort)
+ );
+ }
+
+ // Add it to the queue
+ addExtensionSql($sql);
+ } elseif (isDebugModeEnabled()) {
+ // Double menus should be located and fixed!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s,locked=%s,visible=%s detected.", $action, $what, $title, $locked, $visible));
+ }
+}
+
+// Adds a member menu to the SQL queue if the menu entry is not found
+function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
+ // Now check if this menu is there
+ if (!isMenuActionValid('member', $action, $what)) {
+ // Is what null?
+ if (is_null($what)) {
+ // Add main menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
+ $action,
+ $title,
+ $visible,
+ $locked,
+ bigintval($sort)
+ );
+ } else {
+ // Add sub menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
+ $action,
+ $what,
+ $title,
+ $visible,
+ $locked,
+ bigintval($sort)
+ );
+ }
+
+ // Add it to the queue
+ addExtensionSql($sql);
+ } elseif (isDebugModeEnabled()) {
+ // Double menus should be located and fixed!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s,visivle=%s,locked=%s detected.", $action, $what, $title, $visible, $locked));
+ }
+}
+
+// Adds a sponsor menu to the SQL queue if the menu entry is not found
+function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
+ // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
+ if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
+ // Is what null?
+ if (is_null($what)) {
+ // Add main menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s',NULL,'%s','%s',%s)",
+ $action,
+ $title,
+ $active,
+ bigintval($sort)
+ );
+ } else {
+ // Add sub menu
+ $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES('%s','%s','%s','%s',%s)",
+ $action,
+ $what,
+ $title,
+ $active,
+ bigintval($sort)
+ );
+ }
+
+ // Add it to the queue
+ addExtensionSql($sql);
+ } elseif (isDebugModeEnabled()) {
+ // Double menus should be located and fixed!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
+ }
+}
+
+// Add configuration entry if not found for actual extension
+function addConfigAddSql ($columnName, $columnSql) {
+ // Is the column there?
+ if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
+ // Not found, so add it
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
+ } elseif (isDebugModeEnabled()) {
+ // Add debug line
+ logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
+ }
+}
+
+// Drop configuration entry if found for actual extension
+function addConfigDropSql ($columnName) {
+ // Is the column there?
+ if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
+ // Found, so add it
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
+ } elseif (isDebugModeEnabled()) {
+ // Add debug line, debug_report_bug() would cause some extenion updates fail
+ logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
+ }
+}
+
+// Change configuration entry for actual extension
+function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
+ // Add the SQL statement
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
+}
+
+// Enables/disables productive mode for current extension (used only while
+// registration).
+// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
+function enableExtensionProductive ($isProductive = true) {
+ // Log debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ext_name=%s,isProductive=%d", getCurrentExtensionName(), intval($isProductive)));
+
+ // Set it
+ $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
+}
+
+// Checks wether the extension is in productive phase. If not set, development
+// phase (=false) is assumed.
+function isExtensionProductive ($ext_name = '') {
+ // Is the extension name empty? Then use current
+ if (empty($ext_name)) {
+ // Get current extension name
+ $ext_name = getCurrentExtensionName();
+ } // END - if
+
+ // Do we have cache?
+ if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
+ // Load extension only if not yet loaded
+ if (!isset($GLOBALS['ext_productive'][$ext_name])) {
+ // Load extension in test mode
+ loadExtension($ext_name, 'test');
+ } // END - if
+
+ // Determine it
+ $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
+ } // END - if
+
+ // Log debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ext_name=%s,isProductive=%s", $ext_name, intval($GLOBALS[__FUNCTION__][$ext_name])));
+
+ // Return result
+ return $GLOBALS[__FUNCTION__][$ext_name];
+}
+
+// Mark extension file as loaded
+function markExtensionAsLoaded ($ext_name) {
+ // Is it already loaded?
+ if (isExtensionLoaded($ext_name)) {
+ // Then abort here
+ debug_report_bug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
+ } // END - if
+
+ // Mark it
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("ext_name=%s,ext_loaded=true", $ext_name));
+ $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
+}
+
+// Determine wether the given extension is already loaded
+function isExtensionLoaded ($ext_name) {
+ // Is it there?
+ return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
+}
+
+// Mark extension's library file as loaded
+function markExtensionLibraryAsLoaded ($ext_name) {
+ // Is it already loaded?
+ if (isExtensionLibraryLoaded($ext_name)) {
+ // Then abort here
+ debug_report_bug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
+ } // END - if
+
+ // Mark it
+ $GLOBALS['ext_loaded']['library'][$ext_name] = true;
+}
+
+// Determine wether the given extension's library is already loaded
+function isExtensionLibraryLoaded ($ext_name) {
+ // Is it there?
+ return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));
+}
+