1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\FixedGroups;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25:
26: 27: 28: 29:
30: function xoops_module_install_profile($module)
31: {
32:
33: $xoops = Xoops::getInstance();
34: $xoops->registry()->set('profile_id', $module->getVar('mid'));
35:
36:
37: profile_install_addStep(_PROFILE_MI_STEP_BASIC, '', 1, 0);
38: profile_install_addStep(_PROFILE_MI_STEP_COMPLEMENTARY, '', 2, 1);
39:
40:
41: profile_install_addCategory(_PROFILE_MI_CATEGORY_PERSONAL, 1);
42: profile_install_addCategory(_PROFILE_MI_CATEGORY_MESSAGING, 2);
43: profile_install_addCategory(_PROFILE_MI_CATEGORY_SETTINGS, 3);
44: profile_install_addCategory(_PROFILE_MI_CATEGORY_COMMUNITY, 4);
45:
46: profile_install_addField('name', XoopsLocale::REAL_NAME, '', 1, 'textbox', 1, 1, 1, array(), 2, 255);
47: profile_install_addField('user_from', XoopsLocale::LOCATION, '', 1, 'textbox', 1, 2, 1, array(), 2, 255);
48: profile_install_addField('timezone', XoopsLocale::TIME_ZONE, '', 1, 'timezone', 1, 3, 1, array(), 2, 0);
49: profile_install_addField('user_occ', XoopsLocale::OCCUPATION, '', 1, 'textbox', 1, 4, 1, array(), 2, 255);
50: profile_install_addField('user_intrest', XoopsLocale::INTEREST, '', 1, 'textbox', 1, 5, 1, array(), 2, 255);
51: profile_install_addField('bio', XoopsLocale::EXTRA_INFO, '', 1, 'textarea', 2, 6, 1, array(), 2, 0);
52: profile_install_addField('user_regdate', XoopsLocale::MEMBER_SINCE, '', 1, 'datetime', 3, 7, 0, array(), 0, 10);
53:
54: profile_install_addField('user_icq', XoopsLocale::ICQ, '', 2, 'textbox', 1, 1, 1, array(), 2, 255);
55: profile_install_addField('user_aim', XoopsLocale::AIM, '', 2, 'textbox', 1, 2, 1, array(), 2, 255);
56: profile_install_addField('user_yim', XoopsLocale::YIM, '', 2, 'textbox', 1, 3, 1, array(), 2, 255);
57: profile_install_addField('user_msnm', XoopsLocale::MSNM, '', 2, 'textbox', 1, 4, 1, array(), 2, 255);
58:
59: profile_install_addField('user_viewemail', XoopsLocale::ALLOW_OTHER_USERS_TO_VIEW_EMAIL, '', 3, 'yesno', 3, 1, 1, array(), 2, 1, false);
60: profile_install_addField('attachsig', XoopsLocale::ALWAYS_ATTACH_MY_SIGNATURE, '', 3, 'yesno', 3, 2, 1, array(), 0, 1, false);
61: profile_install_addField('user_mailok', XoopsLocale::Q_RECEIVE_OCCASIONAL_EMAIL_NOTICES_FROM_ADMINISTRATORS, '', 3, 'yesno', 3, 3, 1, array(), 2, 1, false);
62: profile_install_addField('theme', _PROFILE_MA_THEME, '', 3, 'theme', 1, 4, 1, array(), 0, 0, false);
63:
64: profile_install_addField('url', _PROFILE_MI_URL_TITLE, '', 4, 'textbox', 1, 1, 1, array(), 2, 255);
65: profile_install_addField('posts', XoopsLocale::POSTS, '', 4, 'textbox', 3, 2, 0, array(), 0, 255);
66: profile_install_addField('rank', XoopsLocale::RANK, '', 4, 'rank', 3, 3, 2, array(), 0, 0);
67: profile_install_addField('last_login', XoopsLocale::LAST_LOGIN, '', 4, 'datetime', 3, 4, 0, array(), 0, 10);
68: profile_install_addField('user_sig', XoopsLocale::SIGNATURE, '', 4, 'textarea', 1, 5, 1, array(), 0, 0);
69:
70: profile_install_initializeProfiles();
71: return true;
72: }
73:
74: function profile_install_initializeProfiles()
75: {
76: $xoops = Xoops::getInstance();
77: $xoops->db();
78: global $xoopsDB;
79: $module_id = $xoops->registry()->get('profile_id');
80:
81: $xoopsDB->queryF("INSERT INTO " . $xoopsDB->prefix("profile_profile") . " (profile_id) " . " SELECT uid " . " FROM " . $xoopsDB->prefix("system_user"));
82:
83: $sql = "INSERT INTO " . $xoopsDB->prefix("system_permission") . " (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) " . " VALUES " . " (" . FixedGroups::ADMIN . ", " . FixedGroups::ADMIN . ", {$module_id}, 'profile_access'), " . " (" . FixedGroups::ADMIN . ", " . FixedGroups::USERS . ", {$module_id}, 'profile_access'), " . " (" . FixedGroups::USERS . ", " . FixedGroups::USERS . ", {$module_id}, 'profile_access'), " . " (" . FixedGroups::ANONYMOUS . ", " . FixedGroups::USERS . ", {$module_id}, 'profile_access') " . " ";
84: $xoopsDB->queryF($sql);
85:
86: }
87:
88:
89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99:
100: function profile_install_addField($name, $title, $description, $category, $type, $valuetype, $weight, $canedit, $options, $step_id, $length, $visible = true)
101: {
102: $xoops = Xoops::getInstance();
103: $module_id = $xoops->registry()->get('profile_id');
104:
105: $profilefield_handler = $xoops->getModuleHandler('field', 'profile');
106: $obj = $profilefield_handler->create();
107: $obj->setVar('field_name', $name);
108: $obj->setVar('field_moduleid', $module_id);
109: $obj->setVar('field_show', 1);
110: $obj->setVar('field_edit', $canedit ? 1 : 0);
111: $obj->setVar('field_config', 0);
112: $obj->setVar('field_title', strip_tags($title));
113: $obj->setVar('field_description', strip_tags($description));
114: $obj->setVar('field_type', $type);
115: $obj->setVar('field_valuetype', $valuetype);
116: $obj->setVar('field_options', $options);
117: if ($canedit) {
118: $obj->setVar('field_maxlength', $length);
119: }
120:
121: $obj->setVar('field_weight', $weight);
122: $obj->setVar('cat_id', $category);
123: $obj->setVar('step_id', $step_id);
124: $profilefield_handler->insert($obj);
125:
126: profile_install_setPermissions($obj->getVar('field_id'), $module_id, $canedit, $visible);
127:
128: return true;
129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161:
162: }
163:
164: 165: 166:
167: function profile_install_setPermissions($field_id, $module_id, $canedit, $visible)
168: {
169: $xoops = Xoops::getInstance();
170: $xoops->db();
171: global $xoopsDB;
172: $gperm_itemid = $field_id;
173: $gperm_modid = $module_id;
174: $sql = "INSERT INTO " . $xoopsDB->prefix("system_permission") . " (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) " . " VALUES " . ($canedit
175: ? " (" . FixedGroups::ADMIN . ", {$gperm_itemid}, {$gperm_modid}, 'profile_edit'), " : "") . ($canedit == 1
176: ? " (" . FixedGroups::USERS . ", {$gperm_itemid}, {$gperm_modid}, 'profile_edit'), "
177: : "") . " (" . FixedGroups::ADMIN . ", {$gperm_itemid}, {$gperm_modid}, 'profile_search'), " . " (" . FixedGroups::USERS . ", {$gperm_itemid}, {$gperm_modid}, 'profile_search') " . " ";
178: $xoopsDB->queryF($sql);
179:
180: if ($visible) {
181: $sql = "INSERT INTO " . $xoopsDB->prefix("profile_visibility")
182: . " (field_id, user_group, profile_group) "
183: . " VALUES "
184: . " ({$gperm_itemid}, " . FixedGroups::ADMIN . ", " . FixedGroups::ADMIN . "), "
185: . " ({$gperm_itemid}, " . FixedGroups::ADMIN . ", " . FixedGroups::USERS . "), "
186: . " ({$gperm_itemid}, " . FixedGroups::USERS . ", " . FixedGroups::ADMIN . "), "
187: . " ({$gperm_itemid}, " . FixedGroups::USERS . ", " . FixedGroups::USERS . "), "
188: . " ({$gperm_itemid}, " . FixedGroups::ANONYMOUS . ", " . FixedGroups::ADMIN . "), "
189: . " ({$gperm_itemid}, " . FixedGroups::ANONYMOUS . ", " . FixedGroups::USERS . ")" . " ";
190: $xoopsDB->queryF($sql);
191: }
192: }
193:
194: 195: 196:
197: function profile_install_addCategory($name, $weight)
198: {
199: $xoops = Xoops::getInstance();
200: $xoops->db();
201: global $xoopsDB;
202: $xoopsDB->query("INSERT INTO " . $xoopsDB->prefix("profile_category") . " VALUES (0, " . $xoopsDB->quote($name) . ", '', {$weight})");
203: }
204:
205: 206: 207: 208: 209:
210: function profile_install_addStep($name, $desc, $order, $save)
211: {
212: $xoops = Xoops::getInstance();
213: $xoops->db();
214: global $xoopsDB;
215: $xoopsDB->query("INSERT INTO " . $xoopsDB->prefix("profile_regstep") . " VALUES (0, " . $xoopsDB->quote($name) . ", " . $xoopsDB->quote($desc) . ", {$order}, {$save})");
216: }
217: