예제 #1
0
function files_my_tasks_dropdown()
{
    //if (logged_user()->getProjectPermission(active_project(), PermissionManager::CAN_MANAGE_FILES)) {
    echo '<li class="header"><a href="' . get_url('files', 'index') . '">' . lang('files') . '</a></li>';
    //} // if
    if (ProjectFile::canAdd(logged_user(), active_project())) {
        echo '<li><a href="' . get_url('files', 'add_file') . '">' . lang('add file') . '</a></li>';
    }
    // if
    if (ProjectFolder::canAdd(logged_user(), active_project())) {
        echo '<li><a href="' . get_url('files', 'add_folder') . '">' . lang('add folder') . '</a></li>';
    }
    // if
}
예제 #2
0
function files_my_tasks_dropdown()
{
    if (use_permitted(logged_user(), active_project(), 'files')) {
        echo '<li class="header"><a href="' . get_url('files', 'index') . '">' . lang('files') . '</a></li>';
        if (ProjectFile::canAdd(logged_user(), active_project())) {
            echo '<li><a href="' . get_url('files', 'add_file') . '">' . lang('add file') . '</a></li>';
        }
        // if
        if (ProjectFolder::canAdd(logged_user(), active_project())) {
            echo '<li><a href="' . get_url('files', 'add_folder') . '">' . lang('add folder') . '</a></li>';
        }
        // if
    }
    // if
}
예제 #3
0
<?php

set_page_title($file->getObjectName());
project_tabbed_navigation(PROJECT_TAB_FILES);
$files_crumbs = array(0 => array(lang('files'), get_url('files')));
// array
if ($folder instanceof ProjectFolder) {
    $files_crumbs[] = array($folder->getName(), $folder->getBrowseUrl());
}
// if
$files_crumbs[] = lang('file details');
project_crumbs($files_crumbs);
if (ProjectFile::canAdd(logged_user(), active_project())) {
    if ($folder instanceof ProjectFolder) {
        add_page_action(lang('add file'), $folder->getAddFileUrl());
    } else {
        add_page_action(lang('add file'), get_url('files', 'add_file'));
    }
    // if
}
// if
if (ProjectFolder::canAdd(logged_user(), active_project())) {
    add_page_action(lang('add folder'), get_url('files', 'add_folder'));
}
// if
add_stylesheet_to_page('project/files.css');
?>
<div id="fileDetails" class="block">
<?php 
if ($file->isPrivate()) {
    ?>
예제 #4
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
 }
