/**
  * This function will return content of specific searchable column. It uses inherited
  * behaviour for all columns except for `filecontent`. In case of this column function
  * will return file content if file type is marked as searchable (text documents, office
  * documents etc).
  *
  * @param string $column_name Column name
  * @return string
  */
 function getSearchableColumnContent($column_name)
 {
     if ($column_name == 'filecontent') {
         $file_type = $this->getFileType();
         // Unknown type or type not searchable
         if (!$file_type instanceof FileType) {
             return null;
         }
         // if
         // Simple search for .txt and .html documents
         if ($file_type->getIsSearchable()) {
             $content = strip_tags($this->getFileContent());
             // Remove unnecesary html tags
             if (strlen($content) > MAX_SEARCHABLE_FILE_SIZE) {
                 $content = substr($content, 0, MAX_SEARCHABLE_FILE_SIZE);
             }
             return $content;
         } else {
             // Search for .doc and .ppt documents
             if (($this->getFileType()->getExtension() == "doc" || $this->getFileType()->getExtension() == "ppt") && FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
                 $backend = FileRepository::getBackend();
                 if ($backend->isInRepository($this->getRepositoryId())) {
                     $filepath = $backend->getFilePath($this->getRepositoryId());
                     $fileContents = $this->cat_file($filepath, $this->getFileType()->getExtension());
                     if ($fileContents) {
                         if (strlen($fileContents) > MAX_SEARCHABLE_FILE_SIZE) {
                             $fileContents = substr($fileContents, 0, MAX_SEARCHABLE_FILE_SIZE);
                         }
                         return $fileContents;
                     }
                 }
             }
         }
         return null;
     } else {
         return parent::getSearchableColumnContent($column_name);
     }
 }
	function zip_add() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		ajx_current("empty");
		if (!zip_supported()) {
			flash_error(lang('zip not supported'));
			return;
		}

		$files = ProjectFiles::findByCSVIds(array_var($_GET, 'objects'), '`type` = 0');
		if (count($files) == 0) {
			flash_error(lang('no files to compress'));
			return;
		}
                
		$isnew = false;
		$file = null;
		if (array_var($_GET, 'filename')) {
			$filename = array_var($_GET, 'filename');
			$isnew = true;
		} else if (array_var($_GET, 'id')) {
			$file = ProjectFiles::findById(array_var($_GET, 'id'));
			$filename = $file->getFilename();
		}
		
		$tmp_zip_path = ROOT.'/tmp/'.rand().'.zip';
		$handle = fopen($tmp_zip_path, 'wb');
		if (!$isnew) {
			$content = $file->getLastRevision()->getFileContent();
			fwrite($handle, $content, $file->getLastRevision()->getFilesize());
		}
		fclose($handle);
		
		$zip = new ZipArchive();
		if (!$isnew) $zip->open($tmp_zip_path);
		else $zip->open($tmp_zip_path, ZipArchive::OVERWRITE);
		
		$tmp_dir = ROOT.'/tmp/'.rand().'/';
		mkdir($tmp_dir);
		$members = array();
		foreach ($files as $file_to_add) {
			if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
				$file_to_add_path = FileRepository::getBackend()->getFilePath($file_to_add->getLastRevision()->getRepositoryId());
			} else {
				$file_to_add_path = $tmp_dir . $file_to_add->getFilename();
				$handle = fopen($file_to_add_path, 'wb');
				fwrite($handle, $file_to_add->getLastRevision()->getFileContent(), $file_to_add->getLastRevision()->getFilesize());
				fclose($handle);
			}
			$zip->addFile($file_to_add_path, utf8_safe($file_to_add->getFilename()));
			$members[] = $file_to_add->getMemberIds();
		}
		$zip->close();
		delete_dir($tmp_dir);
                
		$this->upload_file($file, $filename, $tmp_zip_path, $members);
		unlink($tmp_zip_path);
		
		flash_success(lang('success compressing files', count($files)));
		ajx_current("reload");
	}
 private static function getLogoAttachmentData($toemail)
 {
     $logo_info = array();
     try {
         $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
         if ($content != "") {
             $file_path = ROOT . "/tmp/logo_empresa.png";
             $handle = fopen($file_path, 'wb');
             if ($handle) {
                 fwrite($handle, $content);
                 fclose($handle);
                 if (!$toemail) {
                     $toemail = "recipient@";
                 }
                 $logo_info = array('cid' => gen_id() . substr($toemail, strpos($toemail, '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
             }
         }
     } catch (FileNotInRepositoryError $e) {
         Logger::log("Could not find owner company picture file: " . $e->getMessage());
     }
     $logo_info;
 }
 private function readAttachmentsFromFileSystem(MailContent $mail, &$att_version)
 {
     $att_version = 2;
     if ($mail->getHasAttachments() && FileRepository::isInRepository($mail->getContentFileId())) {
         $attachments = array();
         $content = FileRepository::getFileContent($mail->getContentFileId());
         if (str_starts_with($content, "--")) {
             $att_version = 1;
         } else {
             if (str_starts_with($content, "#att_ver")) {
                 $att_version = trim(str_replace("#att_ver", "", substr($content, 0, strpos($content, "\n"))));
             }
         }
         if ($att_version < 2) {
             $i = 0;
             $offset = 0;
             while ($offset < strlen($content)) {
                 $delim = "--000000000000000000000000000{$i}";
                 if (strpos($content, $delim, $offset) !== FALSE) {
                     $offset = strpos($content, $delim) + strlen($delim);
                     $endline = strpos($content, ";", $offset);
                     $name = substr($content, $offset + 1, $endline - $offset - 1);
                     $pos = strpos($name, ":");
                     $name = trim(substr($name, $pos + 1, strlen($name) - $pos - 1));
                     $offset = $endline + 1;
                     $endline = strpos($content, ";", $offset);
                     $type = substr($content, $offset + 1, $endline - $offset - 1);
                     $pos = strpos($type, ":");
                     $type = trim(substr($type, $pos + 1, strlen($type) - $pos - 1));
                     $offset = $endline + 1;
                     $endline = strpos($content, "{$delim}--");
                     $attachments[] = array('name' => $name, 'type' => $type, 'data' => base64_decode(trim(substr($content, $offset, $endline - $offset - 1))));
                     $offset = strpos($content, "{$delim}--") + strlen("{$delim}--") + 1;
                 } else {
                     break;
                 }
                 $i++;
             }
         } else {
             $lines = explode("\n", $content);
             foreach ($lines as $line) {
                 if (!str_starts_with($line, "#") && trim($line) !== "") {
                     $data = explode(",", $line);
                     if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
                         $path = FileRepository::getBackend()->getFilePath($data[2]);
                     } else {
                         $path = ROOT . "/tmp/" . gen_id();
                         file_put_contents($path, FileRepository::getFileContent($data[2]));
                     }
                     $attachments[] = array('name' => $data[0], 'type' => $data[1], 'path' => $path, 'repo_id' => $data[2]);
                 }
             }
         }
     } else {
         $attachments = null;
     }
     return $attachments;
 }
Example #5
0
/**
 * Download a file from the file repository.
 * 
 * @param string $id
 * @param string $type
 * @param string $name
 * @param boolean $force_download
 * @return boolean
 */
function download_from_repository($id, $type, $name, $force_download = false) {
	if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
		$path = FileRepository::getBackend()->getFilePath($id);
		if (is_file($path)) {
			// this method allows downloading big files without exhausting php's memory
			return download_file($path, $type, $name, $force_download);
		}
	}
	$content = FileRepository::getBackend()->getFileContent($id);
	return download_contents($content, $type, $name, strlen($content), $force_download);
}
Example #6
0
	function workEstimate(ProjectTask $task) {
		tpl_assign('task_assigned', $task);
		
		if(!($task->getAssignedTo() instanceof Contact)) {
			return true; // not assigned to user
		}
		if (!is_valid_email($task->getAssignedTo()->getEmailAddress())) {
			return true;
		}

		$locale = $task->getAssignedTo()->getLocale();
		Localization::instance()->loadSettings($locale, ROOT . '/language');
                
                tpl_assign('title', $task->getObjectName());
                tpl_assign('by', $task->getAssignedBy()->getObjectName());
                tpl_assign('asigned', $task->getAssignedTo()->getObjectName());
                $text = "";
                if(config_option("wysiwyg_tasks")){
                    $text = purify_html(nl2br($task->getDescription()));
                }else{
                    $text = escape_html_whitespace($task->getDescription());
                }
                tpl_assign('description', $text);//descripction
                tpl_assign('description_title', lang("new task work estimate to you desc", $task->getObjectName(),$task->getAssignedBy()->getObjectName()));//description_title
                
                //priority
                if ($task->getPriority()) {
                    if ($task->getPriority() >= ProjectTasks::PRIORITY_URGENT) {
                            $priorityColor = "#FF0000";
                            $priority = lang('urgent priority');
                    }else if ($task->getPriority() >= ProjectTasks::PRIORITY_HIGH) {
                            $priorityColor = "#FF9088";
                            $priority = lang('high priority');
                    } else if ($task->getPriority() <= ProjectTasks::PRIORITY_LOW) {
                            $priorityColor = "white";
                            $priority = lang('low priority');
                    }else{
                            $priorityColor = "#DAE3F0";
                            $priority = lang('normal priority');
                    }
                    tpl_assign('priority', array($priority,$priorityColor));
		}
		
		//context		
		$contexts = array();
		$members = $task->getMembers();
		if(count($members)>0){
			foreach ($members as $member){
				$dim = $member->getDimension();
				if($dim->getIsManageable()){
					if ($dim->getCode() == "customer_project"){
						$obj_type = ObjectTypes::findById($member->getObjectTypeId());
						if ($obj_type instanceof ObjectType) {
							$contexts[$dim->getCode()][$obj_type->getName()][]= '<span style="'.get_workspace_css_properties($member->getMemberColor()).'">'. $member->getName() .'</span>';
						}
					}else{
						$contexts[$dim->getCode()][]= '<span style="'.get_workspace_css_properties($member->getMemberColor()).'">'. $member->getName() .'</span>';
					}
				}
			}
		}
                tpl_assign('contexts', $contexts);//workspaces
                
                //start date, due date or start
                if ($task->getStartDate() instanceof DateTimeValue) {
			$date = Localization::instance()->formatDescriptiveDate($task->getStartDate(), $task->getAssignedTo()->getTimezone());
			$time = Localization::instance()->formatTime($task->getStartDate(), $task->getAssignedTo()->getTimezone());
                        if($time > 0)
                        $date .= " " . $time;
                        tpl_assign('start_date', $date);//start_date
		}
                
		if ($task->getDueDate() instanceof DateTimeValue) {
			$date = Localization::instance()->formatDescriptiveDate($task->getDueDate(), $task->getAssignedTo()->getTimezone());
			$time = Localization::instance()->formatTime($task->getDueDate(), $task->getAssignedTo()->getTimezone());
                        if($time > 0)
                        $date .= " " . $time;
                        tpl_assign('due_date', $date);//due_date
		}

		$attachments = array();
		try {
			$content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
			if ($content) {
				$file_path = ROOT . "/tmp/logo_empresa.png";
				$handle = fopen($file_path, 'wb');
				if ($handle) {
					fwrite($handle, $content);
					fclose($handle);
					$attachments['logo'] = array(
						'cid' => gen_id() . substr($task->getAssignedBy()->getEmailAddress(), strpos($task->getAssignedBy()->getEmailAddress(), '@')),
						'path' => $file_path,
						'type' => 'image/png',
						'disposition' => 'inline',
						'name' => 'logo_empresa.png',
					);
				}
			}
		} catch (FileNotInRepositoryError $e) {
			unset($attachments['logo']);
		}
		tpl_assign('attachments', $attachments);// attachments
		
                //ALL SUBSCRIBERS
                if($task->getSubscribers()){
                    $subscribers = $task->getSubscribers();
                    $string_subscriber = '';
                    $total_s = count($subscribers);
                    $c = 0;
                    foreach ($subscribers as $subscriber){
                        $c++;
                        if($c == $total_s && $total_s > 1){
                            $string_subscriber .= lang('and');
                        }else if($c > 1){
                            $string_subscriber .= ", ";
                        }

                        $string_subscriber .= $subscriber->getFirstName();
                        if($subscriber->getSurname() != "")
                            $string_subscriber .=" " . $subscriber->getSurname();

                    }
                    tpl_assign('subscribers', $string_subscriber);// subscribers
                }
		
		if($task->getAssignedById() == $task->getAssignedToContactId()){
			$emails[] = array(
                            "to" => array(self::prepareEmailAddress($task->getAssignedBy()->getEmailAddress(), $task->getAssignedBy()->getObjectName())),
                            "from" => self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()),
                            "subject" => lang('work estimate title'),
                            "body" => tpl_fetch(get_template_path('work_estimate', 'notifier')),
                            "attachments" => $attachments
                        ); 
		}else{
			$emails[] = array(
                            "to" => array(self::prepareEmailAddress($task->getAssignedBy()->getEmailAddress(), $task->getAssignedBy()->getObjectName())),
                            "from" => self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()),
                            "subject" => lang('work estimate title'),
                            "body" => tpl_fetch(get_template_path('work_estimate', 'notifier')),
                            "attachments" => $attachments
                        );
			$emails[] = array(
                            "to" => array(self::prepareEmailAddress($task->getAssignedTo()->getEmailAddress(), $task->getAssignedTo()->getObjectName())),
                            "from" => self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()),
                            "subject" => lang('work estimate title'),
                            "body" => tpl_fetch(get_template_path('work_estimate', 'notifier')),
                            "attachments" => $attachments
			);
		}
		self::queueEmails($emails);
		
		$locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
		Localization::instance()->loadSettings($locale, ROOT . '/language');
	}
