/**
	 * Edit file properties
	 *
	 * @access public
	 * @param void
	 * @return null
	 */
	function edit_file() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		$this->setTemplate('add_file');

		$file = ProjectFiles::findById(get_id());
		if(!($file instanceof ProjectFile)) {
			flash_error(lang('file dnx'));
			ajx_current("empty");
			return;
		} // if
			
		if(!$file->canEdit(logged_user())) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		} // if
			
		$file_data = array_var($_POST, 'file');
		if(!is_array($file_data)) {
			$file_data = array(
				'description' => $file->getDescription(),
				'edit_name' => $file->getFilename(),
				'file_id' => get_id()
			); // array
		} // if
		tpl_assign('file', $file);
		tpl_assign('file_data', $file_data);

			
		if(is_array(array_var($_POST, 'file'))) {
			try {
				DB::beginWork();
				$handle_file      = array_var($file_data, 'update_file') == 'checked'; // change file?
				$post_revision    = $handle_file && array_var($file_data, 'version_file_change') == 'checked'; // post revision?
				$revision_comment = trim(array_var($file_data, 'revision_comment')); // user comment?

				$file->setFromAttributes($file_data);
				$file->setFilename(array_var($file_data, 'name'));
				
				if ($file->getType() == ProjectFiles::TYPE_WEBLINK) {
					$url = array_var($file_data, 'url', '');
					if ($url && strpos($url, ':') === false) {
						$url = $this->protocol . $url;
					}
					$file->setUrl($url);
					$revision = $file->getLastRevision();
					/* @var $revision ProjectFileRevision */
					if (!$revision instanceof ProjectFileRevision || array_var($file_data, 'version_file_change') == 'checked') {
						$revision = new ProjectFileRevision();
						$revision->setFileId($file->getId());
						$revision->setRevisionNumber($file->getNextRevisionNumber());
						$revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId());
						$revision->setRepositoryId('webfile');
						$revision->setComment($revision_comment);
					}
				
					$revision->setTypeString($file->getUrl());
					$revision->save();
				}
				
				$file->save();
				
				if( $handle_file) {
					// handle uploaded file
					$upload_id = array_var($file_data, 'upload_id');
					$uploaded_file = array_var($_SESSION, $upload_id, array());
					$file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment); // handle uploaded file
					@unlink($uploaded_file['tmp_name']);
				} // if

				$member_ids = json_decode(array_var($_POST, 'members'));
				$object_controller = new ObjectController();
				$object_controller->add_to_members($file, $member_ids);
				$object_controller->link_to_new_object($file);
				$object_controller->add_subscribers($file);
				$object_controller->add_custom_properties($file);

				$file->resetIsRead();
				
				ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT);
                                
				DB::commit();
								
				flash_success(lang('success edit file', $file->getFilename()));
				ajx_current("back");
			} catch(Exception $e) {
				
				DB::rollback();
				ajx_current("empty");
				flash_error($e->getMessage());
			} // try
		} // if
	} // edit_file
 /**
  * This function will process uploaded file
  *
  * @param array $uploaded_file
  * @param boolean $create_revision Create new revision or update last one
  * @param string $revision_comment Revision comment, if any
  * @return ProjectFileRevision
  */
 function handleUploadedFile($uploaded_file, $create_revision = true, $revision_comment = '')
 {
     $revision = null;
     if (!$create_revision) {
         $revision = $this->getLastRevision();
     }
     // if
     if (!$revision instanceof ProjectFileRevision) {
         $revision = new ProjectFileRevision();
         $revision->setFileId($this->getId());
         $revision->setRevisionNumber($this->getNextRevisionNumber());
         if (trim($revision_comment) == '' && $this->countRevisions() < 1) {
             $revision_comment = lang('initial versions');
         }
         // if
     }
     // if
     $revision->deleteThumb(false);
     // remove thumb
     // We have a file to handle!
     //executes only while uploading files
     if (!is_array($uploaded_file) || !isset($uploaded_file['name']) || !isset($uploaded_file['size']) || !isset($uploaded_file['type']) || (!isset($uploaded_file['tmp_name']) || !is_readable($uploaded_file['tmp_name']))) {
         throw new InvalidUploadError($uploaded_file);
     }
     // if
     if (isset($uploaded_file['error']) && $uploaded_file['error'] > UPLOAD_ERR_OK) {
         throw new InvalidUploadError($uploaded_file);
     }
     // if
     //eyedoc MOD
     $extension = get_file_extension(basename($uploaded_file['name']));
     if ($uploaded_file['type'] == 'application/octet-stream' && $extension == 'eyedoc') {
         $uploaded_file['type'] = 'text/html';
     }
     //eyedoc MOD
     // calculate hash
     if ($revision->columnExists('hash')) {
         $hash = hash_file("sha256", $uploaded_file['tmp_name']);
         $revision->setColumnValue('hash', $hash);
     }
     $repository_id = FileRepository::addFile($uploaded_file['tmp_name'], array('name' => $uploaded_file['name'], 'type' => $uploaded_file['type'], 'size' => $uploaded_file['size']));
     $revision->setRepositoryId($repository_id);
     $revision->deleteThumb(false);
     $revision->setFilesize($uploaded_file['size']);
     if (config_option('detect_mime_type_from_extension')) {
         $type = Mime_Types::instance()->get_type($extension);
         if ($type) {
             $revision->setTypeString($type);
         } else {
             $revision->setTypeString($uploaded_file['type']);
         }
     } else {
         $revision->setTypeString($uploaded_file['type']);
     }
     if (trim($extension)) {
         $file_type = FileTypes::getByExtension($extension);
         if ($file_type instanceof Filetype) {
             $revision->setFileTypeId($file_type->getId());
         }
         // if
     }
     // if
     $revision->setComment($revision_comment);
     $revision->save();
     $this->last_revision = $revision;
     // update last revision
     return $revision;
 }
 /**
  * Edit file properties
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_file()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_file');
     $file = ProjectFiles::findById(get_id());
     if (!$file instanceof ProjectFile) {
         flash_error(lang('file dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$file->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $file_data = array_var($_POST, 'file');
     if (!is_array($file_data)) {
         $tag_names = $file->getTagNames();
         $file_data = array('description' => $file->getDescription(), 'is_private' => $file->getIsPrivate(), 'is_important' => $file->getIsImportant(), 'comments_enabled' => $file->getCommentsEnabled(), 'anonymous_comments_enabled' => $file->getAnonymousCommentsEnabled(), 'tags' => is_array($tag_names) && count($tag_names) ? implode(', ', $tag_names) : '', 'edit_name' => $file->getFilename(), 'file_id' => get_id());
         // array
     }
     // if
     tpl_assign('file', $file);
     tpl_assign('file_data', $file_data);
     if (is_array(array_var($_POST, 'file'))) {
         try {
             $old_is_private = $file->isPrivate();
             $old_is_important = $file->getIsImportant();
             $old_comments_enabled = $file->getCommentsEnabled();
             $old_anonymous_comments_enabled = $file->getAnonymousCommentsEnabled();
             DB::beginWork();
             $handle_file = array_var($file_data, 'update_file') == 'checked';
             // change file?
             $post_revision = $handle_file && array_var($file_data, 'version_file_change') == 'checked';
             // post revision?
             $revision_comment = trim(array_var($file_data, 'revision_comment'));
             // user comment?
             $file->setFromAttributes($file_data);
             $file->setFilename(array_var($file_data, 'name'));
             if ($file->getType() == ProjectFiles::TYPE_WEBLINK) {
                 $url = array_var($file_data, 'url', '');
                 if ($url && strpos($url, ':') === false) {
                     $url = "http://" . $url;
                 }
                 $file->setUrl($url);
                 $revision = $file->getLastRevision();
                 if (!$revision instanceof ProjectFileRevision || array_var($file_data, 'version_file_change') == 'checked') {
                     $revision = new ProjectFileRevision();
                     $revision->setFileId($file->getId());
                     $revision->setRevisionNumber($file->getNextRevisionNumber());
                     $revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId());
                     $revision->setRepositoryId('webfile');
                     $revision->setComment($revision_comment);
                 }
                 $revision->setTypeString($file->getUrl());
                 $revision->save();
             }
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $file->setIsPrivate($old_is_private);
                 $file->setIsImportant($old_is_important);
                 $file->setCommentsEnabled($old_comments_enabled);
                 $file->setAnonymousCommentsEnabled($old_anonymous_comments_enabled);
             }
             // if
             //$file->setFilename(array_var($file_data, 'name'));
             $file->save();
             $file->setTagsFromCSV(array_var($file_data, 'tags'));
             if ($handle_file) {
                 // handle uploaded file
                 $upload_id = array_var($file_data, 'upload_id');
                 $uploaded_file = array_var($_SESSION, $upload_id, array());
                 $file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment);
                 // handle uploaded file
                 @unlink($uploaded_file['tmp_name']);
             }
             // if
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($file);
             $object_controller->link_to_new_object($file);
             $object_controller->add_subscribers($file);
             $object_controller->add_custom_properties($file);
             $file->resetIsRead();
             ApplicationLogs::createLog($file, $file->getWorkspaces(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             flash_success(lang('success edit file', $file->getFilename()));
             ajx_current("back");
         } catch (Exception $e) {
             //@unlink($file->getFilePath());
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
 /**
  * Edit file properties
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_file()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_file');
     $file = ProjectFiles::findById(get_id());
     if (!$file instanceof ProjectFile) {
         flash_error(lang('file dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$file->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $file_data = array_var($_POST, 'file');
     if (!is_array($file_data)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $file_data = array('description' => $file->getDescription(), 'attach_to_notification' => $file->getAttachToNotification(), 'default_subject' => $file->getDefaultSubject(), 'file_id' => get_id());
         // array
     }
     // if
     tpl_assign('file', $file);
     tpl_assign('file_data', $file_data);
     if (is_array(array_var($_POST, 'file'))) {
         foreach ($file_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         try {
             DB::beginWork();
             $handle_file = array_var($file_data, 'update_file');
             // change file?
             $post_revision = $handle_file && array_var($file_data, 'version_file_change');
             // post revision?
             $revision_comment = trim(array_var($file_data, 'revision_comment'));
             // user comment?
             $file->setFromAttributes($file_data);
             $file->setAttachToNotification(array_var($file_data, 'attach_to_notification'));
             if (array_var($file_data, 'default_subject_sel') == 'subject') {
                 $file->setDefaultSubject(array_var($file_data, 'default_subject_text'));
             } else {
                 $file->setDefaultSubject('');
             }
             $fname = array_var($file_data, 'name');
             $ext = trim(array_var($file_data, 'extension'));
             if ($ext != '') {
                 $fname .= "." . $ext;
             }
             $file->setFilename($fname);
             if ($file->getType() == ProjectFiles::TYPE_WEBLINK) {
                 $url = array_var($file_data, 'url', '');
                 if ($url && strpos($url, ':') === false) {
                     $url = $this->protocol . $url;
                 }
                 $file->setUrl($url);
                 $revision = $file->getLastRevision();
                 /* @var $revision ProjectFileRevision */
                 if (!$revision instanceof ProjectFileRevision || $post_revision) {
                     $revision = new ProjectFileRevision();
                     $revision->setFileId($file->getId());
                     $revision->setRevisionNumber($file->getNextRevisionNumber());
                     $revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId());
                     $revision->setRepositoryId('webfile');
                     $revision->setComment($revision_comment);
                 }
                 $revision->setTypeString($file->getUrl());
                 $revision->save();
             }
             $file->save();
             if ($handle_file) {
                 // handle uploaded file
                 $upload_id = array_var($file_data, 'upload_id');
                 $uploaded_file = array_var($_SESSION, $upload_id, array());
                 $file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment);
                 // handle uploaded file
                 @unlink($uploaded_file['tmp_name']);
             }
             // if
             $member_ids = json_decode(array_var($_POST, 'members'));
             $object_controller = new ObjectController();
             $object_controller->add_to_members($file, $member_ids);
             $object_controller->link_to_new_object($file);
             $object_controller->add_subscribers($file);
             $object_controller->add_custom_properties($file);
             $file->resetIsRead();
             DB::commit();
             set_user_config_option('notify_myself_too', array_var($file_data, 'notify_myself_too'));
             if (array_var($file_data, 'notify_myself_too')) {
                 logged_user()->notify_myself = true;
             }
             ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT);
             if (array_var($file_data, 'notify_myself_too')) {
                 logged_user()->notify_myself = false;
             }
             flash_success(lang('success edit file', $file->getFilename()));
             ajx_current("back");
             if (array_var($_REQUEST, 'modal')) {
                 evt_add("reload current panel");
             }
         } catch (Exception $e) {
             DB::rollback();
             if (array_var($_REQUEST, 'modal')) {
                 $this->setLayout("json");
                 $this->setTemplate(get_template_path("empty"));
                 print_modal_json_response(array('errorCode' => 1, 'errorMessage' => $e->getMessage(), 'showMessage' => 1), true, true);
             } else {
                 flash_error($e->getMessage());
             }
             ajx_current("empty");
         }
         // try
     }
     // if
 }
