update
This commit is contained in:
738
Admin/controller/UserController.php
Normal file
738
Admin/controller/UserController.php
Normal file
@@ -0,0 +1,738 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: UserController.php 969 2008-07-29 13:55:14Z pawy $
|
||||
* Zarzadzanie uzytkownikami
|
||||
*
|
||||
*/
|
||||
class UserController extends MainController implements ControllerInterface {
|
||||
|
||||
|
||||
|
||||
// cropper const
|
||||
const PHOTO_ORG_SMALL_SIZE = 70; // minimalny wymiar oryginalnego obrazka
|
||||
const MAX_PHOTO_ORG_FILE_SIZE = 5; // maksymalny rozmiar oryginalnego obrazka w mb
|
||||
|
||||
const CROPPER_MIN_SIZE = 70; // minimalny wymiar croppera
|
||||
const CROPPER_MAX_SIZE = 300; // maksymalny wymiar dla croppera
|
||||
|
||||
const PHOTO_SESSION_NAME = '__avatar_photo_name__';
|
||||
const PHOTO_SESSION_ID = '__avatar_photo_id__';
|
||||
const SIZE_SESSION_NAME = '__avatar_photo_size__';
|
||||
|
||||
const AVATAR_DEST_DIR = 'images/upload/Avatar';
|
||||
const AVATAR_TEMP_DIR = 'images/upload/temp/Avatar';
|
||||
|
||||
const GALLERY_DEST_DIR = 'images/upload/Avatar';
|
||||
const GALLERY_TEMP_DIR = 'images/upload/temp/Avatar';
|
||||
const NO_PHOTO_IMG_BIG = "image/Admin/cropperNoPhotoBig.gif";
|
||||
const NO_PHOTO_IMG_SMALL = "image/Admin/cropperNoPhotoSmall.gif";
|
||||
|
||||
|
||||
/**
|
||||
* Strona glowna
|
||||
*
|
||||
*/
|
||||
public function IndexAction($param) {
|
||||
|
||||
if(isset($param['sort']) && isset($param['direction']))
|
||||
$this->smarty->assign($param['sort'],$param['direction']);
|
||||
else {
|
||||
$param['sort'] = "";
|
||||
$param['direction'] = "";
|
||||
}
|
||||
|
||||
if(isset($param['sort2']) && isset($param['direction2']))
|
||||
$this->smarty->assign($param['sort2'],$param['direction2']);
|
||||
else {
|
||||
$param['sort2'] = "";
|
||||
$param['direction2'] = "";
|
||||
}
|
||||
|
||||
$this->smarty->assign('userList', AdminDAL::GetResult(array(),array(),null,$param['sort'] . " " . $param['direction']));
|
||||
|
||||
|
||||
$this->smarty->assign('archiveUserList', AdminDAL::GetResult(array('archive' => 1),array(),null,$param['sort2'] . " " . $param['direction2']));
|
||||
|
||||
}
|
||||
|
||||
public function JoinAction($param)
|
||||
{
|
||||
if(isset($param['sort']) && isset($param['direction']))
|
||||
$this->smarty->assign($param['sort'],$param['direction']);
|
||||
else
|
||||
{
|
||||
$param['sort'] = "";
|
||||
$param['direction'] = "";
|
||||
}
|
||||
$this->smarty->assign('type',$param['type']);
|
||||
$this->smarty->assign('ids',Request::Get($param['type']));
|
||||
$this->smarty->assign('UserList', AdminDAL::GetResult(array(),array(),null,$param['sort'] . " " . $param['direction']));
|
||||
}
|
||||
|
||||
public function AjaxJoinAction($param)
|
||||
{
|
||||
|
||||
foreach(Request::Get($param['type']) as $key2 => $value2)
|
||||
{
|
||||
MfLinkDAL::DeleteFromLink($value2, $param['type'], null , 'mf_admin');
|
||||
$i = 0;
|
||||
foreach(Request::Get('admin') as $key => $value)
|
||||
{
|
||||
//przypisujemy łączenia
|
||||
$mfLinkObj = new MfLink();
|
||||
$mfLinkObj->SetIdSource($value2);
|
||||
$mfLinkObj->SetSourceType($param['type']);
|
||||
$mfLinkObj->SetIdDestination($value);
|
||||
$mfLinkObj->SetDestinationType('mf_admin');
|
||||
|
||||
MfLinkDAL::Insert($mfLinkObj);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$className = str_replace('mf_','',$param['type']);
|
||||
$className = ucfirst($className);
|
||||
$obj = new $className();
|
||||
$obj->setId($value2);
|
||||
$obj->setAdminCount($i);
|
||||
|
||||
eval($className . 'DAL::Update($obj);');
|
||||
}
|
||||
|
||||
$this->SetAjaxRender();
|
||||
$param['hide']=false;
|
||||
$this->content=$this->FormatAjaxOutput(array(),$param);
|
||||
}
|
||||
|
||||
public function AjaxDeleteAction($param)
|
||||
{
|
||||
|
||||
foreach(Request::Get($param['type']) as $key2 => $value2)
|
||||
{
|
||||
MfLinkDAL::DeleteFromLink($value2, $param['type'], $param['mf_admin'] , 'mf_admin');
|
||||
|
||||
$this->user->SetForumCount($this->user->GetForumCount()-1);
|
||||
AdminDAL::Update($this->user);
|
||||
|
||||
$className = str_replace('mf_','',$param['type']);
|
||||
$className = ucfirst($className);
|
||||
$obj = null;
|
||||
eval('$obj =' .$className . 'DAL::GetById($value2);');
|
||||
$obj->SetAdminCount($obj->GetAdminCount() - 1);
|
||||
|
||||
eval($className . 'DAL::Update($obj);');
|
||||
}
|
||||
|
||||
$this->SetAjaxRender();
|
||||
$param['hide']=false;
|
||||
$this->content=$this->FormatAjaxOutput(array(),$param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edycja uzytkownika
|
||||
*
|
||||
* @param array $param
|
||||
*/
|
||||
public function EditAction($param) {
|
||||
|
||||
$url = Router::GenerateUrl('UserList',array('User' => 'Index'));
|
||||
|
||||
if(Request::IsPost()) {
|
||||
|
||||
// [login] =>
|
||||
// [password] =>
|
||||
// [passwordconf] =>
|
||||
// [firstName] =>
|
||||
// [lastName] =>
|
||||
// [email] =>
|
||||
// [description] =>
|
||||
// [role] => admin
|
||||
|
||||
$postData = Request::GetAllPost(false);
|
||||
|
||||
$user = AdminDAL::GetById($postData['id']);
|
||||
$user->SetLogin(Request::RemoveXss($postData['login']));
|
||||
$user->SetEmail(Request::RemoveXss($postData['email']));
|
||||
$user->SetFirstName($postData['firstName']);
|
||||
$user->SetLastName($postData['lastName']);
|
||||
$user->SetRole($postData['role']);
|
||||
$user->SetDescription($postData['description']);
|
||||
$pass = trim($postData['password']);
|
||||
|
||||
|
||||
|
||||
//if(Request::GetPost('action') == 'submit' ) {
|
||||
$validator = new Validator($postData);
|
||||
$validator->IsEmpty('login','To pole nie może być puste');
|
||||
|
||||
|
||||
// $validator->IsEmpty('firstName','To pole nie może być puste');
|
||||
// $validator->IsEmpty('lastName', 'To pole nie może być puste');
|
||||
//$validator->IsEmpty('email', 'To pole nie może być puste');
|
||||
//$validator->IsEmpty('role', 'To pole nie może być puste');
|
||||
if ($pass && md5($pass) != $user->GetPassword()) {
|
||||
$validator->IsEmpty('password','To pole nie może być puste');
|
||||
$validator->IsEmpty('passwordconf','To pole nie może być puste');
|
||||
if(Request::GetPost('passwordconf') !== Request::GetPost('password')) {
|
||||
$validator -> AddError('passwordconfDif', 'Hasła są różne');
|
||||
}
|
||||
}
|
||||
$out = $validator->GetErrorList();
|
||||
|
||||
|
||||
|
||||
$user->SetPassword(md5($pass));
|
||||
|
||||
if(empty($out)) {
|
||||
$postData = Request::GetAllPost(false);
|
||||
|
||||
$userId = AdminDAL::Save($user);
|
||||
|
||||
|
||||
$this->AddRedirectInfo('Edycja przebiegła pomyślnie.');
|
||||
|
||||
Utils::Redirect($url);
|
||||
|
||||
|
||||
|
||||
}else {
|
||||
//Utils::ArrayDisplay($out);
|
||||
$this->smarty->assign('userData',$user);
|
||||
foreach ($out as $item) {
|
||||
$error[$item['field']] = $item['msg'];
|
||||
}
|
||||
$this->smarty->assign('error',$error);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(isset($param['id']) && is_numeric($param['id']) ) {
|
||||
$user = AdminDAL::GetById($param['id']);
|
||||
} else {
|
||||
$user = new Admin();
|
||||
}
|
||||
|
||||
$this->smarty->assign('userData', $user );
|
||||
$this->smarty->assign('userRole', AdminDAL::GetArrayObjRoles());
|
||||
|
||||
}
|
||||
|
||||
public function AjaxEditFormAction($param) {
|
||||
|
||||
|
||||
|
||||
$this -> SetAjaxRender(true);
|
||||
|
||||
if(isset($param['id'])) {
|
||||
$id = $param['id'];
|
||||
SessionProxy::SetValue('editedUser', AdminDAL::GetById($id));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$url = Router::GenerateUrl(array('_value' => 'user'));
|
||||
|
||||
if(Request::IsPost()) {
|
||||
|
||||
if(isset($param['field'])) {
|
||||
$out = $this->ValidateEdit($param);
|
||||
$param['msg'] = 'Pole zostało zwalidowane';
|
||||
$this->content=$this->FormatAjaxOutput($out,$param);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Request::GetPost('action') == 'submit' ) {
|
||||
$out = $this -> ValidateEdit($param);
|
||||
$param['msg'] = 'Twoje zgłoszenie zostało przyjęte';
|
||||
|
||||
if(empty($out) && Request::GetPost('action') == 'submit' ) {
|
||||
$postData = Request::GetAllPost(false);
|
||||
$mail = Request::RemoveXss($postData['email']);
|
||||
|
||||
|
||||
$editedUser = AdminDAL::GetById($id);
|
||||
|
||||
$editedUser->SetEmail(Request::RemoveXss($postData['email']));
|
||||
$editedUser->SetFirstName($postData['firstName']);
|
||||
$editedUser->SetLastName($postData['lastName']);
|
||||
$editedUser->SetRole($postData['role']);
|
||||
$editedUser->SetDescription($postData['description']);
|
||||
|
||||
$photo = SessionProxy::GetValue(self::PHOTO_SESSION_ID);
|
||||
if($photo) {
|
||||
$obj->SetPhotoSrc($photo);
|
||||
SessionProxy::ClearValue(self::PHOTO_SESSION_ID);
|
||||
}
|
||||
|
||||
if(trim(Request::GetPost('password')) != '' && $editedUser->GetPassword() != md5(trim(Request::GetPost('password'))) ) {
|
||||
$pass = trim($postData['password']);
|
||||
$editedUser->SetPassword(md5($pass));
|
||||
}
|
||||
|
||||
$userId = AdminDAL::Save($editedUser);
|
||||
|
||||
|
||||
// $mailer = new Mailer();
|
||||
// $mailer->SendEmail($this->smarty->fetch('partial/Mail/RegisterMail.tpl'), '', 'Rejestracja konta',$postData['email']);
|
||||
|
||||
$this->AddRedirectInfo('Dodawanie użytkownika przebiegło pomyślnie.');
|
||||
|
||||
$param['redirect'] = $url;
|
||||
|
||||
$this->content=$this->FormatAjaxOutput($out,$param);
|
||||
|
||||
}else {
|
||||
$this->content=$this->FormatAjaxOutput($out,$param);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function ValidateEdit($param) {
|
||||
|
||||
$validator = new Validator(Request::GetAllPost());
|
||||
|
||||
$user = SessionProxy::GetValue('editedUser');
|
||||
|
||||
if(isset($param['field']) && !Request::Check(ereg_replace('((\[)(.*)(\]))','',urldecode($param['field'])))) {
|
||||
$validator -> AddError($param['field'], $this->GetDictionary('validator_field'));
|
||||
}
|
||||
|
||||
//e-mail
|
||||
if((isset($param['field']) && $param['field'] == 'email') || !isset($param['field']) ) {
|
||||
if($user->GetEmail() != Request::GetPost('email') )
|
||||
$validator -> IsNotInDatabase('email', $this->GetDictionary('validator_email_exist'), 'email');
|
||||
$validator -> IsEmailAddress('email', $this->GetDictionary('validator_email_error'));
|
||||
$validator -> IsEmpty('email',$this->GetDictionary('validator_email_empty'));
|
||||
}
|
||||
|
||||
if((isset($param['field']) && $param['field'] == 'password') || !isset($param['field']) ) {
|
||||
if(trim(Request::GetPost('password')) != '' ) {
|
||||
SessionProxy::SetValue('password',Request::GetPost('password'));
|
||||
$validator -> IsEmpty('password',$this->GetDictionary('validator_password_empty'));
|
||||
}
|
||||
}
|
||||
|
||||
//potwierdzenie hasła
|
||||
if((isset($param['field']) && $param['field'] == 'passwordconf') || !isset($param['field']) ) {
|
||||
if(trim(Request::GetPost('passwordconf')) != '' ) {
|
||||
|
||||
$password = SessionProxy::GetValue('password');
|
||||
if(!is_null($password) && Request::GetPost('passwordconf') !== $password && strlen(Request::GetPost('passwordconf')) > 0) {
|
||||
$validator -> AddError('passwordconf',$this->GetDictionary('validator_password_different'));
|
||||
}
|
||||
$validator -> IsEmpty('passwordconf',$this->GetDictionary('validator_password_empty'));
|
||||
}
|
||||
}
|
||||
|
||||
// if((isset($param['field']) && $param['field'] == 'education') || !isset($param['field']) ) {
|
||||
// $validator -> IsEmpty('education','Nie wybrano wykształcenia','education');
|
||||
// }
|
||||
|
||||
|
||||
// $param['submitForm'] = 'walidacja';
|
||||
return $validator->GetErrorList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dodawanie uzytkownika
|
||||
*
|
||||
* @param array $param
|
||||
*/
|
||||
public function AddAction($param) {
|
||||
|
||||
|
||||
|
||||
|
||||
$url = Router::GenerateUrl('UserList',array('User' => 'Index'));
|
||||
|
||||
//Utils::ArrayDisplay($_POST);
|
||||
|
||||
if(Request::IsPost()) {
|
||||
|
||||
// [login] =>
|
||||
// [password] =>
|
||||
// [passwordconf] =>
|
||||
// [firstName] =>
|
||||
// [lastName] =>
|
||||
// [email] =>
|
||||
// [description] =>
|
||||
// [role] => admin
|
||||
|
||||
$postData = Request::GetAllPost(false);
|
||||
//if(Request::GetPost('action') == 'submit' ) {
|
||||
$validator = new Validator($postData);
|
||||
$validator->IsEmpty('login','To pole nie może być puste');
|
||||
$validator->IsEmpty('password','To pole nie może być puste');
|
||||
$validator->IsEmpty('passwordconf','To pole nie może być puste');
|
||||
$validator->IsEmpty('firstName','To pole nie może być puste');
|
||||
$validator->IsEmpty('lastName', 'To pole nie może być puste');
|
||||
$validator->IsEmpty('email', 'To pole nie może być puste');
|
||||
$validator->IsEmpty('role', 'To pole nie może być puste');
|
||||
if(Request::GetPost('passwordconf') !== Request::GetPost('password')) {
|
||||
$validator -> AddError('passwordconfDif', 'Hasła są róne');
|
||||
}
|
||||
$out = $validator->GetErrorList();
|
||||
|
||||
if(empty($out)) {
|
||||
$postData = Request::GetAllPost(false);
|
||||
$mail = Request::RemoveXss($postData['email']);
|
||||
|
||||
|
||||
$newuser = new Admin();
|
||||
$newuser->SetId(-1);
|
||||
$newuser->SetLogin(Request::RemoveXss($postData['login']));
|
||||
$newuser->SetEmail(Request::RemoveXss($postData['email']));
|
||||
$newuser->SetFirstName($postData['firstName']);
|
||||
$newuser->SetLastName($postData['lastName']);
|
||||
$newuser->SetRole($postData['role']);
|
||||
$newuser->SetDescription($postData['description']);
|
||||
|
||||
$pass = trim($postData['password']);
|
||||
$newuser->SetPassword(md5($pass));
|
||||
|
||||
$userId = AdminDAL::Save($newuser);
|
||||
|
||||
|
||||
$this->AddRedirectInfo('Dodawanie użytkownika przebiegło pomyślnie.');
|
||||
|
||||
Utils::Redirect($url);
|
||||
|
||||
|
||||
|
||||
}else {
|
||||
//Utils::ArrayDisplay($out);
|
||||
$this->smarty->assign('user',$postData);
|
||||
foreach ($out as $item) {
|
||||
$error[$item['field']] = $item['msg'];
|
||||
}
|
||||
$this->smarty->assign('error',$error);
|
||||
|
||||
}
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->smarty->assign('userRole', AdminDAL::GetArrayObjRoles());
|
||||
|
||||
}
|
||||
|
||||
public function AjaxAddFormAction($param) {
|
||||
|
||||
$this -> SetAjaxRender(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function ValidateAdd($param) {
|
||||
|
||||
$validator = new Validator(Request::GetAllPost());
|
||||
if(isset($param['field']) && !Request::Check(ereg_replace('((\[)(.*)(\]))','',urldecode($param['field'])))) {
|
||||
$validator -> AddError($param['field'], $this->GetDictionary('validator_field'));
|
||||
}
|
||||
|
||||
//e-mail
|
||||
if((isset($param['field']) && $param['field'] == 'email') || !isset($param['field']) ) {
|
||||
|
||||
$validator -> IsNotInDatabase('email', $this->GetDictionary('validator_email_exist'), 'email');
|
||||
$validator -> IsEmailAddress('email', $this->GetDictionary('validator_email_error'));
|
||||
$validator -> IsEmpty('email',$this->GetDictionary('validator_email_empty'));
|
||||
}
|
||||
|
||||
if((isset($param['field']) && $param['field'] == 'password') || !isset($param['field']) ) {
|
||||
SessionProxy::SetValue('password',Request::GetPost('password'));
|
||||
$validator -> IsEmpty('password',$this->GetDictionary('validator_password_empty'));
|
||||
}
|
||||
|
||||
//potwierdzenie hasła
|
||||
if((isset($param['field']) && $param['field'] == 'passwordconf') || !isset($param['field']) ) {
|
||||
|
||||
$password = SessionProxy::GetValue('password');
|
||||
if(!is_null($password) && Request::GetPost('passwordconf') !== $password && strlen(Request::GetPost('passwordconf')) > 0) {
|
||||
$validator -> AddError('passwordconf',$this->GetDictionary('validator_password_different'));
|
||||
}
|
||||
$validator -> IsEmpty('passwordconf',$this->GetDictionary('validator_password_empty'));
|
||||
|
||||
}
|
||||
|
||||
// if((isset($param['field']) && $param['field'] == 'education') || !isset($param['field']) ) {
|
||||
// $validator -> IsEmpty('education','Nie wybrano wykształcenia','education');
|
||||
// }
|
||||
|
||||
|
||||
// $param['submitForm'] = 'walidacja';
|
||||
return $validator->GetErrorList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Usuwanie uzytkownika
|
||||
*
|
||||
* @param array $param
|
||||
*/
|
||||
public function DeleteAction($param) {
|
||||
$this->SetAjaxRender(true);
|
||||
if(isset($param['ok'])) {
|
||||
|
||||
$res = null;
|
||||
if(isset($param['id'])) {
|
||||
$res = AdminDAL::GetById($param['id']);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if(is_object($res)) {
|
||||
AdminDAL::Delete($res);
|
||||
}
|
||||
|
||||
$this->AddRedirectInfo('Użytkownik został usunięty');
|
||||
$this->AddRedirect(Router::GenerateUrl('userIndex', array('User'=>'Index')), 0);
|
||||
|
||||
} else {
|
||||
$buttons = new HtmlButton();
|
||||
$buttons->AddButton('popoverAbort', 'button anuluj lbAction', 'Anuluj', null, 'deactivate');
|
||||
$buttons->AddButton('popoverOk', 'button zapisz', 'Ok', 'document.location.href=\''.Router::GenerateUrl(array('User'=>'Delete', 'id'=>$param['id'], 'ok'=>'1')).'\';', null);
|
||||
$this->content = $this->GeneratePopover('Usuwanie użytkownika', 'usun.gif', 'Czy na pewno chcesz usunąć tego użytkownika?', $buttons->GetElements());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Zmiana hasla
|
||||
*
|
||||
*/
|
||||
public function ChangePasswordAction() {
|
||||
$this->AddScript('prototype.js');
|
||||
$this->AddScript('scriptaculous.js');
|
||||
|
||||
$this->partialTemplate = 'Password.tpl';
|
||||
$this->smarty->assign('msg', '');
|
||||
|
||||
if(isset($_POST['oldPassword']) && isset($_POST['newPassword']) && isset($_POST['confirmPassword'])) {
|
||||
$admin = AuthDAL::GetAdmin();
|
||||
if(AdminDAL::CheckPassword($admin->GetId(), $_POST['oldPassword'])) {
|
||||
AdminDAL::UpdatePassword($admin->GetId(), $_POST['newPassword'], $_POST['oldPassword']);
|
||||
$this->smarty->assign('msg', 'Hasło zostało zmienione');
|
||||
} else {
|
||||
$this->smarty->assign('msg', 'Podano nieprawidłowe hasło. Spróbuj ponownie.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Wspolna metoda
|
||||
*
|
||||
*/
|
||||
public function preDispatch($param) {
|
||||
$this->RunShared('Auth', $param);
|
||||
$this->Run($param);
|
||||
$admin = AuthDAL::GetAdmin();
|
||||
$this->user = $admin;
|
||||
|
||||
$this->smarty->assign('titleAdmin', 'Administracja');
|
||||
|
||||
$panelMenu = ARRAY_PANEL_MENU;
|
||||
$struct = $panelMenu['admin'];
|
||||
|
||||
$this->smarty->assign('structure',$this->renderStruct($struct));
|
||||
|
||||
}
|
||||
|
||||
private function renderStruct($struct){
|
||||
$return = '';
|
||||
|
||||
foreach($struct AS $k => $row){
|
||||
$return .= '<li><a href="' . Router::GenerateUrl('dictpig',$row).'">'.$k.'</a></li>';
|
||||
}
|
||||
|
||||
$html = '<ul>';
|
||||
$html .= $return;
|
||||
$html .= '</ul>';
|
||||
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function postDispatch($param) {
|
||||
|
||||
}
|
||||
|
||||
// cropper
|
||||
// cropper //
|
||||
|
||||
public function AjaxPhotoCropperAction($param) {
|
||||
$this->SetAjaxRender();
|
||||
|
||||
$photoPath = Request::GetPost('photoPath');
|
||||
$photoHeight = Request::GetPost('photoHeight');
|
||||
$photoWidth = Request::GetPost('photoWidth');
|
||||
|
||||
$this->smarty->assign('photoWidth', $photoWidth);
|
||||
$this->smarty->assign('photoHeight', $photoHeight);
|
||||
|
||||
$this->smarty->assign('minPhotoWidth', self::CROPPER_MIN_SIZE);
|
||||
$this->smarty->assign('minPhotoHeight', self::CROPPER_MIN_SIZE);
|
||||
|
||||
$this->smarty->assign('noPhotoImgBig', URL_STATIC_CONTENT . URL_DELIMITER . self::NO_PHOTO_IMG_BIG);
|
||||
$this->smarty->assign('noPhotoImgSmall', URL_STATIC_CONTENT . URL_DELIMITER . self::NO_PHOTO_IMG_SMALL);
|
||||
|
||||
$this->smarty->assign('photoPath', Request::GetPost('photoPath'));
|
||||
if (isset($param['id'])) {
|
||||
$this->smarty->assign('cutUrl', array('user' => 'AjaxPhotoCropped', 'id' => $param['id']));
|
||||
} else {
|
||||
$this->smarty->assign('cutUrl', array('user' => 'AjaxPhotoCropped'));
|
||||
}
|
||||
|
||||
$this->smarty->assign('fields',
|
||||
array(
|
||||
0 => array('name'=>'colSize', 'type'=>'radio', 'value'=>1, 'label'=>'pół kolumny', 'options'=>'checked="checked"'),
|
||||
1 => array('name'=>'colSize', 'type'=>'radio', 'value'=>2, 'label'=>'cała kolumna', 'options'=>''),
|
||||
2 => array('name'=>'colSize', 'type'=>'radio', 'value'=>3, 'label'=>'bez skalowania', 'options'=>''),
|
||||
)
|
||||
);
|
||||
|
||||
$this->smarty->assign('uploadUrl', array('user' => 'AjaxPhotoUpload'));
|
||||
}
|
||||
|
||||
public function AjaxPhotoCroppedAction($param) {
|
||||
$upload = true;
|
||||
$oldPhoto = null;
|
||||
|
||||
|
||||
$redirect = 'self';
|
||||
$this->SetAjaxRender();
|
||||
|
||||
$photoFile = SessionProxy::GetValue(self::PHOTO_SESSION_NAME);
|
||||
SessionProxy::ClearValue(self::PHOTO_SESSION_NAME);
|
||||
$tmpPhotoArray = array();
|
||||
$tmpPhotoArray['name'] = $photoFile . '.' . PhotoDAL::PHOTO_NEW_EXT;
|
||||
$tmpPhotoArray['tmp_name'] = Config::Get('PATH_STATIC_CONTENT') . self::GALLERY_TEMP_DIR . DIRECTORY_SEPARATOR . $tmpPhotoArray['name'];
|
||||
|
||||
$croppSize = SessionProxy::GetValue(self::SIZE_SESSION_NAME);
|
||||
SessionProxy::ClearValue(self::SIZE_SESSION_NAME);
|
||||
$orgSize = getimagesize($tmpPhotoArray['tmp_name']);
|
||||
|
||||
$sc = 1;
|
||||
if($upload) {
|
||||
if($orgSize[0] != $croppSize['w']) {
|
||||
$sc = $orgSize[0]/$croppSize['w'];
|
||||
}
|
||||
} else {
|
||||
$cs = getimagesize(Config::Get('PATH_STATIC_CONTENT') . self::GALLERY_TEMP_DIR . DIRECTORY_SEPARATOR . $oldPhoto[0]->GetPhoto('temp') . '.' . PhotoDAL::PHOTO_NEW_EXT);
|
||||
if($orgSize[0] != $cs[0]) {
|
||||
$sc = $orgSize[0] / $cs[0];
|
||||
}
|
||||
}
|
||||
|
||||
$croppArray = array(
|
||||
'x' => Request::Get('x') * $sc,
|
||||
'y' => Request::Get('y') * $sc,
|
||||
'w' => Request::Get('w') * $sc,
|
||||
'h' => Request::Get('h') * $sc
|
||||
);
|
||||
|
||||
$destDir = self::GALLERY_DEST_DIR;
|
||||
|
||||
|
||||
$photo = PhotoDAL::ExtSimplePhotoUpload($tmpPhotoArray, $destDir, 'user', null, null, $croppArray);
|
||||
|
||||
$id = null;
|
||||
|
||||
// $objPhoto = new Picture();
|
||||
// $objPhoto->SetLink($photoFile);
|
||||
// $idPhoto = PictureDAL::Insert($objPhoto);
|
||||
if (isset($param['id'])) {
|
||||
|
||||
$admin = AdminDAL::GetById($param['id']);
|
||||
$admin->SetPhotoSrc($photoFile);
|
||||
AdminDAL::Save($admin);
|
||||
|
||||
// $articleObj = MfArticleDAL::GetById($param['id']);
|
||||
// $articleObj->SetIdPicture($idPhoto);
|
||||
// MfArticleDAL::Save($articleObj);
|
||||
} else {
|
||||
SessionProxy::SetValue(self::PHOTO_SESSION_ID, $photoFile);
|
||||
}
|
||||
|
||||
if(isset($param['id'])) {
|
||||
$redirect = Router::GenerateUrl(array('user'=>'Edit', 'id'=>$param['id']));
|
||||
} else {
|
||||
$redirect = Router::GenerateUrl(array('user'=>'Edit'));
|
||||
}
|
||||
$this->smarty->assign('photoPath', $photoFile);
|
||||
$this->smarty->assign('redirect', null);
|
||||
}
|
||||
|
||||
public function AjaxPhotoUploadAction($param) {
|
||||
|
||||
$this->SetAjaxRender();
|
||||
$photoFile = $_FILES['photo']['tmp_name'];
|
||||
$photoSize = getimagesize($photoFile);
|
||||
|
||||
if ($photoSize[0] < self::PHOTO_ORG_SMALL_SIZE) {
|
||||
$error = "Szerokość zdjęcia jest zbyt mała.";
|
||||
} else if($photoSize[1] < self::PHOTO_ORG_SMALL_SIZE) {
|
||||
$error = "Wysokość zdjęcia jest zbyt mała.";
|
||||
} else if (filesize($photoFile) > (self::MAX_PHOTO_ORG_FILE_SIZE*1048576)) {
|
||||
$error = "Przekroczony rozmiar zdjęcia(max: " . self::MAX_PHOTO_ORG_FILE_SIZE . "MB).";
|
||||
}
|
||||
|
||||
if (!MimeType::IsImage($_FILES['photo'])) {
|
||||
$error = "Podany przez ciebie plik ma niepoprawny format.";
|
||||
}
|
||||
|
||||
if (isset($error)) {
|
||||
$this->smarty->assign('error', $error);
|
||||
} else {
|
||||
|
||||
$photoProp = $photoSize[0] / $photoSize[1];
|
||||
|
||||
$photoWidth = $photoSize[0];
|
||||
$photoHeight = $photoSize[1];
|
||||
|
||||
|
||||
if ($photoWidth > self::CROPPER_MAX_SIZE) {
|
||||
$photoHeight = self::CROPPER_MAX_SIZE / $photoProp;
|
||||
$photoWidth = self::CROPPER_MAX_SIZE;
|
||||
}
|
||||
|
||||
if ($photoHeight > self::CROPPER_MAX_SIZE) {
|
||||
$photoWidth = self::CROPPER_MAX_SIZE * $photoProp;
|
||||
$photoHeight = self::CROPPER_MAX_SIZE;
|
||||
}
|
||||
|
||||
$newName = md5(time());
|
||||
SessionProxy::SetValue(self::PHOTO_SESSION_NAME, $newName);
|
||||
SessionProxy::SetValue(self::SIZE_SESSION_NAME, array('w' => $photoWidth, 'h' => $photoHeight));
|
||||
|
||||
$photoFile = PhotoDAL::ExtSimplePhotoUpload($_FILES['photo'], self::GALLERY_TEMP_DIR , 'gallery_cropp_temporary', $newName, 'temp');
|
||||
$photoFile = self::GALLERY_TEMP_DIR . URL_DELIMITER . $photoFile;
|
||||
|
||||
$this->smarty->assign('page2load', Router::GenerateUrl(array('zdjecia' => 'edycja')));
|
||||
$this->smarty->assign('photoFile', $photoFile);
|
||||
$this->smarty->assign('photoWidth', (int)$photoWidth);
|
||||
$this->smarty->assign('photoHeight', (int)$photoHeight);
|
||||
$this->smarty->assign('onFly', (Request::Check('onFly') ? 'true' : 'false'));
|
||||
$this->smarty->assign('cropPrefix', Request::GetPost('cropPrefix'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user