Example #7
0
 function workEstimate(ProjectTask $task)
 {
     tpl_assign('task_assigned', $task);
     if (!$task->getAssignedTo() instanceof Contact) {
         return true;
         // not assigned to user
     }
     if (!is_valid_email($task->getAssignedTo()->getEmailAddress())) {
         return true;
     }
     $locale = $task->getAssignedTo()->getLocale();
     Localization::instance()->loadSettings($locale, ROOT . '/language');
     tpl_assign('title', $task->getObjectName());
     tpl_assign('by', $task->getAssignedBy()->getObjectName());
     tpl_assign('asigned', $task->getAssignedTo()->getObjectName());
     $text = "";
     if (config_option("wysiwyg_tasks")) {
         $text = purify_html(nl2br($task->getDescription()));
     } else {
         $text = escape_html_whitespace($task->getDescription());
     }
     tpl_assign('description', $text);
     //descripction
     tpl_assign('description_title', lang("new task work estimate to you desc", $task->getObjectName(), $task->getCreatedBy()->getObjectName()));
     //description_title
     //priority
     if ($task->getPriority()) {
         if ($task->getPriority() >= ProjectTasks::PRIORITY_URGENT) {
             $priorityColor = "#FF0000";
             $priority = lang('urgent priority');
         } else {
             if ($task->getPriority() >= ProjectTasks::PRIORITY_HIGH) {
                 $priorityColor = "#FF9088";
                 $priority = lang('high priority');
             } else {
                 if ($task->getPriority() <= ProjectTasks::PRIORITY_LOW) {
                     $priorityColor = "white";
                     $priority = lang('low priority');
                 } else {
                     $priorityColor = "#DAE3F0";
                     $priority = lang('normal priority');
                 }
             }
         }
         tpl_assign('priority', array($priority, $priorityColor));
     }
     //context
     $contexts = array();
     if ($task->getMembersToDisplayPath()) {
         $members = $task->getMembersToDisplayPath();
         foreach ($members as $key => $member) {
             $dim = Dimensions::getDimensionById($key);
             if ($dim->getCode() == "customer_project") {
                 foreach ($members[$key] as $member) {
                     $obj_type = ObjectTypes::findById($member['ot']);
                     $contexts[$dim->getCode()][$obj_type->getName()][] = '<span style="' . get_workspace_css_properties($member['c']) . '">' . $member['name'] . '</span>';
                 }
             } else {
                 foreach ($members[$key] as $member) {
                     $contexts[$dim->getCode()][] = '<span style="' . get_workspace_css_properties($member['c']) . '">' . $member['name'] . '</span>';
                 }
             }
         }
     }
     tpl_assign('contexts', $contexts);
     //workspaces
     //start date, due date or start
     if ($task->getStartDate() instanceof DateTimeValue) {
         $date = Localization::instance()->formatDescriptiveDate($task->getStartDate(), $task->getAssignedTo()->getTimezone());
         $time = Localization::instance()->formatTime($task->getStartDate(), $task->getAssignedTo()->getTimezone());
         if ($time > 0) {
             $date .= " " . $time;
         }
         tpl_assign('start_date', $date);
         //start_date
     }
     if ($task->getDueDate() instanceof DateTimeValue) {
         $date = Localization::instance()->formatDescriptiveDate($task->getDueDate(), $task->getAssignedTo()->getTimezone());
         $time = Localization::instance()->formatTime($task->getDueDate(), $task->getAssignedTo()->getTimezone());
         if ($time > 0) {
             $date .= " " . $time;
         }
         tpl_assign('due_date', $date);
         //due_date
     }
     $attachments = array();
     try {
         $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
         $file_path = ROOT . "/upload/logo_empresa.png";
         $handle = fopen($file_path, 'wb');
         fwrite($handle, $content);
         fclose($handle);
         if ($content != "") {
             $attachments['logo'] = array('cid' => gen_id() . substr($task->getAssignedBy()->getEmailAddress(), strpos($task->getAssignedBy()->getEmailAddress(), '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
             tpl_assign('attachments', $attachments);
             // attachments
         }
     } catch (FileNotInRepositoryError $e) {
         // If no logo is set, don't interrupt notifications.
     }
     tpl_assign('attachments', $attachments);
     // attachments
     self::queueEmail(array(self::prepareEmailAddress($task->getCreatedBy()->getEmailAddress(), $task->getCreatedBy()->getObjectName())), self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()), lang('work estimate title'), tpl_fetch(get_template_path('work_estimate', 'notifier')), 'text/html', '8bit', $attachments);
     // send
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
 }
Example #8
0
if (file_exists($dir)) {
    foreach (new DirectoryIterator($dir) as $file) {
        if (true === $file->isFile()) {
            unlink($file->getPathName());
        }
    }
} else {
	mkdir($dir, 0777, true);
}

if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
	$files = ProjectFiles::findAll();
	foreach ($files as $file) {
		$filename = $file->getFilename();
		$id = $file->getLastRevision()->getRepositoryId();
		$path = FileRepository::getBackend()->getFilePath($id);
		$newpath = "$dir/$filename";
		if (file_exists($newpath)) {
			$tmppath = $newpath;
			$ext = strrpos($newpath, ".");
			if ($ext === false) {
				$name = $newpath;
				$ext = "";
			} else {
				$name = substr($newpath, 0, $ext);
				$ext = substr($newpath, $ext + 1);
			}
			for ($i=2; file_exists($tmppath); $i++) {
				$tmppath = "$name-$i.$ext";
			}
			$newpath = $tmppath;