예제 #5
0
	function add_presentation() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		if (get_id() > 0) {
			//open presentation
			try {
				DB::beginWork();
				$this->setTemplate('add_presentation');
				$file = ProjectFiles::findById(get_id());
	
				if (!($file instanceof ProjectFile)) {
					throw new Exception(lang('file dnx'));
				} // if
	
				if (!$file->canEdit(logged_user())) {
					if ($file->isCheckedOut() && !$file->canCheckin(logged_user())) {
						throw new Exception(lang('error document checked out by another user'));
					} else {
						throw new Exception(lang('no access permissions'));
					}
				} // if
	
				if (config_option('checkout_for_editing_online')) {
					$file->checkOut(true, logged_user());
				}
				
				$file_data = array_var($_POST, 'file');
				if (!is_array($file_data)) {
					$file_data = array(
						'description' => $file->getDescription(),
					); // array
				} // if
				tpl_assign('file', $file);
				tpl_assign('file_data', $file_data);
				DB::commit();
			} catch (Exception $e) {
				DB::rollback();
				flash_error($e->getMessage());
				ajx_current("empty");
			}
		} else {
			//new presentation
			$notAllowedMember = '' ;
			if (!ProjectFile::canAdd(logged_user(), active_context(), $notAllowedMember)) {
				if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
				else flash_error(lang('no context permissions to add',lang("presentations"), $notAllowedMember));
				ajx_current("empty");
				return;
			} // if

			$file = new ProjectFile();
			$file_data = array_var($_POST, 'file');

			tpl_assign('file', $file);
			tpl_assign('file_data', $file_data);
		}
	}
 function copy()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     ajx_set_no_toolbar();
     $ws = active_or_personal_project();
     $id = get_id();
     $file = ProjectFiles::findById($id);
     if (!$file instanceof ProjectFile) {
         flash_error("file dnx");
         ajx_current("empty");
         return;
     }
     if (!can_read(logged_user(), $file)) {
         flash_error("no access permissions");
         ajx_current("empty");
         return;
     }
     if (!ProjectFile::canAdd(logged_user(), $ws)) {
         flash_error("no access permissions");
         ajx_current("empty");
         return;
     }
     try {
         DB::beginWork();
         $copy = $file->copy();
         $copy->setFilename(lang('copy of file', $file->getFilename()));
         $copy->save();
         $copy->addToWorkspace($ws);
         $rev_data = array();
         $rev_data['name'] = $copy->getFilename();
         $rev_data['size'] = $file->getFileSize();
         $rev_data['type'] = $file->getTypeString();
         $rev_data['tmp_name'] = ROOT . '/tmp/' . rand();
         $handler = fopen($rev_data['tmp_name'], 'w');
         $file_content = $file->getLastRevision()->getFileContent();
         fputs($handler, $file_content);
         fclose($handler);
         $copy->handleUploadedFile($rev_data, false, lang("copied from file", $file->getFilename(), $file->getUniqueObjectId()));
         DB::commit();
         $this->setTemplate('file_details');
         tpl_assign('file', $copy);
         tpl_assign('last_revision', $copy->getLastRevision());
         tpl_assign('revisions', $copy->getRevisions());
     } catch (Exception $ex) {
         DB::rollback();
         flash_error($ex->getMessage());
         ajx_current("empty");
     }
 }
 /**
  * Classify specific email
  *
  */
 function classify()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $email = MailContents::findById(get_id());
     if (!$email instanceof MailContent) {
         flash_error(lang('email dnx'));
         ajx_current("empty");
         return;
     }
     if ($email->getIsDeleted()) {
         flash_error(lang('email dnx deleted'));
         ajx_current("empty");
         return;
     }
     if (!$email->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     MailUtilities::parseMail($email->getContent(), $decoded, $parsedEmail, $warnings);
     $projects = logged_user()->getActiveProjects();
     tpl_assign('projects', $projects);
     $classification_data = array_var($_POST, 'classification');
     if (!is_array($classification_data)) {
         $tag_names = $email->getTagNames();
         $classification_data = array('tag' => is_array($tag_names) ? implode(', ', $tag_names) : '');
         // array
     }
     // if
     if (is_array(array_var($_POST, 'classification'))) {
         try {
             $create_task = array_var($classification_data, 'create_task') == 'checked';
             $canWriteFiles = $this->checkFileWritability($classification_data, $parsedEmail);
             if ($canWriteFiles) {
                 $project_ids = $classification_data["project_ids"];
                 $enteredWS = Projects::findByCSVIds($project_ids);
                 $validWS = array();
                 if (isset($enteredWS)) {
                     foreach ($enteredWS as $ws) {
                         if (ProjectFile::canAdd(logged_user(), $ws)) {
                             $validWS[] = $ws;
                         }
                     }
                 }
                 if (empty($validWS)) {
                     flash_error(lang('must choose at least one workspace error'));
                     ajx_current("empty");
                     return;
                 }
                 DB::beginWork();
                 $conversation = MailContents::getMailsFromConversation($email);
                 foreach ($conversation as $conv_email) {
                     $conv_email->removeFromWorkspaces(logged_user()->getWorkspacesQuery());
                     foreach ($validWS as $w) {
                         $conv_email->addToWorkspace($w);
                     }
                     $conv_email->save();
                     MailUtilities::parseMail($conv_email->getContent(), $decoded, $parsedEmail, $warnings);
                     $csv = array_var($classification_data, 'tag');
                     $conv_email->setTagsFromCSV($csv);
                     if ($conv_email->getHasAttachments()) {
                         //Classify attachments
                         $this->classifyFile($classification_data, $conv_email, $parsedEmail, $validWS, true, $csv);
                     }
                 }
                 DB::commit();
                 flash_success(lang('success classify email'));
                 if ($create_task) {
                     ajx_replace(true);
                     $this->redirectTo('task', 'add_task', array('from_email' => $email->getId(), 'replace' => 1));
                 } else {
                     ajx_current("back");
                     evt_add("reload mails panel", array());
                 }
             } else {
                 flash_error(lang("error classifying attachment cant open file"));
                 ajx_current("empty");
             }
             // If can write files
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     } else {
         $classification_data["project_ids"] = $email->getWorkspaces();
     }
     tpl_assign('classification_data', $classification_data);
     tpl_assign('email', $email);
     tpl_assign('parsedEmail', $parsedEmail);
 }
예제 #8
0
 function uploadFile($username, $password, $workspaces, $tags, $generate_rev, $filename, $description, $do_checkin, $data)
 {
     $result = array('status' => true, 'errorid' => 0, 'message' => '');
     if ($this->loginUser($username, $password)) {
         try {
             DB::beginWork();
             $file = null;
             $files = ProjectFiles::getAllByFilename($filename, logged_user()->getWorkspacesQuery());
             if (is_array($files) && count($files) > 0) {
                 if ($generate_rev) {
                     $file = ProjectFiles::findById($files[0]->getId());
                     if ($file->isCheckedOut()) {
                         if (!$file->canCheckin(logged_user())) {
                             $result['status'] = false;
                             $result['errorid'] = 1004;
                             $result['message'] = lang('no access permissions');
                         }
                         $file->setCheckedOutById(0);
                     } else {
                         // Check for edit permissions
                         if (!$file->canEdit(logged_user())) {
                             $result['status'] = false;
                             $result['errorid'] = 1004;
                             $result['message'] = lang('no access permissions');
                         }
                     }
                 }
             }
             if ($result['status']) {
                 $enteredWS = Projects::findByCSVIds($workspaces);
                 $validWS = array();
                 foreach ($enteredWS as $ws) {
                     if (ProjectFile::canAdd(logged_user(), $ws)) {
                         $validWS[] = $ws;
                     }
                 }
                 if (count($validWS) == 0) {
                     $result['status'] = false;
                     $result['errorid'] = 1005;
                     $result['message'] = 'Invalid workspaces given. Check access permissions.';
                 } else {
                     $make_revision_comment = $file != null;
                     if ($file == null) {
                         $file = new ProjectFile();
                         $file->setFilename($filename);
                         $file->setIsVisible(true);
                         $file->setIsPrivate(false);
                         $file->setIsImportant(false);
                         $file->setCommentsEnabled(true);
                         $file->setAnonymousCommentsEnabled(false);
                         $file->setCreatedOn(new DateTimeValue(time()));
                         $file->setDescription($description);
                     }
                     $file_dt['name'] = $file->getFilename();
                     $file_dt['size'] = strlen($data);
                     $file_dt['tmp_name'] = ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . rand();
                     $extension = trim(get_file_extension($file->getFilename()));
                     $file_dt['type'] = Mime_Types::instance()->get_type($extension);
                     if (!trim($file_dt['type'])) {
                         $file_dt['type'] = 'text/html';
                     }
                     $handle = fopen($file_dt['tmp_name'], "w");
                     fwrite($handle, $data, $file_dt['size']);
                     fclose($handle);
                     $file->save();
                     $revision = $file->handleUploadedFile($file_dt, true, $make_revision_comment ? $description : '');
                     $file->setTagsFromCSV($tags);
                     foreach ($validWS as $w) {
                         $file->addToWorkspace($w);
                     }
                     foreach ($validWS as $w) {
                         ApplicationLogs::createLog($file, $w, ApplicationLogs::ACTION_ADD);
                     }
                     DB::commit();
                     $result['message'] = 'd' . str_pad($file->getId(), 3, '0', STR_PAD_LEFT) . 'r' . $file->getRevisionNumber();
                     if (!$do_checkin) {
                         $this->checkoutFile($username, $password, $file->getId());
                     }
                 }
             }
         } catch (Exception $e) {
             DB::rollback();
             $result['message'] = $e->getMessage();
             $result['errorid'] = 1003;
             $result['status'] = false;
             // If we uploaded the file remove it from repository
             if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) {
                 FileRepository::deleteFile($revision->getRepositoryId());
             }
         }
     } else {
         $result['status'] = false;
         $result['errorid'] = 1002;
         $result['message'] = lang('invalid login data');
     }
     return $this->result_to_xml($result, 'result');
 }
예제 #9
0
<?php
  set_page_title($folder->isNew() ? lang('add folder') : lang('edit folder'));
  
  if(ProjectFile::canAdd(logged_user(), active_context())) {
    add_page_action(lang('add file'), get_url('files', 'add_file'), 'ico-add');
  } // if

  
?>
<form class="internalForm" action="<?php echo ($folder->isNew())? get_url('files', 'add_folder') : $folder->getEditUrl()?>" method="post">

<?php tpl_display(get_template_path('form_errors')) ?>
  
  <div>
    <?php echo label_tag(lang('name'), 'folderFormName') ?>
    <?php echo text_field('folder[name]', array_var($folder_data, 'name'), array('id' => 'folderFormName')) ?>
  </div>
  
  <?php echo submit_button($folder->isNew() ? lang('add folder') : lang('edit folder')) ?>
  
</form>
    /**
    * 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(
          'folder_id' => get_id('folder_id'),
          'is_private' => config_option('default_private', false)
        ); // array
      } // 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
    } // add_file