XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
avatar.php
Go to the documentation of this file.
1 <?php
18 defined('XOOPS_ROOT_PATH') or die('Restricted access');
19 
20 include_once $GLOBALS['xoops']->path( '/kernel/avatar.php' );
21 
29 {
30  function __construct()
31  {
32  parent::__construct();
33  }
34 
35  function getForm()
36  {
37  if ($this->isNew()) {
38  $blank_img = 'blank.gif';
39  } else {
40  $blank_img = str_replace( 'avatars/', '', $this->getVar('avatar_file', 'e') );
41  }
42  // Get User Config
43  $config_handler =& xoops_gethandler('config');
44  $xoopsConfigUser = $config_handler->getConfigsByCat( XOOPS_CONF_USER );
45  // New and edit form
46  $form = new XoopsThemeForm( _AM_SYSTEM_AVATAR_ADD, 'avatar_form', 'admin.php', "post", true );
47  $form->setExtra( 'enctype="multipart/form-data"' );
48  // Name
49  $form->addElement( new XoopsFormText( _IMAGENAME, 'avatar_name', 50, 255, $this->getVar('avatar_name', 'e') ), true );
50  // Name description
51  $maxpixel = '<div>' . _US_MAXPIXEL . '&nbsp;:&nbsp;' . $xoopsConfigUser['avatar_width'] . ' x ' . $xoopsConfigUser['avatar_height'] . '</div>';
52  $maxsize = '<div>' . _US_MAXIMGSZ . '&nbsp;:&nbsp;' . $xoopsConfigUser['avatar_maxsize'] . '</div>';
53  // Upload part
54  $imgtray_img = new XoopsFormElementTray( _IMAGEFILE, '<br />' );
55  $imgtray_img->setDescription( $maxpixel . $maxsize );
56  $imageselect_img = new XoopsFormSelect(sprintf( _AM_SYSTEM_AVATAR_USE_FILE, XOOPS_UPLOAD_PATH . '/avatars/'), 'avatar_file', $blank_img);
57  $image_array_img = XoopsLists::getImgListAsArray( XOOPS_UPLOAD_PATH . '/avatars' );
58  $imageselect_img->addOption("$blank_img", $blank_img);
59  foreach ($image_array_img as $image_img) {
60  $imageselect_img->addOption("$image_img", $image_img);
61  }
62  $imageselect_img->setExtra( "onchange='showImgSelected(\"xo-avatar-img\", \"avatar_file\", \"avatars\", \"\", \"" . XOOPS_UPLOAD_URL . "\")'");
63  $imgtray_img->addElement( $imageselect_img, false );
64  $imgtray_img->addElement( new XoopsFormLabel( '', "<br /><img src='" . XOOPS_UPLOAD_URL . "/avatars/" . $blank_img . "' name='image_img' id='xo-avatar-img' alt='' />" ) );
65  $fileseltray_img = new XoopsFormElementTray( '<br />','<br /><br />' );
66  $fileseltray_img->addElement( new XoopsFormFile( _AM_SYSTEM_AVATAR_UPLOAD, 'avatar_file', 500000 ), false);
67  $imgtray_img->addElement($fileseltray_img);
68  $form->addElement($imgtray_img);
69  // Weight
70  $form->addElement( new XoopsFormText( _IMGWEIGHT, 'avatar_weight', 3, 4, $this->getVar('avatar_weight', 'e') ) );
71  // Display
72  $form->addElement( new XoopsFormRadioYN( _IMGDISPLAY, 'avatar_display', $this->getVar('avatar_display', 'e'), _YES, _NO) );
73  // Hidden
74  if ( $this->isNew() ) {
75  $form->addElement( new XoopsFormHidden( 'avatar_type', 's') );
76  }
77  $form->addElement( new XoopsFormHidden( 'op', 'save') );
78  $form->addElement( new XoopsFormHidden( 'fct', 'avatars') );
79  $form->addElement( new XoopsFormHidden( 'avatar_id', $this->getVar('avatar_id', 'e') ) );
80  // Button
81  $form->addElement( new XoopsFormButton( '', 'avt_button', _SUBMIT, 'submit') );
82 
83  return $form;
84  }
85 
86 }
87 
99 {
100  function __construct($db)
101  {
102  parent::__construct($db);
103  $this->className = 'SystemAvatar';
104  }
105 
112  function &create($isNew = true)
113  {
114  $avatar = new SystemAvatar();
115  if ($isNew) {
116  $avatar->setNew();
117  }
118  return $avatar;
119  }
120 
127  function &get($id)
128  {
129  $avatar = false;
130  $id = intval($id);
131  if ($id > 0) {
132  $sql = 'SELECT * FROM ' . $this->db->prefix('avatar') . ' WHERE avatar_id=' . $id;
133  if (!$result = $this->db->query($sql)) {
134  return false;
135  }
136  $numrows = $this->db->getRowsNum($result);
137  if ($numrows == 1) {
138  $avatar = new SystemAvatar();
139  $avatar->assignVars($this->db->fetchArray($result));
140  return $avatar;
141  }
142  }
143  return $avatar;
144  }
145 }
146 
147 ?>