function UAM_version_update() { // Get current plugin version // -------------------------- $plugin = PluginInfos(UAM_PATH); $version = $plugin['version']; // Update plugin version in #_config table // --------------------------------------- $query = ' UPDATE ' . CONFIG_TABLE . ' SET value="' . $version . '" WHERE param="UserAdvManager_Version" LIMIT 1 ;'; pwg_query($query); // Check #_plugin table consistency // Only useful if a previous version upgrade has not worked correctly (rare case) // ------------------------------------------------------------------------------ $query = ' SELECT version FROM ' . PLUGINS_TABLE . ' WHERE id = "UserAdvManager" ;'; $data = pwg_db_fetch_assoc(pwg_query($query)); if (empty($data['version']) or $data['version'] != $version) { $query = ' UPDATE ' . PLUGINS_TABLE . ' SET version="' . $version . '" WHERE id = "UserAdvManager" LIMIT 1 ;'; pwg_query($query); } }
if (!isset($_GET['tab'])) { $page['tab'] = 'global'; } else { $page['tab'] = $_GET['tab']; } $tabsheet = new tabsheet(); $tabsheet->add('global', l10n('UAM_Tab_Global'), $my_base_url . '&tab=global'); $tabsheet->add('userlist', l10n('UAM_Tracking registered users'), $my_base_url . '&tab=userlist'); $tabsheet->add('usermanager', l10n('UAM_Tracking confirmations'), $my_base_url . '&tab=usermanager'); $tabsheet->add('ghosttracker', l10n('UAM_Tab_GhostTracker'), $my_base_url . '&tab=ghosttracker'); $tabsheet->select($page['tab']); $tabsheet->assign(); // +-----------------------------------------------------------------------+ // | Getting plugin version | // +-----------------------------------------------------------------------+ $plugin = PluginInfos(UAM_PATH); $version = $plugin['version']; // +----------------------------------------------------------+ // | FCK Editor for email text fields | // +----------------------------------------------------------+ $toolbar = 'Basic'; $width = '750px'; $height = '300px'; $areas = array(); array_push($areas, 'UAM_ConfirmMail_Custom_Txt1', 'UAM_ConfirmMail_Custom_Txt2', 'UAM_GTAutoDelText', 'UAM_USRAutoDelText', 'UAM_CustomRejectConnexion_Text'); if (function_exists('set_fckeditor_instance')) { $fcke_config = unserialize($conf['FCKEditor']); foreach ($areas as $area) { if (!isset($fcke_config[$area])) { $fcke_config[$area] = false; }
/** * UAM specific database dump (only for MySql !) * Creates an SQL dump of UAM specific tables and configuration settings * * @returns : Boolean to manage appropriate message display * */ function UAM_dump($download) { global $conf; $plugin = PluginInfos(UAM_PATH); $version = $plugin['version']; // Initial backup folder creation and file initialisation // ------------------------------------------------------ if (!is_dir(UAM_PATH . '/include/backup')) { mkdir(UAM_PATH . '/include/backup'); } $Backup_File = UAM_PATH . '/include/backup/UAM_dbbackup.sql'; $fp = fopen($Backup_File, 'w'); // Writing plugin version $insertions = "-- " . $version . " --\n\n"; fwrite($fp, $insertions); // Saving UAM specific tables // -------------------------- $ListTables = array(USER_CONFIRM_MAIL_TABLE, USER_LASTVISIT_TABLE); $j = 0; while ($j < count($ListTables)) { $sql = 'SHOW CREATE TABLE ' . $ListTables[$j]; $res = pwg_query($sql); if ($res) { $insertions = "-- -------------------------------------------------------\n"; $insertions .= "-- Create " . $ListTables[$j] . " table\n"; $insertions .= "-- ------------------------------------------------------\n\n"; $insertions .= "DROP TABLE IF EXISTS " . $ListTables[$j] . ";\n\n"; $array = pwg_db_fetch_row($res); $array[1] .= ";\n\n"; $insertions .= $array[1]; $req_table = pwg_query('DESCRIBE ' . $ListTables[$j] . ';') or die(my_error()); $nb_fields = pwg_db_num_rows($req_table); $req_table2 = pwg_query('SELECT * FROM ' . $ListTables[$j]) or die(my_error()); while ($line = pwg_db_fetch_row($req_table2)) { $insertions .= 'INSERT INTO ' . $ListTables[$j] . ' VALUES ('; for ($i = 0; $i < $nb_fields; $i++) { $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; } $insertions = substr($insertions, 0, -2); $insertions .= ");\n"; } $insertions .= "\n\n"; } fwrite($fp, $insertions); $j++; } // Saving UAM configuration // ------------------------ $insertions = "-- -------------------------------------------------------\n"; $insertions .= "-- Insert UAM configuration in " . CONFIG_TABLE . "\n"; $insertions .= "-- ------------------------------------------------------\n\n"; fwrite($fp, $insertions); $pattern = "UserAdvManager%"; $req_table = pwg_query('SELECT * FROM ' . CONFIG_TABLE . ' WHERE param LIKE "' . $pattern . '";') or die(my_error()); $nb_fields = pwg_db_num_rows($req_table); $nb_fields = $nb_fields - 1; // Fix the number of fields because pwg_db_num_rows() returns a bad number while ($line = pwg_db_fetch_row($req_table)) { $insertions = 'INSERT INTO ' . CONFIG_TABLE . ' VALUES ('; for ($i = 0; $i < $nb_fields; $i++) { $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; } $insertions = substr($insertions, 0, -2); $insertions .= ");\n"; fwrite($fp, $insertions); } fclose($fp); // Download generated dump file // ---------------------------- if ($download == 'true') { if (@filesize($Backup_File)) { $http_headers = array('Content-Length: ' . @filesize($Backup_File), 'Content-Type: text/x-sql', 'Content-Disposition: attachment; filename="UAM_dbbackup.sql";', 'Content-Transfer-Encoding: binary'); foreach ($http_headers as $header) { header($header); } @readfile($Backup_File); exit; } } return true; }
function plugin_install($id, $version, &$errors) { global $conf; /* ****************************************************************** */ /* **************** BEGIN - Data preparation in vars **************** */ /* ****************************************************************** */ // Default global parameters for UserAdvManager conf // ------------------------------------------------- $defaultUAM = array('MAIL_INFO' => 'false', 'CONFIRM_MAIL' => 'false', 'NO_CONFIRM_GROUP' => '-1', 'VALIDATED_GROUP' => '-1', 'VALIDATED_STATUS' => '-1', 'USERNAME_CHAR' => 'false', 'USERNAME_CHAR_LIST' => '', 'NO_CONFIRM_STATUS' => '-1', 'MAILINFO_TEXT' => l10n('UAM_Default_InfoMail_Txt'), 'CONFIRMMAIL_TEXT' => l10n('UAM_Default_ConfirmMail_Txt'), 'MAILEXCLUSION' => 'false', 'MAILEXCLUSION_LIST' => '', 'ADMINPASSWENF' => 'false', 'GHOSTRACKER' => 'false', 'GHOSTRACKER_DAYLIMIT' => '10', 'GHOSTRACKER_REMINDERTEXT' => l10n('UAM_Default_GhstReminder_Txt'), 'ADDLASTVISIT' => 'false', 'ADMINCONFMAIL' => 'false', 'REDIRTOPROFILE' => 'false', 'GTAUTO' => 'false', 'GTAUTOMAIL' => 'false', 'GTAUTODEL' => l10n('UAM_Default_GhstDeletion_Txt'), 'GTAUTOMAILTEXT' => l10n('UAM_Default_GhstDemotion_Txt'), 'DOWNGRADE_GROUP' => '-1', 'DOWNGRADE_STATUS' => '-1', 'ADMINVALIDATIONMAIL' => l10n('UAM_Default_AdminValidation_Txt'), 'CUSTOMPASSWRETR' => 'false', 'CUSTOMPASSWRETR_TEXT' => l10n('UAM_Default_PwdRequest_Txt'), 'USRAUTO' => 'false', 'USRAUTODEL' => l10n('UAM_Default_ValidationTimeout_Txt'), 'USRAUTOMAIL' => 'false', 'STUFFS' => 'false', 'HIDEPASSW' => 'false', 'NO_VALID_LEVEL' => '-1', 'VALID_LEVEL' => '-1', 'DOWNGRADE_LEVEL' => '-1', 'REJECTCONNECT' => 'false', 'REJECTCONNECT_TEXT' => l10n('UAM_Default_RejectConnexion_Txt'), 'CONFIRMMAIL_SUBJECT' => l10n('UAM_Default_ConfirmMail_Subject'), 'CONFIRMMAIL_REMAIL_SUBJECT' => l10n('UAM_Default_ConfirmMail_Remail_Subject'), 'INFOMAIL_SUBJECT' => l10n('UAM_Default_InfoMail_Subject'), 'GTAUTOMAIL_SUBJECT' => l10n('UAM_Default_GTAutoMail_Subject'), 'GTREMINDER_SUBJECT' => l10n('UAM_Default_GTReminder_Subject'), 'ADMINVALIDATIONMAIL_SUBJECT' => l10n('UAM_Default_AdminValidationMail_Subject'), 'ADD_GALLERY_URL_TO_EMAILS' => 'false', 'EMAILS_COPY_TO_ADMINS' => 'false'); // Default specific parameters for UserAdvManager ConfirmMail conf // --------------------------------------------------------------- $defaultConfirmMail = array('CONFIRMMAIL_TIMEOUT' => 'false', 'CONFIRMMAIL_DELAY' => '5', 'CONFIRMMAIL_REMAIL_TXT1' => l10n('UAM_Default_CfmMail_Remail_Txt1'), 'CONFIRMMAIL_REMAIL' => 'false', 'CONFIRMMAIL_REMAIL_TXT2' => l10n('UAM_Default_CfmMail_Remail_Txt2'), 'CONFIRMMAIL_CUSTOM_TXT1' => l10n('UAM_Default_CfmMail_Custom_Txt1'), 'CONFIRMMAIL_CUSTOM_TXT2' => l10n('UAM_Default_CfmMail_Custom_Txt2')); // Set current plugin version in config table // ------------------------------------------ $plugin = PluginInfos(UAM_PATH); $version = $plugin['version']; /* **************************************************************** */ /* **************** END - Data preparation in vars **************** */ /* **************************************************************** */ /* ***************************************************************************** */ /* **************** BEGIN - Database actions and initialization **************** */ /* ***************************************************************************** */ // Create UserAdvManager conf if not already exists // ------------------------------------------------ $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "UserAdvManager" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("UserAdvManager","' . pwg_db_real_escape_string(serialize($defaultUAM)) . '","UAM parameters") ;'; pwg_query($q); } // Create UserAdvManager_ConfirmMail conf if not already exists // ------------------------------------------------------------ $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "UserAdvManager_ConfirmMail" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("UserAdvManager_ConfirmMail","' . pwg_db_real_escape_string(serialize($defaultConfirmMail)) . '","UAM ConfirmMail parameters") ;'; pwg_query($q); } // Create UserAdvManager_Redir conf if not already exists // ------------------------------------------------------ $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "UserAdvManager_Redir" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("UserAdvManager_Redir","0","UAM Redirections") ;'; pwg_query($q); } // Create UserAdvManager_Version conf if not already exists // -------------------------------------------------------- $query = ' SELECT param FROM ' . CONFIG_TABLE . ' WHERE param = "UserAdvManager_Version" ;'; $count = pwg_db_num_rows(pwg_query($query)); if ($count == 0) { $q = ' INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment) VALUES ("UserAdvManager_Version","' . $version . '","UAM version check") ;'; pwg_query($q); } // Create USER_CONFIRM_MAIL_TABLE // ------------------------------ $q = ' CREATE TABLE IF NOT EXISTS ' . USER_CONFIRM_MAIL_TABLE . ' ( id varchar(50) NOT NULL default "", user_id smallint(5) NOT NULL default "0", mail_address varchar(255) default NULL, status enum("webmaster","admin","normal","generic","guest") default NULL, date_check datetime default NULL, reminder ENUM("true","false") NULL, PRIMARY KEY (id) ) ENGINE=MyISAM;'; pwg_query($q); // Create USER_LASTVISIT_TABLE // --------------------------- $q = ' CREATE TABLE IF NOT EXISTS ' . USER_LASTVISIT_TABLE . ' ( user_id SMALLINT(5) NOT NULL DEFAULT "0", lastvisit DATETIME NULL DEFAULT NULL, reminder ENUM("true","false") NULL, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM;'; pwg_query($q); // Piwigo's native tables modifications for validation status // ---------------------------------------------------------- $query = ' SHOW COLUMNS FROM ' . USERS_TABLE . ' LIKE "UAM_validated" ;'; $result = pwg_query($query); if (!pwg_db_fetch_row($result)) { $q = ' ALTER TABLE ' . USERS_TABLE . ' ADD UAM_validated enum("true","false") ;'; pwg_query($q); } /* *************************************************************************** */ /* **************** END - Database actions and initialization **************** */ /* *************************************************************************** */ }