/**
  * 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);
         }
     }
 }