function saveinfo() { $juser =& JFactory::getUser(); if ($juser->guest) { $error = 'Bạn phải đăng nhập để thực hiện chức năng này'; $this->setError($error); return false; } $post = JRequest::get('post'); $data = array(); $data['user_id'] = $juser->id; $data['couple_name'] = $post['couple_name']; $data['address'] = $post['address']; $data['country'] = $post['country']; if (isset($_FILES['avatar']) && $_FILES['avatar']['error'] == 0) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'thumb.php'; $p = manThumb::resize($_FILES['avatar']['tmp_name'], 96, 96); $name = 'avatar_' . $juser->id . '.jpg'; $file = JPATH_ROOT . DS . 'images' . DS . 'wedding' . DS . 'avatar' . DS . $name; imagejpeg($p, $file, 90); imagedestroy($p); $data['avatar'] = 'images/wedding/avatar/' . $name; } $row =& $this->getTable('users'); if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }
function save() { $db =& JFactory::getDbo(); $data = JRequest::get('post'); $data['intro'] = JRequest::getVar('intro', '', '', 'string', JREQUEST_ALLOWHTML); $data['content'] = JRequest::getVar('content', '', '', 'string', JREQUEST_ALLOWHTML); $row =& $this->getTable('diary'); $juser =& JFactory::getUser(); if (isset($data['id']) && $data['id'] > 0) { $row->load($data['id']); if ($row->user_id != $juser->id) { $error = 'Bạn không có quyền ghi nội dung này'; $this->setError($error); return false; } } else { $data['created_date'] = date('Y-m-d H:i:s'); } $data['modified_date'] = date('Y-m-d H:i:s'); $data['user_id'] = $juser->id; if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'thumb.php'; $p = manThumb::resize($_FILES['image']['tmp_name'], 540); if (!empty($data['old_image']) && file_exists($data['old_image'])) { unlink($data['old_image']); } jimport('joomla.filesystem.folder'); $file = JPATH_ROOT . DS . 'images' . DS . 'wedding' . DS . 'diary' . DS; if (!JFolder::exists($file)) { JFolder::create($file, 777); } $time = time(); $sfile = $file . 'diary-' . $juser->id . $time . '.jpg'; imagejpeg($p, $sfile, 90); imagedestroy($p); $data['image'] = 'images/wedding/diary/diary-' . $juser->id . $time . '.jpg'; } //echo '<pre>'; print_r($data); die; if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }
function save() { $db =& JFactory::getDbo(); $data = JRequest::get('post'); $data['intro'] = JRequest::getVar('intro', '', '', 'string', JREQUEST_ALLOWHTML); $data['content'] = JRequest::getVar('content', '', '', 'string', JREQUEST_ALLOWHTML); $row =& $this->getTable('home'); $juser =& JFactory::getUser(); if (isset($data['id']) && $data['id'] > 0) { $row->load($data['id']); if ($row->user_id != $juser->id) { $error = 'Bạn không có quyền ghi nội dung này'; $this->setError($error); return false; } } else { $data['id'] = null; require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'user.php'; $content = userHelpers::getContent($juser->id); if (!empty($content) && $content->id > 0) { $data['id'] = $content->id; } } $data['user_id'] = $juser->id; if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'thumb.php'; $p = manThumb::resize($_FILES['image']['tmp_name'], 540); jimport('joomla.filesystem.folder'); $file = JPATH_ROOT . DS . 'images' . DS . 'wedding' . DS . 'home' . DS; //; if (!JFolder::exists($file)) { JFolder::create($file, 755); } imagejpeg($p, $file . 'home-' . $juser->id . '.jpg', 90); imagedestroy($p); $data['image'] = 'images/wedding/home/home-' . $juser->id . '.jpg'; } if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }
function savephoto() { $juser =& JFactory::getUser(); $db =& JFactory::getDbo(); $data = JRequest::get('post'); $data['photos'] = null; $data['thumbnail'] = null; if (isset($data['album_id'])) { $query = "SELECT user_id FROM #__wedding_albums WHERE id = {$data['album_id']} LIMIT 1"; $db->setQuery($query); $user_id = $db->loadResult(); if ($juser->id != $user_id) { $this->setError('Bạn không có quyền ghi nội dung này'); return false; } } else { $this->setError('Bạn không có quyền ghi nội dung này'); return false; } if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'thumb.php'; try { $p = manThumb::resize($_FILES['image']['tmp_name'], 160, 120); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } jimport('joomla.filesystem.folder'); $file = JPATH_BASE . DS . 'images' . DS . 'wedding' . DS . 'album' . DS; if (!JFolder::exists($file)) { JFolder::create($file, 755); } $time = time(); $sfile = $file . 'photo-' . $data['album_id'] . $time . '.jpg'; $tfile = $file . 'thumb-' . $juser->id . $time . '.jpg'; if (!imagejpeg($p, $tfile, 90)) { imagedestroy($p); $this->setError('Lưu file bị lỗi'); return false; } imagedestroy($p); try { $p = manThumb::resize($_FILES['image']['tmp_name'], 1100); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } if (!imagejpeg($p, $sfile, 90)) { imagedestroy($p); $this->setError('Lưu file bị lỗi'); return false; } imagedestroy($p); $data['thumbnail'] = 'images/wedding/album/thumb-' . $juser->id . $time . '.jpg'; $data['photos'] = 'images/wedding/album/photo-' . $data['album_id'] . $time . '.jpg'; $data['created_date'] = date('Y-m-d H:i:s', $time); $row = $this->getTable('photo'); if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } else { $msg = 'Upload file thất bại, hãy thử lại với file có kích thước nhỏ hơn'; $this->setError($msg); return false; } }