示例#5
0
 /**
  * This function will process uploaded file
  *
  * @param array $uploaded_file
  * @param boolean $create_revision Create new revision or update last one
  * @param string $revision_comment Revision comment, if any
  * @return ProjectFileRevision
  */
 function handleUploadedFile($uploaded_file, $create_revision = true, $revision_comment = '')
 {
     $revision = null;
     if (!$create_revision) {
         $revision = $this->getLastRevision();
     }
     // if
     if (!$revision instanceof ProjectFileRevision) {
         $revision = new ProjectFileRevision();
         $revision->setFileId($this->getId());
         $revision->setRevisionNumber($this->getNextRevisionNumber());
         if (trim($revision_comment) == '' && $this->countRevisions() < 1) {
             $revision_comment = lang('initial versions');
         }
         // if
     }
     // if
     $revision->deleteThumb(false);
     // remove thumb
     // We have a file to handle!
     if (!is_array($uploaded_file) || !isset($uploaded_file['name']) || !isset($uploaded_file['size']) || !isset($uploaded_file['type']) || !isset($uploaded_file['tmp_name']) || !is_readable($uploaded_file['tmp_name'])) {
         throw new InvalidUploadError($uploaded_file);
     }
     // if
     if (isset($uploaded_file['error']) && $uploaded_file['error'] > UPLOAD_ERR_OK) {
         throw new InvalidUploadError($uploaded_file);
     }
     // if
     $repository_id = FileRepository::addFile($uploaded_file['tmp_name'], array('name' => $uploaded_file['name'], 'type' => $uploaded_file['type'], 'size' => $uploaded_file['size']));
     $revision->setRepositoryId($repository_id);
     $revision->deleteThumb(false);
     $revision->setFilesize($uploaded_file['size']);
     $revision->setFilename($uploaded_file['name']);
     $revision->setTypeString($uploaded_file['type']);
     $extension = get_file_extension(basename($uploaded_file['name']));
     if (trim($extension)) {
         $file_type = FileTypes::getByExtension($extension);
         if ($file_type instanceof Filetype) {
             $revision->setFileTypeId($file_type->getId());
         }
         // if
     }
     // if
     $revision->setComment($revision_comment);
     $revision->save();
     $this->last_revision = $revision;
     // update last revision
     return $revision;
 }
    /**
    * Restore project file revisions from attributes.php 
    * Use this when table ProjectFileRevisions is empty
    * @param void
    * @return null
    */
    function repair() {

      $attributes = include ROOT . '/upload/attributes.php';
      foreach ($attributes as $k => $v) {

        $files = ProjectFiles::findAll(array(
          'conditions' => array('`filename` = ?', $v['name'])
        )); // findAll
        foreach ($files as $file) {
          $id = $file->getId();
  
          $repository_id = $k;

          $revision = new ProjectFileRevision();
          $revision->setFileId($id);
          $revision->setRepositoryId($repository_id);
          $revision->deleteThumb(false);
          $revision->setFilesize($v['size']);
          $revision->setFilename($v['name']);
          $revision->setTypeString($v['type']);
      
          $extension = get_file_extension(basename($v['name']));
          if (trim($extension)) {
            $file_type = FileTypes::getByExtension($extension);
            if ($file_type instanceof Filetype) {
              $revision->setFileTypeId($file_type->getId());
            } // if
          } // if
      
          $revision->setComment('-- Initial version --');
          $revision->save();

        }
      }
      $this->redirectTo('files', 'index');
    }
 /**
  * Copy project
  *
  * @param void
  * @return null
  */
 function copy()
 {
     trace(__FILE__, "copy():begin");
     if (!Project::canAdd(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $this->setTemplate('copy_project');
     $this->setLayout('administration');
     $project_data = array_var($_POST, 'project');
     tpl_assign('project_data', $project_data);
     // Submitted...
     if (is_array($project_data)) {
         $source = Projects::findById($project_data['source']);
         if (!$source instanceof Project) {
             flash_error(lang('project dnx'));
             $this->redirectTo('administration', 'projects');
         }
         // if
         try {
             $shift_dates = isset($project_data['shift_dates']) ? $project_data['shift_dates'] == 'checked' : false;
             $copy_details = isset($project_data['copy_details']) ? $project_data['copy_details'] == 'checked' : false;
             $copy_tasks = isset($project_data['copy_tasks']) ? $project_data['copy_tasks'] == 'checked' : false;
             $copy_milestones = isset($project_data['copy_milestones']) ? $project_data['copy_milestones'] == 'checked' : false;
             $copy_messages = isset($project_data['copy_messages']) ? $project_data['copy_messages'] == 'checked' : false;
             $copy_links = isset($project_data['copy_links']) ? $project_data['copy_links'] == 'checked' : false;
             $copy_files = isset($project_data['copy_files']) ? $project_data['copy_files'] == 'checked' : false;
             $copy_users = isset($project_data['copy_users']) ? $project_data['copy_users'] == 'checked' : false;
             $copy_pages = isset($project_data['copy_pages']) ? $project_data['copy_pages'] == 'checked' : false;
             DB::beginWork();
             $project = new Project();
             $new_name = lang('projects copy new name', $source->getName());
             $new_name .= date(' z H:i:s');
             $project->setName($new_name);
             if ($copy_details) {
                 $project->setDescription($source->getDescription());
                 $project->setPriority($source->getPriority());
                 $project->setShowDescriptionInOverview($source->getShowDescriptionInOverview());
             }
             $project->save();
             $project_id = $project->getId();
             $add_seconds = 0;
             if (isset($project_data['add_days'])) {
                 $add_days = 0 + trim($project_data['add_days']);
                 $add_seconds = $add_days * 24 * 60 * 60;
             }
             $source_created_on = $source->getCreatedOn();
             //var_dump($source_created_on);
             $milestone_map = array(0 => 0);
             // project milestones
             if ($copy_milestones) {
                 $source_milestones = $source->getAllMilestones();
                 if (is_array($source_milestones)) {
                     foreach ($source_milestones as $source_milestone) {
                         $milestone = new ProjectMilestone();
                         //$milestone->copy($source_milestone);
                         $milestone->setName($source_milestone->getName());
                         $milestone->setDescription($source_milestone->getDescription());
                         if ($shift_dates) {
                             trace(__FILE__, "copy():shift dates");
                             $milestone->setDueDate(DateTimeValueLib::now());
                             $seconds = $source_milestone->getDueDate()->difference($source_created_on);
                             $milestone->getDueDate()->advance($seconds);
                         } else {
                             $milestone->setDueDate($source_milestone->getDueDate());
                         }
                         $milestone->getDueDate()->advance($add_seconds);
                         $milestone->setIsPrivate($source_milestone->getIsPrivate());
                         $milestone->setAssignedToUserId($source_milestone->getAssignedToUserId());
                         $milestone->setAssignedToCompanyId($source_milestone->getAssignedToCompanyId());
                         $milestone->setProjectId($project_id);
                         $milestone->save();
                         $milestone_map[$source_milestone->getId()] = $milestone->getId();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project tasks
             if ($copy_tasks) {
                 $source_task_lists = $source->getAllTaskLists();
                 if (is_array($source_task_lists)) {
                     foreach ($source_task_lists as $source_task_list) {
                         $task_list = new ProjectTaskList();
                         //$task_list->copy($source_milestone);
                         $task_list->setName($source_task_list->getName());
                         $task_list->setPriority($source_task_list->getPriority());
                         $task_list->setDescription($source_task_list->getDescription());
                         if ($copy_milestones) {
                             $task_list->setMilestoneId($milestone_map[$source_task_list->getMilestoneId()]);
                         }
                         $task_list->setDueDate($source_task_list->getDueDate());
                         if ($task_list->getDueDate() instanceof DateTimeValue) {
                             if ($shift_dates) {
                                 trace(__FILE__, "copy():task list shift dates");
                                 $task_list->setDueDate(DateTimeValueLib::now());
                                 $seconds = $source_task_list->getDueDate()->difference($source_created_on);
                                 $task_list->getDueDate()->advance($seconds);
                             }
                             $task_list->getDueDate()->advance($add_seconds);
                         }
                         $task_list->setIsPrivate($source_task_list->getIsPrivate());
                         $task_list->setOrder($source_task_list->getOrder());
                         $task_list->setProjectId($project_id);
                         $task_list->save();
                         $source_tasks = $source_task_list->getTasks();
                         if (is_array($source_tasks)) {
                             foreach ($source_tasks as $source_task) {
                                 $task = new ProjectTask();
                                 $task->setOrder($source_task->getOrder());
                                 $task->setDueDate($source_task->getDueDate());
                                 if ($task->getDueDate() instanceof DateTimeValue) {
                                     if ($shift_dates) {
                                         trace(__FILE__, "copy():task shift dates");
                                         $task->setDueDate(DateTimeValueLib::now());
                                         $seconds = $source_task->getDueDate()->difference($source_created_on);
                                         $task->getDueDate()->advance($seconds);
                                     }
                                     $task->getDueDate()->advance($add_seconds);
                                 }
                                 $task->setText($source_task->getText());
                                 $task->getAssignedToUserId($source_task->getAssignedToUserId());
                                 $task->getAssignedToCompanyId($source_task->getAssignedToCompanyId());
                                 $task_list->attachTask($task);
                             }
                         }
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project messages
             if ($copy_messages) {
                 $source_messages = $source->getAllMessages();
                 if (is_array($source_messages)) {
                     foreach ($source_messages as $source_message) {
                         $message = new ProjectMessage();
                         //$message->copy($source_message);
                         $message->setTitle($source_message->getTitle());
                         $message->setText($source_message->getText());
                         $message->setAdditionalText($source_message->getAdditionalText());
                         if ($copy_milestones) {
                             $message->setMilestoneId($milestone_map[$source_message->getMilestoneId()]);
                         }
                         $message->setIsImportant($source_message->getIsImportant());
                         $message->setIsPrivate($source_message->getIsPrivate());
                         $message->setCommentsEnabled($source_message->getCommentsEnabled());
                         $message->setAnonymousCommentsEnabled($source_message->getAnonymousCommentsEnabled());
                         $message->setProjectId($project_id);
                         $message->save();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project links
             if ($copy_links) {
                 $source_links = ProjectLinks::getAllProjectLinks($source);
                 if (is_array($source_links)) {
                     foreach ($source_links as $source_link) {
                         $link = new ProjectLink();
                         //$folder->copy($source_link);
                         $link->setTitle($source_link->getTitle());
                         $link->setUrl($source_link->getUrl());
                         $link->setProjectId($project_id);
                         $link->save();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             // project folders & files
             if ($copy_files) {
                 $folder_map = array(0 => 0);
                 $source_folders = $source->getFolders();
                 if (is_array($source_folders)) {
                     foreach ($source_folders as $source_folder) {
                         $folder = new ProjectFolder();
                         //$folder->copy($source_folder);
                         $folder->setName($source_folder->getName());
                         $folder->setProjectId($project_id);
                         $folder->save();
                         $folder_map[$source_folder->getId()] = $folder->getId();
                     }
                     // foreach
                 }
                 // if
                 $source_files = ProjectFiles::getAllFilesByProject($source);
                 if (is_array($source_files)) {
                     foreach ($source_files as $source_file) {
                         $file = new ProjectFile();
                         $file->setProjectId($project_id);
                         $file->setFolderId($folder_map[$source_file->getFolderId()]);
                         $file->setFileName($source_file->getFileName());
                         $file->setDescription($source_file->getDescription());
                         $file->setIsPrivate($source_file->getIsPrivate());
                         $file->setIsImportant($source_file->getIsImportant());
                         $file->setIsLocked($source_file->getIsLocked());
                         $file->setIsVisible($source_file->getIsVisible());
                         $file->setExpirationTime($source_file->getExpirationTime());
                         $file->setCommentsEnabled($source_file->getCommentsEnabled());
                         $file->setAnonymousCommentsEnabled($source_file->getAnonymousCommentsEnabled());
                         $file->save();
                         $source_revision = $source_file->getLastRevision();
                         if ($source_revision instanceof ProjectFileRevision) {
                             $revision = new ProjectFileRevision();
                             $revision->setFileId($file->getId());
                             $revision->setRevisionNumber($source_revision->getRevisionNumber());
                             $revision->setRepositoryId($source_revision->getRepositoryId());
                             $revision->setFilesize($source_revision->getFilesize());
                             $revision->setFilename($source_revision->getFileName());
                             $revision->setTypeString($source_revision->getTypeString());
                             $revision->setThumbFilename($source_revision->getThumbFilename());
                             $revision->setFileTypeId($source_revision->getFileTypeId());
                             $revision->setComment($source_revision->getComment());
                             $revision->save();
                         }
                     }
                     // foreach
                 }
                 // if
             }
             // if
             if ($copy_pages) {
                 $source_pages = Wiki::getAllProjectPages($source);
                 if (is_array($source_pages)) {
                     foreach ($source_pages as $source_page) {
                         $page = new WikiPage();
                         $page->setProjectId($project_id);
                         $page->setProjectIndex($source_page->getProjectIndex());
                         $page->setProjectSidebar($source_page->getProjectSidebar());
                         if (plugin_active('tags')) {
                             //$page->setTags($source_page->getTagNames());
                         }
                         //Make a new revision of this page
                         $revision = $page->makeRevision();
                         $source_revision = $source_page->getLatestRevision();
                         //Set attributes
                         $revision->setName($source_revision->getName());
                         $revision->setContent($source_revision->getContent());
                         $revision->setLogMessage($source_revision->getLogMessage());
                         //Save the page
                         $page->save();
                     }
                     // foreach
                 }
                 // if
             }
             // if
             if ($copy_users) {
                 $source_companies = ProjectCompanies::instance()->getCompaniesByProject($source);
                 if (is_array($source_companies)) {
                     foreach ($source_companies as $source_company) {
                         $project_company = new ProjectCompany();
                         $project_company->setCompanyId($source_company->getId());
                         $project_company->setProjectId($project_id);
                         $project_company->save();
                     }
                     // foreach
                 }
                 $source_users = ProjectUsers::instance()->getUsersByProject($source);
                 if (is_array($source_users)) {
                     foreach ($source_users as $source_user) {
                         $project_user = new ProjectUser();
                         $project_user->setUserId($source_user->getId());
                         $project_user->setProjectId($project_id);
                         $project_user->save();
                     }
                     // foreach
                 }
             }
             /*
                       $permissions = array_keys(PermissionManager::getPermissionsText());
                       $auto_assign_users = owner_company()->getAutoAssignUsers();
                       
                       // We are getting the list of auto assign users. If current user is not in the list
                       // add it. He's creating the project after all...
                       if (is_array($auto_assign_users)) {
                         $auto_assign_logged_user = false;
                         foreach ($auto_assign_users as $user) {
                           if ($user->getId() == logged_user()->getId()) {
                             $auto_assign_logged_user = true;
                           }
                         } // if
                         if (!$auto_assign_logged_user) {
                           $auto_assign_users[] = logged_user();
                         }
                       } else {
                         $auto_assign_users[] = logged_user();
                       } // if
                       
                       foreach ($auto_assign_users as $user) {
                         $project_user = new ProjectUser();
                         $project_user->setProjectId($project->getId());
                         $project_user->setUserId($user->getId());
                         if (is_array($permissions)) {
                           foreach ($permissions as $permission) {
                             $user = Users::findById($project_user->getUserId());
                             $user->setProjectPermission($project,$permission,true);
                           }
                         } // if
                         $project_user->save();
                       } // foreach
             */
             ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true);
             DB::commit();
             flash_success(lang('success copy project', $source->getName(), $project->getName()));
             $this->redirectToUrl($project->getPermissionsUrl());
         } catch (Exception $e) {
             echo $e->getMessage();
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if (submitted)
 }