/** * Create and download db bakcup * * @before _secured, _admin */ public function createDatabaseBackup() { $view = $this->getActionView(); $dump = new Mysqldump(array('exclude-tables' => array('tb_user'))); $fm = new FileManager(); if (!is_dir(APP_PATH . '/temp/db/')) { $fm->mkdir(APP_PATH . '/temp/db/'); } $dump->create(); $view->successMessage('Záloha databáze byla úspěšně vytvořena'); Event::fire('admin.log', array('success', 'Database backup ' . $dump->getBackupName())); self::redirect('/admin/system/'); }
/** * @before _secured, _admin * @param type $id */ public function edit($id) { $view = $this->getActionView(); $user = App_Model_User::first(array('id = ?' => (int) $id)); if (NULL === $user) { $view->warningMessage(self::ERROR_MESSAGE_2); $this->_willRenderActionView = false; self::redirect('/admin/user/'); } elseif ($user->role == 'role_superadmin' && $this->getUser()->getRole() != 'role_superadmin') { $view->warningMessage(self::ERROR_MESSAGE_4); $this->_willRenderActionView = false; self::redirect('/admin/user/'); } $dogs = App_Model_Dog::fetchAllDogsByUserId($user->getId()); $view->set('user', $user)->set('dogs', $dogs); if (RequestMethods::post('submitEditUser')) { if ($this->checkCSRFToken() !== true) { self::redirect('/admin/user/'); } $errors = array(); if (RequestMethods::post('password') !== RequestMethods::post('password2')) { $errors['password2'] = array('Hesla se neshodují'); } if (RequestMethods::post('email') != $user->email) { $email = App_Model_User::first(array('email = ?' => RequestMethods::post('email', $user->email)), array('email')); if ($email) { $errors['email'] = array('Tento email je již použit'); } } $pass = RequestMethods::post('password'); if ($pass === null || $pass == '') { $salt = $user->getSalt(); $hash = $user->getPassword(); } else { $salt = PasswordManager::createSalt(); $hash = PasswordManager::hashPassword($pass, $salt); } if ($user->imgMain == '') { $cfg = Registry::get('configuration'); $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight)); $photoNameRaw = RequestMethods::post('firstname') . '-' . RequestMethods::post('lastname'); $photoName = $this->_createUrlKey($photoNameRaw); $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'members', time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $imgMain = trim($file->getFilename(), '.'); $imgThumb = trim($file->getThumbname(), '.'); break; } } } else { $errors['croppedimage'] = $fileErrors; } } else { $imgMain = $user->imgMain; $imgThumb = $user->imgThumb; } $user->firstname = RequestMethods::post('firstname'); $user->lastname = RequestMethods::post('lastname'); $user->email = RequestMethods::post('email'); $user->password = $hash; $user->salt = $salt; $user->imgMain = $imgMain; $user->imgThumb = $imgThumb; $user->role = RequestMethods::post('role', $user->getRole()); $user->active = RequestMethods::post('active'); if (empty($errors) && $user->validate()) { $user->save(); Event::fire('admin.log', array('success', 'User id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/user/'); } else { Event::fire('admin.log', array('fail', 'User id: ' . $id)); $view->set('errors', $errors + $user->getErrors()); } } }
/** * @before _secured, _admin */ public function edit($id) { $view = $this->getActionView(); $dog = App_Model_Dog::fetchDogById((int) $id); if ($dog === null) { $view->warningMessage(self::ERROR_MESSAGE_2); $this->_willRenderActionView = false; self::redirect('/admin/dog/'); } $dogExams = $dog->exams; $dogExamIds = array(); if (!empty($dogExams)) { foreach ($dogExams as $dogExam) { $dogExamIds[] = $dogExam->examId; } } $exams = App_Model_Exam::all(array('active = ?' => true)); $users = App_Model_User::all(array('role = ?' => 'role_member'), array('id', 'firstname', 'lastname')); $view->set('dog', $dog)->set('exams', $exams)->set('dogexamids', $dogExamIds)->set('users', $users); if (RequestMethods::post('submitEditDog')) { if ($this->checkCSRFToken() !== true) { self::redirect('/admin/dog/'); } $errors = array(); $cfg = Registry::get('configuration'); $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight)); $imgMain = $imgThumb = ''; if ($dog->imgMain == '') { $photoNameRaw = RequestMethods::post('user') . '-' . RequestMethods::post('dogname'); $photoName = $this->_createUrlKey($photoNameRaw); $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'dog', time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($fileErrors)) { $errors['croppedimage'] = $fileErrors; } if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $imgMain = trim($file->getFilename(), '.'); $imgThumb = trim($file->getThumbname(), '.'); break; } } } } else { $imgMain = $dog->imgMain; $imgThumb = $dog->imgThumb; } if ((int) RequestMethods::post('isactive') == 1) { App_Model_Dog::updateAll(array('isActive = ?' => true, 'userId = ?' => (int) RequestMethods::post('user')), array('isActive' => 0)); } $dog->userId = RequestMethods::post('user'); $dog->isActive = RequestMethods::post('isactive', 0); $dog->dogName = RequestMethods::post('dogname'); $dog->race = RequestMethods::post('dograce'); $dog->dob = RequestMethods::post('dogdob'); $dog->information = RequestMethods::post('doginfo'); $dog->active = RequestMethods::post('active'); $dog->imgMain = $imgMain; $dog->imgThumb = $imgThumb; if (empty($errors) && $dog->validate()) { $dog->save(); $examsArr = (array) RequestMethods::post('chexam'); if ($examsArr[0] != '') { $deleteStatus = App_Model_DogExam::deleteAll(array('dogId = ?' => (int) $dog->getId())); if ($deleteStatus != -1) { foreach ($examsArr as $exam) { $de = new App_Model_DogExam(array('dogId' => (int) $dog->getId(), 'examId' => (int) $exam)); $de->save(); Event::fire('admin.log', array('success', 'Dog id: ' . $dog->getId() . ' has exam ' . $exam)); } } else { $errors['exams'] = array('Nastala chyba při ukládání zkoušek'); } } if (RequestMethods::post('uploadmorephotos') == '1') { $fileErrors = $fileManager->newUpload()->uploadImage('secondfile', 'dog', time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($fileErrors)) { $errors['secondfile'] = $fileErrors; } if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $info = $file->getOriginalInfo(); $photo = new App_Model_Photo(array('galleryId' => 2, 'imgMain' => trim($file->getFilename(), '.'), 'imgThumb' => trim($file->getThumbname(), '.'), 'description' => RequestMethods::post('description'), 'photoName' => pathinfo($file->getFilename(), PATHINFO_FILENAME), 'mime' => $info['mime'], 'format' => $info['format'], 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize())); if ($photo->validate()) { $photoId = $photo->save(); $dp = new App_Model_DogPhoto(array('dogId' => $dog->getId(), 'photoId' => $photoId)); $dp->save(); Event::fire('admin.log', array('success', 'Photo id: ' . $photoId)); } else { Event::fire('admin.log', array('fail')); $errors['secondfile'][] = $photo->getErrors(); } } } } if (empty($errors)) { Event::fire('admin.log', array('success', 'Dog Id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/dog/'); } else { Event::fire('admin.log', array('fail')); $view->set('errors', $errors)->set('dog', $dog); } } else { Event::fire('admin.log', array('success', 'Dog Id: ' . $id)); $view->successMessage(self::SUCCESS_MESSAGE_2); self::redirect('/admin/dog/'); } } else { Event::fire('admin.log', array('fail', 'Dog Id: ' . $dog->getId())); $view->set('errors', $errors + $dog->getErrors())->set('dog', $dog); } } }
/** * Action method shows and processes form used for uploading photos into * collection specified by param id * * @before _secured, _admin * @param int $id collection id */ public function addPhoto($id) { $view = $this->getActionView(); $gallery = App_Model_Gallery::first(array('id = ?' => (int) $id, 'active = ?' => true), array('id', 'title')); if ($gallery === null) { $view->warningMessage(self::ERROR_MESSAGE_2); self::redirect('/admin/gallery/'); } $view->set('gallery', $gallery)->set('submstoken', $this->mutliSubmissionProtectionToken()); if (RequestMethods::post('submitAddPhoto')) { if ($this->checkCSRFToken() !== true && $this->checkMutliSubmissionProtectionToken(RequestMethods::post('submstoken')) !== true) { self::redirect('/admin/gallery/'); } $errors = array(); $cfg = Registry::get('configuration'); $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight)); $fileErrors = $fileManager->uploadImage('secondfile', 'gallery/' . $gallery->getId(), time() . '_')->getUploadErrors(); $files = $fileManager->getUploadedFiles(); if (!empty($files)) { foreach ($files as $i => $file) { if ($file instanceof \THCFrame\Filesystem\Image) { $info = $file->getOriginalInfo(); $photo = new App_Model_Photo(array('galleryId' => $gallery->getId(), 'imgMain' => trim($file->getFilename(), '.'), 'imgThumb' => trim($file->getThumbname(), '.'), 'description' => RequestMethods::post('description'), 'photoName' => pathinfo($file->getFilename(), PATHINFO_FILENAME), 'mime' => $info['mime'], 'format' => $info['format'], 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize())); if ($photo->validate()) { $aid = $photo->save(); Event::fire('admin.log', array('success', 'Photo id: ' . $aid . ' in gallery ' . $gallery->getId())); } else { Event::fire('admin.log', array('fail', 'Photo in gallery ' . $gallery->getId())); $errors['secondfile'][] = $photo->getErrors(); } } } } $errors['secondfile'] = $fileErrors; if (empty($errors['secondfile'])) { $view->successMessage(self::SUCCESS_MESSAGE_7); self::redirect('/admin/gallery/detail/' . $gallery->getId()); } else { $view->set('errors', $errors); } } }