| 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 < '1.6.2') { | 
| 35: | $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_field') . ' SET field_valuetype=2 WHERE field_name=umode'); | 
| 36: | } | 
| 37: |  | 
| 38: | if ($oldversion < '1.0.0') { | 
| 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: | if (!$GLOBALS['xoopsDB']->isResultSet($result)) { | 
| 63: | throw new \RuntimeException( | 
| 64: | \sprintf(_DB_QUERY_ERROR, $sql) . $GLOBALS['xoopsDB']->error(), E_USER_ERROR | 
| 65: | ); | 
| 66: | } | 
| 67: | $fields        = array(); | 
| 68: | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { | 
| 69: | $fields[] = $myrow['field_name']; | 
| 70: | $object   = $field_handler->create(); | 
| 71: | $object->setVars($myrow, true); | 
| 72: | $object->setVar('cat_id', 1); | 
| 73: | if (!empty($myrow['field_register'])) { | 
| 74: | $object->setVar('step_id', 2); | 
| 75: | } | 
| 76: | if (!empty($myrow['field_options'])) { | 
| 77: | $object->setVar('field_options', unserialize($myrow['field_options'])); | 
| 78: | } | 
| 79: | $field_handler->insert($object, true); | 
| 80: |  | 
| 81: | $gperm_itemid = $object->getVar('field_id'); | 
| 82: | $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')"; | 
| 83: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 84: |  | 
| 85: | $groups_visible = $goupperm_handler->getGroupIds('profile_visible', $myrow['fieldid'], $module->getVar('mid')); | 
| 86: | $groups_show    = $goupperm_handler->getGroupIds('profile_show', $myrow['fieldid'], $module->getVar('mid')); | 
| 87: | foreach ($groups_visible as $ugid) { | 
| 88: | foreach ($groups_show as $pgid) { | 
| 89: | $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('profile_visibility') . ' (field_id, user_group, profile_group) ' . ' VALUES ' . " ({$gperm_itemid}, {$ugid}, {$pgid})"; | 
| 90: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 91: | } | 
| 92: | } | 
| 93: |  | 
| 94: |  | 
| 95: | unset($object); | 
| 96: | } | 
| 97: |  | 
| 98: |  | 
| 99: | foreach ($fields as $field) { | 
| 100: | $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"); | 
| 101: | } | 
| 102: |  | 
| 103: |  | 
| 104: | $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('user_profile'); | 
| 105: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 106: |  | 
| 107: |  | 
| 108: | $sql = 'DROP TABLE ' . $GLOBALS['xoopsDB']->prefix('user_profile_field'); | 
| 109: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 110: |  | 
| 111: |  | 
| 112: | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('group_permission') . '   WHERE `gperm_modid` = ' . $module->getVar('mid') . " AND `gperm_name` IN ('profile_show', 'profile_visible')"; | 
| 113: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 114: | } | 
| 115: |  | 
| 116: | if ($oldversion < '1.6.2') { | 
| 117: | $GLOBALS['xoopsDB']->queryF('UPDATE `' . $GLOBALS['xoopsDB']->prefix('profile_field') . "` SET `field_valuetype`=1 WHERE `field_name`='umode'"); | 
| 118: | } | 
| 119: |  | 
| 120: | if ($oldversion < '1.8.6') { | 
| 121: |  | 
| 122: | $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/'; | 
| 123: | $template_list     = array_diff(scandir($templateDirectory), array('..', '.')); | 
| 124: | foreach ($template_list as $k => $v) { | 
| 125: | $fileinfo = new SplFileInfo($templateDirectory . $v); | 
| 126: | if ($fileinfo->getExtension() === 'html' && $fileinfo->getFilename() !== 'index.html') { | 
| 127: | @unlink($templateDirectory . $v); | 
| 128: | } | 
| 129: | } | 
| 130: |  | 
| 131: | xoops_load('xoopsfile'); | 
| 132: |  | 
| 133: | $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/images/'; | 
| 134: | $folderHandler   = XoopsFile::getHandler('folder', $imagesDirectory); | 
| 135: | $folderHandler->delete($imagesDirectory); | 
| 136: |  | 
| 137: | $cssFile       = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname', 'n') . '/templates/style.css'; | 
| 138: | $folderHandler = XoopsFile::getHandler('file', $cssFile); | 
| 139: | $folderHandler->delete($cssFile); | 
| 140: |  | 
| 141: | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; | 
| 142: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 143: | } | 
| 144: |  | 
| 145: | if ($oldversion < '1.8.8') { | 
| 146: |  | 
| 147: | $tables = new Xmf\Database\Tables(); | 
| 148: | $tables->useTable('profile_field'); | 
| 149: | $criteria = new Criteria('field_name', 'user_sig', '='); | 
| 150: | $tables->update('profile_field', array('field_type' => 'dhtml'), $criteria); | 
| 151: | $tables->executeQueue(true); | 
| 152: | } | 
| 153: |  | 
| 154: | if ($oldversion < '1.9.2') { | 
| 155: |  | 
| 156: | $sql          = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('profile_field') . " CHANGE `field_name` `field_name` VARCHAR(64) NOT NULL DEFAULT ''"; | 
| 157: | $GLOBALS['xoopsDB']->queryF($sql); | 
| 158: |  | 
| 159: | } | 
| 160: |  | 
| 161: | $profile_handler = xoops_getModuleHandler('profile', $module->getVar('dirname', 'n')); | 
| 162: | $profile_handler->cleanOrphan($GLOBALS['xoopsDB']->prefix('users'), 'uid', 'profile_id'); | 
| 163: | $field_handler = xoops_getModuleHandler('field', $module->getVar('dirname', 'n')); | 
| 164: | $user_fields   = $field_handler->getUserVars(); | 
| 165: | $criteria      = new Criteria('field_name', "('" . implode("', '", $user_fields) . "')", 'IN'); | 
| 166: | $field_handler->updateAll('field_config', 0, $criteria); | 
| 167: |  | 
| 168: | return true; | 
| 169: | } | 
| 170: |  |