1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\Handlers\XoopsUser;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25:
26: 27: 28: 29: 30: 31: 32: 33:
34: function profile_getRegisterForm(XoopsUser $user, $profile, $step = null)
35: {
36: $xoops = Xoops::getInstance();
37: $action = $_SERVER['REQUEST_URI'];
38: $step_no = $step['step_no'];
39: $use_token = $step['step_no'] > 0 ? true : false;
40: $reg_form = new Xoops\Form\ThemeForm($step['step_name'], 'regform', $action, 'post', $use_token);
41:
42: if ($step['step_desc']) {
43: $reg_form->addElement(new Xoops\Form\Label('', $step['step_desc']));
44: }
45:
46: if ($step_no == 1) {
47:
48:
49: $elements[0][] = array(
50: 'element' => new Xoops\Form\Text(XoopsLocale::USERNAME, 'uname', 40, $xoops->getConfig('maxuname'), $user->getVar('uname', 'e')),
51: 'required' => true
52: );
53: $weights[0][] = 0;
54:
55: $elements[0][] = array(
56: 'element' => new Xoops\Form\Text(XoopsLocale::EMAIL, 'email', 40, 160, $user->getVar('email', 'e')), 'required' => true
57: );
58: $weights[0][] = 0;
59:
60: $elements[0][] =
61: array('element' => new Xoops\Form\Password(XoopsLocale::PASSWORD, 'pass'), 'required' => true);
62: $weights[0][] = 0;
63:
64: $elements[0][] =
65: array('element' => new Xoops\Form\Password(XoopsLocale::VERIFY_PASSWORD, 'vpass'), 'required' => true);
66: $weights[0][] = 0;
67: }
68:
69:
70:
71: $profile_handler = \Xoops::getModuleHelper('profile')->getHandler('profile');
72: $fields = $profile_handler->loadFields();
73: $_SESSION['profile_required'] = array();
74: $weights = array();
75:
76: foreach ($fields as $field) {
77: if ($field->getVar('step_id') == $step['step_id']) {
78: $fieldinfo['element'] = $field->getEditElement($user, $profile);
79:
80: if ($fieldinfo['required'] = $field->getVar('field_required')) {
81: $_SESSION['profile_required'][$field->getVar('field_name')] = $field->getVar('field_title');
82: }
83:
84: $key = $field->getVar('cat_id');
85: $elements[$key][] = $fieldinfo;
86: $weights[$key][] = $field->getVar('field_weight');
87: }
88: }
89: ksort($elements);
90:
91: foreach (array_keys($elements) as $k) {
92: array_multisort($weights[$k], SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]);
93: foreach (array_keys($elements[$k]) as $i) {
94: $reg_form->addElement($elements[$k][$i]['element'], $elements[$k][$i]['required']);
95: }
96: }
97:
98: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
99: if ($step_no == 1 && $xoops->getConfig('reg_dispdsclmr') != 0 && $xoops->getConfig('reg_disclaimer') != '') {
100: $disc_tray = new Xoops\Form\ElementTray(XoopsLocale::DISCLAIMER, '<br />');
101: $disc_text = new Xoops\Form\Label("", "<div class=\"pad5\">" . $myts->displayTarea($xoops->getConfig('reg_disclaimer'), 1) . "</div>");
102: $disc_tray->addElement($disc_text);
103: $agree_chk = new Xoops\Form\Checkbox('', 'agree_disc');
104: $agree_chk->addOption(1, XoopsLocale::I_AGREE_TO_THE_ABOVE);
105: $disc_tray->addElement($agree_chk);
106: $reg_form->addElement($disc_tray);
107: }
108:
109: if ($step_no == 1) {
110: $reg_form->addElement(new Xoops\Form\Captcha(), true);
111: }
112:
113: $reg_form->addElement(new Xoops\Form\Hidden('uid', $user->getVar('uid')));
114: $reg_form->addElement(new Xoops\Form\Hidden('step', $step_no));
115: $reg_form->addElement(new Xoops\Form\Button('', 'submitButton', XoopsLocale::A_SUBMIT, 'submit'));
116: return $reg_form;
117: }
118:
119:
120: 121: 122: 123: 124: 125: 126: 127:
128: function profile_getUserForm(XoopsUser $user, ProfileProfile $profile = null, $action = false)
129: {
130: $xoops = Xoops::getInstance();
131:
132: if ($action === false) {
133: $action = $_SERVER['REQUEST_URI'];
134: }
135:
136: $title = $user->isNew() ? _PROFILE_AM_ADDUSER : XoopsLocale::EDIT_PROFILE;
137:
138: $form = new Xoops\Form\ThemeForm($title, 'userinfo', $action, 'post', true);
139:
140:
141: $profile_handler = \Xoops::getModuleHelper('profile')->getHandler('profile');
142:
143: if (!$profile) {
144: $profile = $profile_handler->getProfile($user->getVar('uid'));
145: }
146:
147: $fields = $profile_handler->loadFields();
148:
149:
150: $gperm_handler = $xoops->getHandlerGroupPermission();
151: $editable_fields = $gperm_handler->getItemIds('profile_edit', $xoops->user->getGroups(), $xoops->module->getVar('mid'));
152:
153: if ($user->isNew() || $xoops->user->isAdmin()) {
154: $elements[0][] = array(
155: 'element' => new Xoops\Form\Text(XoopsLocale::USERNAME, 'uname', 40, $xoops->user->isAdmin() ? 60
156: : $xoops->getConfig('maxuname'), $user->getVar('uname', 'e')), 'required' => 1
157: );
158: $email_text = new Xoops\Form\Text('', 'email', 40, 160, $user->getVar('email'));
159: } else {
160: $elements[0][] = array('element' => new Xoops\Form\Label(XoopsLocale::USERNAME, $user->getVar('uname')), 'required' => 0);
161: $email_text = new Xoops\Form\Label('', $user->getVar('email'));
162: }
163: $email_tray = new Xoops\Form\ElementTray(XoopsLocale::EMAIL, '<br />');
164: $email_tray->addElement($email_text, ($user->isNew() || $xoops->user->isAdmin()) ? 1 : 0);
165: $weights[0][] = 0;
166: $elements[0][] = array('element' => $email_tray, 'required' => 0);
167: $weights[0][] = 0;
168:
169: if ($xoops->user->isAdmin() && $user->getVar('uid') != $xoops->user->getVar('uid')) {
170:
171: $pwd_text = new Xoops\Form\Password('', 'password');
172: $pwd_text2 = new Xoops\Form\Password('', 'vpass');
173: $pwd_tray = new Xoops\Form\ElementTray(XoopsLocale::PASSWORD . '<br />' . XoopsLocale::TYPE_NEW_PASSWORD_TWICE_TO_CHANGE_IT);
174: $pwd_tray->addElement($pwd_text);
175: $pwd_tray->addElement($pwd_text2);
176: $elements[0][] = array('element' => $pwd_tray, 'required' => 0);
177: $weights[0][] = 0;
178:
179: $level_radio = new Xoops\Form\Radio(_PROFILE_MA_USERLEVEL, 'level', $user->getVar('level'));
180: $level_radio->addOption(1, _PROFILE_MA_ACTIVE);
181: $level_radio->addOption(0, _PROFILE_MA_INACTIVE);
182:
183: $elements[0][] = array('element' => $level_radio, 'required' => 0);
184: $weights[0][] = 0;
185: }
186:
187: $elements[0][] = array('element' => new Xoops\Form\Hidden('uid', $user->getVar('uid')), 'required' => 0);
188: $weights[0][] = 0;
189: $elements[0][] = array('element' => new Xoops\Form\Hidden('op', 'save'), 'required' => 0);
190: $weights[0][] = 0;
191:
192: $cat_handler = \Xoops::getModuleHelper('profile')->getHandler('category');
193: $categories = array();
194: $all_categories = $cat_handler->getObjects(null, true, false);
195: $count_fields = count($fields);
196:
197: foreach ($fields as $field) {
198: if (in_array($field->getVar('field_id'), $editable_fields)) {
199:
200: if ($user->isNew()) {
201: $default = $field->getVar('field_default');
202: if ($default !== '' && $default !== null) {
203: $user->setVar($field->getVar('field_name'), $default);
204: }
205: }
206:
207: if ($profile->getVar($field->getVar('field_name'), 'n') === null) {
208: $default = $field->getVar('field_default', 'n');
209: $profile->setVar($field->getVar('field_name'), $default);
210: }
211:
212: $fieldinfo['element'] = $field->getEditElement($user, $profile);
213: $fieldinfo['required'] = $field->getVar('field_required');
214:
215: $key = @$all_categories[$field->getVar('cat_id')]['cat_weight'] * $count_fields + $field->getVar('cat_id');
216: $elements[$key][] = $fieldinfo;
217: $weights[$key][] = $field->getVar('field_weight');
218: $categories[$key] = @$all_categories[$field->getVar('cat_id')];
219: }
220: }
221:
222: if ($xoops->isUser() && $xoops->user->isAdmin()) {
223: $xoops->loadLanguage('admin', 'profile');
224: $gperm_handler = $xoops->getHandlerGroupPermission();
225:
226: include_once $xoops->path('modules/system/constants.php');
227: if ($gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $xoops->user->getGroups(), 1)) {
228:
229: $group_select = new Xoops\Form\SelectGroup(XoopsLocale::USER_GROUPS, 'groups', false, $user->getGroups(), 5, true);
230: $elements[0][] = array('element' => $group_select, 'required' => 0);
231:
232: $weights[0][] = $count_fields + 1;
233: }
234: }
235:
236: ksort($elements);
237: foreach (array_keys($elements) as $k) {
238: array_multisort($weights[$k], SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]);
239: $title = isset($categories[$k]) ? $categories[$k]['cat_title'] : _PROFILE_MA_DEFAULT;
240: $desc = isset($categories[$k]) ? $categories[$k]['cat_description'] : "";
241:
242: $desc = ($desc != '' ? ' - ' . $desc : '');
243: $form->insertBreak($title . $desc);
244: foreach (array_keys($elements[$k]) as $i) {
245: $form->addElement($elements[$k][$i]['element'], $elements[$k][$i]['required']);
246: }
247: }
248:
249: $form->addElement(new Xoops\Form\Hidden('uid', $user->getVar('uid')));
250: $form->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::SAVE_CHANGES, 'submit'));
251: return $form;
252: }
253: