1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17:
18:
19: include_once $GLOBALS['xoops']->path('/kernel/avatar.php');
20:
21: 22: 23: 24: 25: 26:
27: class SystemAvatar extends XoopsAvatar
28: {
29: 30: 31:
32: public function __construct()
33: {
34: parent::__construct();
35: }
36:
37: 38: 39:
40: public function getForm()
41: {
42: if ($this->isNew()) {
43: $blank_img = 'blank.gif';
44: } else {
45: $blank_img = str_replace('avatars/', '', $this->getVar('avatar_file', 'e'));
46: }
47:
48:
49: $config_handler = xoops_getHandler('config');
50: $xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
51:
52: $form = new XoopsThemeForm(_AM_SYSTEM_AVATAR_ADD, 'avatar_form', 'admin.php', 'post', true);
53: $form->setExtra('enctype="multipart/form-data"');
54:
55: $form->addElement(new XoopsFormText(_IMAGENAME, 'avatar_name', 50, 255, $this->getVar('avatar_name', 'e')), true);
56:
57: $maxpixel = '<div>' . _US_MAXPIXEL . ' : ' . $xoopsConfigUser['avatar_width'] . ' x ' . $xoopsConfigUser['avatar_height'] . '</div>';
58: $maxsize = '<div>' . _US_MAXIMGSZ . ' : ' . $xoopsConfigUser['avatar_maxsize'] . '</div>';
59:
60: $imgtray_img = new XoopsFormElementTray(_IMAGEFILE, '<br>');
61: $imgtray_img->setDescription($maxpixel . $maxsize);
62: $imageselect_img = new XoopsFormSelect(sprintf(_AM_SYSTEM_AVATAR_USE_FILE, XOOPS_UPLOAD_PATH . '/avatars/'), 'avatar_file', $blank_img);
63: $image_array_img = XoopsLists::getImgListAsArray(XOOPS_UPLOAD_PATH . '/avatars');
64: $imageselect_img->addOption("$blank_img", $blank_img);
65: foreach ($image_array_img as $image_img) {
66: $imageselect_img->addOption("$image_img", $image_img);
67: }
68: $imageselect_img->setExtra("onchange='showImgSelected(\"xo-avatar-img\", \"avatar_file\", \"avatars\", \"\", \"" . XOOPS_UPLOAD_URL . "\")'");
69: $imgtray_img->addElement($imageselect_img, false);
70: $imgtray_img->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_UPLOAD_URL . '/avatars/' . $blank_img . "' name='image_img' id='xo-avatar-img' alt='' />"));
71: $fileseltray_img = new XoopsFormElementTray('<br>', '<br><br>');
72: $fileseltray_img->addElement(new XoopsFormFile(_AM_SYSTEM_AVATAR_UPLOAD, 'avatar_file', 500000), false);
73: $imgtray_img->addElement($fileseltray_img);
74: $form->addElement($imgtray_img);
75:
76: $form->addElement(new XoopsFormText(_IMGWEIGHT, 'avatar_weight', 3, 4, $this->getVar('avatar_weight', 'e')));
77:
78: $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'avatar_display', $this->getVar('avatar_display', 'e'), _YES, _NO));
79:
80: if ($this->isNew()) {
81: $form->addElement(new XoopsFormHidden('avatar_type', 's'));
82: }
83: $form->addElement(new XoopsFormHidden('op', 'save'));
84: $form->addElement(new XoopsFormHidden('fct', 'avatars'));
85: $form->addElement(new XoopsFormHidden('avatar_id', $this->getVar('avatar_id', 'e')));
86:
87: $form->addElement(new XoopsFormButton('', 'avt_button', _SUBMIT, 'submit'));
88:
89: return $form;
90: }
91: }
92:
93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
103: class SystemAvatarHandler extends XoopsAvatarHandler
104: {
105: 106: 107:
108: public function __construct($db)
109: {
110: parent::__construct($db);
111: $this->className = 'SystemAvatar';
112: }
113:
114: 115: 116: 117: 118: 119:
120: public function create($isNew = true)
121: {
122: $avatar = new SystemAvatar();
123: if ($isNew) {
124: $avatar->setNew();
125: }
126:
127: return $avatar;
128: }
129:
130: 131: 132: 133: 134: 135:
136: public function get($id)
137: {
138: $avatar = false;
139: $id = (int)$id;
140: if ($id > 0) {
141: $sql = 'SELECT * FROM ' . $this->db->prefix('avatar') . ' WHERE avatar_id=' . $id;
142: if (!$result = $this->db->query($sql)) {
143: return false;
144: }
145: $numrows = $this->db->getRowsNum($result);
146: if ($numrows == 1) {
147: $avatar = new SystemAvatar();
148: $avatar->assignVars($this->db->fetchArray($result));
149:
150: return $avatar;
151: }
152: }
153:
154: return $avatar;
155: }
156: }
157: