1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: $path = dirname(dirname(dirname(__DIR__)));
20: require_once $path . '/include' . '/cp_header.php';
21:
22: 23: 24: 25: 26:
27: 28: 29: 30: 31:
32: function xoops_module_update_profile(XoopsModule $module, $oldversion = null)
33: {
34: if ($oldversion < 162) {
35: $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_field') . ' SET field_valuetype=2 WHERE field_name=umode');
36: }
37:
38: if ($oldversion < 100) {
39:
40:
41: $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('profile_category');
42: $GLOBALS['xoopsDB']->queryF($sql);
43:
44:
45: $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('profile_fieldcategory');
46: $GLOBALS['xoopsDB']->queryF($sql);
47:
48:
49: $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/sql/mysql.sql');
50:
51: include_once __DIR__ . '/install.php';
52: xoops_module_install_profile($module);
53:
54: $goupperm_handler = xoops_getHandler('groupperm');
55:
56: $field_handler = xoops_getModuleHandler('field', $module->getVar('dirname', 'n'));
57: $skip_fields = $field_handler->getUserVars();
58: $skip_fields[] = 'newemail';
59: $skip_fields[] = 'pm_link';
60: $sql = 'SELECT * FROM `' . $GLOBALS['xoopsDB']->prefix('user_profile_field') . "` WHERE `field_name` NOT IN ('" . implode("', '", $skip_fields) . "')";
61: $result = $GLOBALS['xoopsDB']->query($sql);
62: $fields = array();
63: while ($myrow = $GLOBALS['xoopsDB']->fetchArray($result)) {
64: $fields[] = $myrow['field_name'];
65: $object = $field_handler->create();
66: $object->setVars($myrow, true);
67: $object->setVar('cat_id', 1);
68: if (!empty($myrow['field_register'])) {
69: $object->setVar('step_id', 2);
70: }
71: if (!empty($myrow['field_options'])) {
72: $object->setVar('field_options', unserialize($myrow['field_options']));
73: }
74: $field_handler->insert($object, true);
75:
76: $gperm_itemid = $object->getVar('field_id');
77: $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('group_permission') . ' SET gperm_itemid = ' . $gperm_itemid . ' WHERE gperm_itemid = ' . $myrow['fieldid'] . ' AND gperm_modid = ' . $module->getVar('mid') . " AND gperm_name IN ('profile_edit', 'profile_search')";
78: $GLOBALS['xoopsDB']->queryF($sql);
79:
80: $groups_visible = $goupperm_handler->getGroupIds('profile_visible', $myrow['fieldid'], $module->getVar('mid'));
81: $groups_show = $goupperm_handler->getGroupIds('profile_show', $myrow['fieldid'], $module->getVar('mid'));
82: foreach ($groups_visible as $ugid) {
83: foreach ($groups_show as $pgid) {
84: $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('profile_visibility') . ' (field_id, user_group, profile_group) ' . ' VALUES ' . " ({$gperm_itemid}, {$ugid}, {$pgid})";
85: $GLOBALS['xoopsDB']->queryF($sql);
86: }
87: }
88:
89:
90: unset($object);
91: }
92:
93:
94: foreach ($fields as $field) {
95: $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_profile') . '` u, `' . $GLOBALS['xoopsDB']->prefix('user_profile') . "` p SET u.{$field} = p.{$field} WHERE u.profile_id=p.profileid");
96: }
97:
98:
99: $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('user_profile');
100: $GLOBALS['xoopsDB']->queryF($sql);
101:
102:
103: $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('user_profile_field');
104: $GLOBALS['xoopsDB']->queryF($sql);
105:
106:
107: $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('group_permission') . ' WHERE `gperm_modid` = ' . $module->getVar('mid') . " AND `gperm_name` IN ('profile_show', 'profile_visible')";
108: $GLOBALS['xoopsDB']->queryF($sql);
109: }
110:
111: if ($oldversion < 162) {
112: $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_field') . "` SET `field_valuetype`=1 WHERE `field_name`='umode'");
113: }
114:
115: if ($oldversion < 186) {
116:
117: $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/';
118: $template_list = array_diff(scandir($templateDirectory), array('..', '.'));
119: foreach ($template_list as $k => $v) {
120: $fileinfo = new SplFileInfo($templateDirectory . $v);
121: if ($fileinfo->getExtension() === 'html' && $fileinfo->getFilename() !== 'index.html') {
122: @unlink($templateDirectory . $v);
123: }
124: }
125:
126: xoops_load('xoopsfile');
127:
128: $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/images/';
129: $folderHandler = XoopsFile::getHandler('folder', $imagesDirectory);
130: $folderHandler->delete($imagesDirectory);
131:
132: $cssFile = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/style.css';
133: $folderHandler = XoopsFile::getHandler('file', $cssFile);
134: $folderHandler->delete($cssFile);
135:
136: $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
137: $GLOBALS['xoopsDB']->queryF($sql);
138: }
139:
140: if ($oldversion < 188) {
141:
142: $tables = new Xmf\Database\Tables();
143: $tables->useTable('profile_field');
144: $criteria = new Criteria('field_name', 'user_sig', '=');
145: $tables->update('profile_field', array('field_type' => 'dhtml'), $criteria);
146: $tables->executeQueue(true);
147: }
148:
149: $profile_handler = xoops_getModuleHandler('profile', $module->getVar('dirname', 'n'));
150: $profile_handler->cleanOrphan($GLOBALS['xoopsDB']->prefix('users'), 'uid', 'profile_id');
151: $field_handler = xoops_getModuleHandler('field', $module->getVar('dirname', 'n'));
152: $user_fields = $field_handler->getUserVars();
153: $criteria = new Criteria('field_name', "('" . implode("', '", $user_fields) . "')", 'IN');
154: $field_handler->updateAll('field_config', 0, $criteria);
155:
156: return true;
157: }
158: