예제 #1
0
 /**
  * Return parent folder instance
  *
  * @param void
  * @return ProjectFolder
  */
 function getFolder()
 {
     if (is_null($this->folder)) {
         $this->folder = ProjectFolders::findById($this->getFolderId());
         if ($this->folder instanceof ProjectFolder && $this->folder->getProjectId() != $this->getProjectId()) {
             $this->folder = null;
         }
         // if
     }
     // if
     return $this->folder;
 }
예제 #2
0
 /**
  * Return parent folder
  *
  * @param void
  * @return object
  */
 function getParent()
 {
     if (is_null($this->parent)) {
         $this->parent = ProjectFolders::findById($this->getParentId());
         if ($this->parent instanceof ProjectFolder && $this->parent->getProjectId() != $this->getProjectId()) {
             $this->parent = null;
         }
         // if
     }
     // if
     return $this->parent;
 }
예제 #3
0
 /**
  * Add file
  *
  * @access public
  * @param void
  * @return null
  */
 function add_file()
 {
     if (!ProjectFile::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('files'));
     }
     // if
     $file = new ProjectFile();
     $file_data = array_var($_POST, 'file');
     if (!is_array($file_data)) {
         $file_data = array('is_private' => config_option('default_private', false));
         // array
     }
     // if
     $folder = null;
     $folder_id = get_id('folder_id');
     if ($folder_id) {
         $folder = ProjectFolders::findById($folder_id);
     }
     // if
     if ($folder instanceof ProjectFolder) {
         if (!is_array($file_data)) {
             $file_data = array('folder_id' => $folder->getId(), 'is_private' => config_option('default_private', false));
             // array
         } else {
             $file_data['is_private'] = config_option('default_private', false);
         }
     }
     // if
     tpl_assign('file', $file);
     tpl_assign('file_data', $file_data);
     if (is_array(array_var($_POST, 'file'))) {
         try {
             DB::beginWork();
             $uploaded_file = array_var($_FILES, 'file_file');
             $file->setFromAttributes($file_data);
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $file->setIsPrivate(false);
                 $file->setIsImportant(false);
                 $file->setCommentsEnabled(true);
                 $file->setAnonymousCommentsEnabled(false);
             }
             // if
             $file->setFilename(array_var($uploaded_file, 'name'));
             $file->setProjectId(active_project()->getId());
             $file->setIsVisible(true);
             $file->save();
             if (plugin_active('tags')) {
                 $file->setTagsFromCSV(array_var($file_data, 'tags'));
             }
             $revision = $file->handleUploadedFile($uploaded_file, true);
             // handle uploaded file
             ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             flash_success(lang('success add file', $file->getFilename()));
             $this->redirectToUrl($file->getDetailsUrl());
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
             tpl_assign('file', new ProjectFile());
             // reset file
             // If we uploaded the file remove it from repository
             if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) {
                 FileRepository::deleteFile($revision->getRepositoryId());
             }
             // if
         }
         // try
     }
     // if
 }
    /**
    * Delete folder
    *
    * @access public
    * @param void
    * @return null
    */
    function delete_folder() {
      $this->setTemplate('del_folder');

      $folder = ProjectFolders::findById(get_id());
      if (!($folder instanceof ProjectFolder)) {
        flash_error(lang('folder dnx'));
        $this->redirectTo('files');
      } // if
      
      if (!$folder->canDelete(logged_user())) {
        flash_error(lang('no access permissions'));
        $this->redirectToReferer(get_url('files'));
      } // if

      $delete_data = array_var($_POST, 'deleteFolder');
      tpl_assign('folder', $folder);
      tpl_assign('delete_data', $delete_data);
      
      if (!is_array($delete_data)) {
        $delete_data = array(
          'really' => 0,
          'password' => '',
          ); // array
        tpl_assign('delete_data', $delete_data);
      } else if ($delete_data['really'] == 1) {
        $password = $delete_data['password'];
        if (trim($password) == '') {
          tpl_assign('error', new Error(lang('password value missing')));
          return $this->render();
        }
        if (!logged_user()->isValidPassword($password)) {
          tpl_assign('error', new Error(lang('invalid login data')));
          return $this->render();
        }
      
        try {
          DB::beginWork();
          $folder->delete();
          ApplicationLogs::createLog($folder, active_project(), ApplicationLogs::ACTION_DELETE);
          DB::commit();
          
          flash_success(lang('success delete folder', $folder->getName()));
        } catch(Exception $e) {
          DB::rollback();
          flash_error(lang('error delete folder'));
        } // try
      
        $this->redirectTo('files');
      } else {
        flash_error(lang('error delete folder'));
        $this->redirectToUrl($folder->getDetailsUrl());
      }
    } // delete_folder
 /**
  * Add file
  *
  * @access public
  * @param void
  * @return null
  */
 function add_file()
 {
     if (!ProjectFile::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('files'));
     }
     // if
     $file = new ProjectFile();
     $file_data = array_var($_POST, 'file');
     if (!is_array($file_data)) {
         $file_data = array('is_private' => config_option('default_private', false));
         // array
     }
     // if
     $folder = null;
     $folder_id = get_id('folder_id');
     if ($folder_id) {
         $folder = ProjectFolders::findById($folder_id);
     }
     // if
     if ($folder instanceof ProjectFolder) {
         if (!is_array($file_data)) {
             $file_data = array('folder_id' => $folder->getId(), 'is_private' => config_option('default_private', false));
             // array
         } else {
             $file_data['is_private'] = config_option('default_private', false);
         }
     }
     // if
     tpl_assign('file', $file);
     tpl_assign('file_data', $file_data);
     if (is_array(array_var($_POST, 'file'))) {
         try {
             DB::beginWork();
             $uploaded_file = array_var($_FILES, 'file_file');
             // move uploaded file to folder where I can read and write
             move_uploaded_file($uploaded_file['tmp_name'], ROOT . '/tmp/' . $uploaded_file['name']);
             $uploaded_file['tmp_name'] = ROOT . '/tmp/' . $uploaded_file['name'];
             $file->setFromAttributes($file_data);
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $file->setIsPrivate(false);
                 $file->setIsImportant(false);
                 $file->setCommentsEnabled(true);
                 $file->setAnonymousCommentsEnabled(false);
             }
             // if
             $file->setFilename(array_var($uploaded_file, 'name'));
             $file->setProjectId(active_project()->getId());
             $file->setIsVisible(true);
             $file->save();
             if (plugin_active('tags')) {
                 $file->setTagsFromCSV(array_var($file_data, 'tags'));
             }
             $revision = $file->handleUploadedFile($uploaded_file, true);
             // handle uploaded file
             ApplicationLogs::createLog($file, active_project(), ApplicationLogs::ACTION_ADD);
             DB::commit();
             // Try to send notifications but don't break submission in case of an error
             // define all the users to be notified - here all project users, from all companies.
             // Restrictions if comment is private is taken into account in newOtherComment()
             try {
                 $notify_people = array();
                 $project_companies = active_project()->getCompanies();
                 foreach ($project_companies as $project_company) {
                     $company_users = $project_company->getUsersOnProject(active_project());
                     if (is_array($company_users)) {
                         foreach ($company_users as $company_user) {
                             if (array_var($file_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($file_data, 'notify_user_' . $company_user->getId())) {
                                 $notify_people[] = $company_user;
                             }
                             // if
                         }
                         // if
                     }
                     // if
                 }
                 // if
                 Notifier::newFile($file, $notify_people);
                 // send notification email...
             } catch (Exception $e) {
                 Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR);
             }
             // try
             flash_success(lang('success add file', $file->getFilename()));
             $this->redirectToUrl($file->getDetailsUrl());
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
             tpl_assign('file', new ProjectFile());
             // reset file
             // If we uploaded the file remove it from repository
             if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) {
                 FileRepository::deleteFile($revision->getRepositoryId());
             }
             // if
         }
         // try
     }
     // if
 }