23 include_once
$GLOBALS[
'xoops']->path(
'class/xoopsformloader.php');
26 if ( !is_object(
$GLOBALS[
'xoopsUser']) ) {
37 if (!
$GLOBALS[
'xoopsSecurity']->check()) {
44 if (
$GLOBALS[
'xoopsUser']->isAdmin()) {
45 $edituser->setVar(
'uname', trim(
$_POST[
'uname']) );
46 $edituser->setVar(
'email', trim(
$_POST[
'email']) );
65 $profile->setVar(
'profile_id', $edituser->getVar(
'uid'));
69 $fieldname =
$fields[
$i]->getVar(
'field_name');
70 if (in_array(
$fields[
$i]->getVar(
'field_id'), $editable_fields) && isset(
$_REQUEST[$fieldname])) {
73 $edituser->setVar($fieldname, $value);
75 $profile->setVar($fieldname, $value);
80 $stop = $edituser->getHtmlErrors();
83 $profile->setVar(
'profile_id', $edituser->getVar(
'uid'));
92 if (
$op ==
'editprofile') {
93 $xoopsOption[
'template_main'] =
'profile_editprofile.html';
94 include_once
$GLOBALS[
'xoops']->path(
'header.php');
95 include_once dirname(__FILE__) .
'/include/forms.php';
105 if (
$op ==
'avatarform') {
107 include
$GLOBALS[
'xoops']->path(
'header.php');
110 $oldavatar =
$GLOBALS[
'xoopsUser']->getVar(
'user_avatar');
111 if (!empty($oldavatar) && $oldavatar !=
'blank.gif') {
114 if (
$GLOBALS[
'xoopsConfigUser'][
'avatar_allow_upload'] == 1 &&
$GLOBALS[
'xoopsUser']->getVar(
'posts') >=
$GLOBALS[
'xoopsConfigUser'][
'avatar_minposts']) {
115 include_once
$GLOBALS[
'xoops']->path(
'class/xoopsformloader.php');
117 $form->setExtra(
'enctype="multipart/form-data"');
124 $form->assign($GLOBALS[
'xoopsTpl']);
127 $form2 =
new XoopsThemeForm(
_US_CHOOSEAVT,
'chooseavatar', XOOPS_URL .
'/modules/' . $GLOBALS[
'xoopsModule']->getVar(
'dirname',
'n') .
'/edituser.php',
'post',
true);
128 $avatar_select =
new XoopsFormSelect(
'',
'user_avatar', $GLOBALS[
'xoopsUser']->getVar(
'user_avatar'));
129 $avatar_list = $avatar_handler->getList(
'S',
true);
130 $avatar_selected = $GLOBALS[
'xoopsUser']->getVar(
"user_avatar",
"E");
131 $avatar_selected = in_array($avatar_selected, array_keys($avatar_list) ) ? $avatar_selected :
"blank.gif";
132 $avatar_select->addOptionArray($avatar_list);
133 $avatar_select->setExtra(
"onchange='showImgSelected(\"avatar\", \"user_avatar\", \"uploads\", \"\", \"" . XOOPS_URL .
"\")'");
135 $avatar_tray->addElement($avatar_select);
136 $avatar_tray->addElement(
new XoopsFormLabel(
'',
"<a href=\"javascript:openWithSelfMain('" . XOOPS_URL .
"/misc.php?action=showpopups&type=avatars','avatars',600,400);\">".
_LIST.
"</a><br />"));
137 $avatar_tray->addElement(
new XoopsFormLabel(
'',
"<br /><img src='" .
XOOPS_UPLOAD_URL .
"/" . $avatar_selected .
"' name='avatar' id='avatar' alt='' />"));
138 $form2->addElement($avatar_tray);
139 $form2->addElement(
new XoopsFormHidden(
'uid', $GLOBALS[
'xoopsUser']->getVar(
'uid')));
142 $form2->assign($GLOBALS[
'xoopsTpl']);
145 if (
$op ==
'avatarupload') {
146 if (!$GLOBALS[
'xoopsSecurity']->check()) {
150 $xoops_upload_file = array();
152 if (!empty(
$_POST[
'xoops_upload_file']) && is_array(
$_POST[
'xoops_upload_file'])){
153 $xoops_upload_file =
$_POST[
'xoops_upload_file'];
155 if (!empty(
$_POST[
'uid']) ) {
158 if (empty(
$uid) || $GLOBALS[
'xoopsUser']->getVar(
'uid') !=
$uid) {
162 if ($GLOBALS[
'xoopsConfigUser'][
'avatar_allow_upload'] == 1 && $GLOBALS[
'xoopsUser']->getVar(
'posts') >= $GLOBALS[
'xoopsConfigUser'][
'avatar_minposts']) {
163 include_once $GLOBALS[
'xoops']->path(
'class/uploader.php');
164 $uploader =
new XoopsMediaUploader(
XOOPS_UPLOAD_PATH .
'/avatars', array(
'image/gif',
'image/jpeg',
'image/pjpeg',
'image/x-png',
'image/png'), $GLOBALS[
'xoopsConfigUser'][
'avatar_maxsize'], $GLOBALS[
'xoopsConfigUser'][
'avatar_width'], $GLOBALS[
'xoopsConfigUser'][
'avatar_height']);
165 if ($uploader->fetchMedia(
$_POST[
'xoops_upload_file'][0])) {
166 $uploader->setPrefix(
'cavt');
167 if ($uploader->upload()) {
169 $avatar =& $avt_handler->create();
170 $avatar->setVar(
'avatar_file',
'avatars/' . $uploader->getSavedFileName());
171 $avatar->setVar(
'avatar_name', $GLOBALS[
'xoopsUser']->getVar(
'uname'));
172 $avatar->setVar(
'avatar_mimetype', $uploader->getMediaType());
173 $avatar->setVar(
'avatar_display', 1);
174 $avatar->setVar(
'avatar_type',
'C');
175 if (!$avt_handler->insert(
$avatar)) {
176 @unlink($uploader->getSavedDestination());
178 $oldavatar = $GLOBALS[
'xoopsUser']->getVar(
'user_avatar');
179 if (!empty($oldavatar) &&
false !== strpos(strtolower($oldavatar),
"cavt")) {
180 $avatars = $avt_handler->getObjects(
new Criteria(
'avatar_file', $oldavatar));
181 if (!empty($avatars) && count($avatars) == 1 && is_object($avatars[0])) {
182 $avt_handler->delete($avatars[0]);
184 if (0 === strpos($oldavatar_path,
XOOPS_UPLOAD_PATH) && is_file($oldavatar_path)) {
185 unlink($oldavatar_path);
189 $sql = sprintf(
"UPDATE %s SET user_avatar = %s WHERE uid = %u", $GLOBALS[
'xoopsDB']->prefix(
'users'), $GLOBALS[
'xoopsDB']->quoteString(
'avatars/' . $uploader->getSavedFileName() ), $GLOBALS[
'xoopsUser']->getVar(
'uid'));
190 $GLOBALS[
'xoopsDB']->query(
$sql);
191 $avt_handler->addUser(
$avatar->getVar(
'avatar_id'), $GLOBALS[
'xoopsUser']->getVar(
'uid'));
196 redirect_header(
"edituser.php?op=avatarform", 3, $uploader->getErrors() );
200 if (
$op ==
'avatarchoose') {
201 if (!$GLOBALS[
'xoopsSecurity']->check()) {
206 if (!empty(
$_POST[
'uid'])) {
209 if (empty(
$uid) || $GLOBALS[
'xoopsUser']->getVar(
'uid') !=
$uid) {
215 if (!empty(
$_POST[
'user_avatar'])) {
216 $user_avatar =
$myts->addSlashes(trim(
$_POST[
'user_avatar']));
218 $criteria_avatar->add(
new Criteria(
'avatar_type',
"S") );
219 $avatars = $avt_handler->getObjects($criteria_avatar);
220 if (!is_array($avatars) || !count($avatars)) {
221 $user_avatar =
'avatars/blank.gif';
223 unset($avatars, $criteria_avatar);
226 if (0 === strpos($user_avatarpath, realpath(
XOOPS_UPLOAD_PATH)) && is_file($user_avatarpath)) {
227 $oldavatar = $GLOBALS[
'xoopsUser']->getVar(
'user_avatar');
228 $GLOBALS[
'xoopsUser']->setVar(
'user_avatar', $user_avatar);
231 include $GLOBALS[
'xoops']->path(
'header.php');
232 echo $GLOBALS[
'xoopsUser']->getHtmlErrors();
233 include $GLOBALS[
'xoops']->path(
'footer.php');
236 if ($oldavatar && preg_match(
"/^cavt/", strtolower(substr($oldavatar,8)))) {
237 $avatars = $avt_handler->getObjects(
new Criteria(
'avatar_file', $oldavatar));
238 if (!empty($avatars) && count($avatars) == 1 && is_object($avatars[0])) {
239 $avt_handler->delete($avatars[0]);
241 if (0 === strpos($oldavatar_path, realpath(
XOOPS_UPLOAD_PATH)) && is_file($oldavatar_path)) {
242 unlink($oldavatar_path);
246 if ($user_avatar !=
'avatars/blank.gif') {
247 $avatars = $avt_handler->getObjects(
new Criteria(
'avatar_file', $user_avatar));
248 if (is_object($avatars[0])) {
249 $avt_handler->addUser($avatars[0]->getVar(
'avatar_id'), $GLOBALS[
'xoopsUser']->getVar(
'uid'));