예제 #1
0
파일: Fm.php 프로젝트: rbraband/sefrengo
 /**
  * Backend area (only rightpane) with a form to copy file
  * @return void
  */
 public function copyFile()
 {
     //get id
     $id = (int) $this->req->req('id', 0);
     //load data - if loading fails redirect to index page
     if (!$this->file_sql_item->loadById($id)) {
         $this->_setSystemLogMessage('file_is_not_loaded', array('id' => $id));
         $this->_indexRedirect('error_file_is_not_loaded');
     }
     // check perm for action
     if ($this->file_sql_item->hasPerm('copy') == FALSE) {
         $this->_setUserLogMessage('permission_denied', array('id' => $id, 'path' => $this->file_sql_item->getRelativePath()), 'debug');
         $this->_indexRedirect('error_permission_denied');
     }
     $form = sf_api('VIEW', 'Form');
     // assign real form vals to config fields
     $config_fields = $this->_assignValuesToConfigFields($this->config_fields['copy_file'], $this->file_sql_item, $form->wasSend());
     $config_fields['source']['val'] = $this->file_sql_item->getHtmlPath();
     // validate or save form
     $msg_string = '';
     if ($form->wasSend()) {
         // check if invalid files are allowed
         switch ($this->config_area['allow_invalid_filenames']) {
             // no: check by normal validation
             case 0:
                 break;
                 // yes: disable validation
             // yes: disable validation
             case 1:
                 unset($config_fields['filename']['validation']['filename']);
                 break;
                 // correct filename: disable validation and correct filename in file_sql_item
             // correct filename: disable validation and correct filename in file_sql_item
             case 2:
                 unset($config_fields['filename']['validation']['filename']);
                 break;
         }
         // validate form
         $msg_string = $this->_validateConfigFields($config_fields);
         $fsm = sf_api('LIB', 'FilesystemManipulation');
         $extension = $fsm->getPathinfo($config_fields['filename']['val'], 'extension');
         unset($fsm);
         // validation errors found, so mark them as errors
         if ($msg_string != '') {
             $msg_string = 'error_' . $msg_string;
         } else {
             if ($this->_isForbiddenFileExtension($extension) == TRUE) {
                 $msg_string = 'error_forbidden_file_extension';
             } else {
                 $filedata = $this->_getItemFieldArrayFromConfigFields($config_fields);
                 $filedata['area'] = $this->config_area['area_name'];
                 $filedata['idclient'] = $this->config_area['idclient'];
                 try {
                     $move = $this->req->asBoolean('move');
                     $success = FALSE;
                     $msgcode = '';
                     if ($move == FALSE && $this->file_sql_item->copy($filedata) == TRUE) {
                         $filedata['path'] = $this->file_sql_item->getRelativePath();
                         $this->_setUserLogMessage('copy_file_success', $filedata);
                         $msgcode = 'ok_copy_file_success';
                         $success = TRUE;
                     } else {
                         if ($move == TRUE && $this->file_sql_item->move($filedata) == TRUE) {
                             $filedata['path'] = $this->file_sql_item->getRelativePath();
                             $this->_setUserLogMessage('move_file_success', $filedata);
                             $msgcode = 'ok_move_file_success';
                             $success = TRUE;
                         }
                     }
                     if ($success == TRUE) {
                         // redirect to tableview
                         if ($form->saveWasPressed()) {
                             $this->_indexRedirect($msgcode);
                         } else {
                             $this->url->urlAddModifyParams(array('msgcode' => $msgcode, 'id' => $this->file_sql_item->getId()));
                             $this->http_header->redirect($this->url->urlGet(array('area' => $this->config_area['area_name'] . '_copy_file')));
                         }
                     }
                 } catch (Exception $e) {
                     switch ($e->getCode()) {
                         // 0 = fatal, 1 = error
                         case 0:
                         case 1:
                             $code = 'error';
                             break;
                             // 2 = warning
                         // 2 = warning
                         case 2:
                             $code = 'warning';
                             break;
                         default:
                             $code = 'info';
                     }
                     $lng = $this->lng->get($this->config_area['area_name'] . '_' . $e->getMessage());
                     $msg_string = $code . '_';
                     $msg_string .= $lng != '' ? $lng : $e->getMessage();
                     $filedata['path'] = $this->file_sql_item->getRelativePath();
                     $this->_setUserLogMessage($e->getMessage(), $filedata, $code);
                 }
             }
         }
     }
     // build directory tree
     $config_fields['iddirectory']['tree'] = $this->_getDirectoryChooserTree($this->params['iddirectory'], array(), $this->config_area['files_in_root']);
     // build form
     $this->_buildFormFromConfigFields($config_fields, $form);
     $backend_area = sf_api('VIEW', 'BackendArea');
     $backend_area->addCmsHeader($this->config_area['js_lang']);
     $backend_area->addFooter();
     // error or warning templates
     $msg = $this->_getMessage($this->req->req('msgcode', $msg_string));
     if ($msg !== FALSE) {
         $backend_area->addMessage($msg['type'], $msg['message']);
     }
     $backend_area->addTemplateVar('TITLE', $this->lng->get($this->config_area['area_name'] . '_area_copy_file'), 'RIGHTPANE.TITLE');
     $backend_area->addTemplateVar('RIGHTPANE', $form, 'RIGHTPANE');
     $backend_area->generate();
     return $backend_area->get();
 }