Beispiel #1
0
 public function render($return = false)
 {
     $this->_pdf = new \GO\Base\Util\Pdf();
     $this->_pdf->title = $this->name();
     if (!empty($_REQUEST['startdate'])) {
         $this->_pdf->subtitle = $_REQUEST['startdate'];
         if (!empty($_REQUEST['enddate'])) {
             $this->_pdf->subtitle .= " - " . $_REQUEST['enddate'];
         }
     }
     $this->_pdf->AddPage();
     $this->_addTimeEntries();
     if ($this->project) {
         $findParams = GO\Base\Db\FindParams::newInstance();
         $findParams->getCriteria()->addCondition("path", $this->project->path . '/%', 'LIKE');
         $findParams->getCriteria()->addCondition("id", $this->project->id, 'LIKE', 't', false);
         $stmt = GO\Projects2\Model\Project::model()->find($findParams);
         if ($stmt->rowCount()) {
             $this->_pdf->Ln(10);
             $this->_pdf->h2(GO::t('timeEntriesPerProject', 'projects2'));
             foreach ($stmt as $project) {
                 $this->_addTimeEntries($project);
             }
         }
     } else {
         $this->_addHolidays();
     }
     if ($return) {
         return $this->_pdf->Output($this->filename . ".pdf", 'I');
     } else {
         \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\Fs\File($this->filename . ".pdf"));
         echo $this->_pdf->Output($this->filename . ".pdf", 'I');
     }
 }
Beispiel #2
0
 protected function actionDownload($params)
 {
     $version = \GO\Files\Model\Version::model()->findByPk($params['id']);
     $file = $version->getFilesystemFile();
     \GO\Base\Util\Http::outputDownloadHeaders($file);
     $file->output();
 }
 public function actionDownload($params)
 {
     //fetch account for permission check.
     $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
     $cert = \GO\Smime\Model\Certificate::model()->findByPk($account->id);
     if (!$cert) {
         throw new \GO\Base\Exception\NotFound();
     }
     $filename = str_replace(array('@', '.'), '-', $account->getDefaultAlias()->email) . '.p12';
     $file = new \GO\Base\Fs\File($filename);
     \GO\Base\Util\Http::outputDownloadHeaders($file);
     echo $cert->cert;
 }
 /**
  * Export the contact model to a .csv, including the company.
  * 
  * @param array $params
  */
 public function export($params)
 {
     GO::$disableModelCache = true;
     GO::setMaxExecutionTime(420);
     // Load the data from the session.
     $findParams = \GO::session()->values['contact']['findParams'];
     $findParams->getCriteria()->recreateTemporaryTables();
     $model = \GO::getModel(\GO::session()->values['contact']['model']);
     // Include the companies
     $findParams->joinRelation('company', 'LEFT');
     // Let the export handle all found records without a limit
     $findParams->limit(0);
     // Create the statement
     $stmt = $model->find($findParams);
     // Create the csv file
     $csvFile = new \GO\Base\Fs\CsvFile(\GO\Base\Fs\File::stripInvalidChars('export.csv'));
     // Output the download headers
     \GO\Base\Util\Http::outputDownloadHeaders($csvFile, false);
     $csvWriter = new \GO\Base\Csv\Writer('php://output');
     $headerPrinted = false;
     $attrs = array();
     $compAttrs = array();
     foreach ($stmt as $m) {
         $iterationStartUnix = time();
         if (!$headerPrinted) {
             $attrs = $m->getAttributes();
             $compAttrs = $m->company->getAttributes();
         }
         $header = array();
         $record = array();
         foreach ($attrs as $attr => $val) {
             if (!$headerPrinted) {
                 $header[$attr] = $m->getAttributeLabel($attr);
             }
             $record[$attr] = $m->{$attr};
         }
         foreach ($compAttrs as $cattr => $cval) {
             if (!$headerPrinted) {
                 $header[GO::t('company', 'addressbook') . $cattr] = GO::t('company', 'addressbook') . ':' . $m->company->getAttributeLabel($cattr);
             }
             $record[GO::t('company', 'addressbook') . $cattr] = $m->company->{$cattr};
         }
         if (!$headerPrinted) {
             $csvWriter->putRecord($header);
             $headerPrinted = true;
         }
         $csvWriter->putRecord($record);
     }
 }
 /**
  * Function exporting addressbook contents to VCFs.
  * 
  * @param array $params 
  */
 public function actionExportVCard($params)
 {
     $findParams = \GO\Base\Db\FindParams::loadExportFindParams('contact');
     $findParams->limit(0);
     $store = new \GO\Base\Data\DbStore('GO\\Addressbook\\Model\\Contact', new \GO\Base\Data\ColumnModel('GO\\Addressbook\\Model\\Contact'), $params, $findParams);
     $file = new \GO\Base\Fs\File(\GO::t('contacts', 'addressbook') . '.vcf');
     \GO\Base\Util\Http::outputDownloadHeaders($file);
     while ($record = $store->nextRecord()) {
         $model = \GO\Addressbook\Model\Contact::model()->findByPk($record['id']);
         if (!isset($fileStream)) {
             $fileStream = fopen('php://output', 'w+');
         }
         fwrite($fileStream, $model->toVObject()->serialize());
     }
 }
Beispiel #6
0
 public function render($return = false)
 {
     $this->_pdf = new Pdf('L');
     //		$this->_pdf->font_size=8;
     $this->_pdf->title = $this->name();
     if ($this->project) {
         $this->_pdf->title .= ': ' . $this->project->path;
     }
     if (!empty($_REQUEST['startdate'])) {
         $this->_pdf->subtitle = $_REQUEST['startdate'];
         if (!empty($_REQUEST['enddate'])) {
             $this->_pdf->subtitle .= " - " . $_REQUEST['enddate'];
         }
     }
     $this->_pdf->AddPage();
     $this->_addProjects();
     if ($return) {
         return $this->_pdf->Output($this->filename . ".pdf", 'I');
     } else {
         Http::outputDownloadHeaders(new File($this->filename . ".pdf"));
         echo $this->_pdf->Output($this->filename . ".pdf", 'I');
     }
 }
Beispiel #7
0
 public function render($return = false)
 {
     $this->_pdf = new \GO\Base\Util\Pdf();
     $this->_pdf->title = \GO::t('projectReport', 'projects2');
     if (!empty($_REQUEST['startdate'])) {
         $this->_pdf->subtitle = $_REQUEST['startdate'];
         if (!empty($_REQUEST['enddate'])) {
             $this->_pdf->subtitle .= " - " . $_REQUEST['enddate'];
         }
     }
     $this->_pdf->AddPage();
     $this->_addProjectInfo();
     $this->_addTasks();
     $this->_addTimeEntries();
     $this->_addExpenses();
     //		$this->_addMileage();
     //		exit;
     if ($return) {
         return $this->_pdf->Output($this->filename . ".pdf", 'I');
     } else {
         \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\Fs\File($this->filename . ".pdf"));
         echo $this->_pdf->Output($this->filename . ".pdf", 'I');
     }
 }
 protected function actionViewLog($params)
 {
     $mailing = \GO\Addressbook\Model\SentMailing::model()->findByPk($params['mailing_id']);
     if ($mailing->user_id != \GO::user()->id && !\GO::user()->isAdmin()) {
         throw new \GO\Base\Exception\AccessDenied();
     }
     $file = $mailing->logFile;
     \GO\Base\Util\Http::outputDownloadHeaders($file);
     $file->output();
 }
 /**
  * Run from the browser's address bar. Collects all language files, and puts
  * them in a zip file in the file storage path, respecting the folder
  * structure. I.e., you can later unpack the file contents to the
  * Group-Office path.
  * @param type $params 
  */
 protected function actionZipLanguage($params)
 {
     if (!empty($params['lang'])) {
         $langCode = $params['lang'];
     } else {
         die('<font color="red"><i>The GET parameter lang is required for the zipLanguage action!</i></font>');
     }
     $fileNames = array();
     //gather file list in array
     $commonLangFolder = new \GO\Base\Fs\Folder(\GO::config()->root_path . 'language/');
     if ($commonLangFolder->exists()) {
         $commonLangFolderContentArr = $commonLangFolder->ls();
         $moduleModelArr = \GO::modules()->getAllModules();
         foreach ($commonLangFolderContentArr as $commonLangFolder) {
             if (get_class($commonLangFolder) == 'GO\\Base\\Fs\\Folder') {
                 $commonLangFileArr = $commonLangFolder->ls();
                 foreach ($commonLangFileArr as $commonLangFile) {
                     if (get_class($commonLangFile) == 'GO\\Base\\Fs\\File' && $commonLangFile->name() == $langCode . '.php') {
                         $fileNames[] = str_replace(\GO::config()->root_path, '', $commonLangFile->path());
                     }
                 }
             }
         }
     }
     foreach ($moduleModelArr as $moduleModel) {
         $modLangFolder = new \GO\Base\Fs\Folder($moduleModel->path . 'language/');
         if ($modLangFolder->exists()) {
             $modLangFiles = $modLangFolder->ls();
             foreach ($modLangFiles as $modLangFile) {
                 if ($modLangFile->name() == $langCode . '.php') {
                     $fileNames[] = str_replace(\GO::config()->root_path, '', $modLangFile->path());
                 }
             }
         }
     }
     $tmpFile = \GO\Base\Fs\File::tempFile($langCode . '-' . str_replace('.', '-', \GO::config()->version), 'zip');
     //exec zip
     $cmdString = \GO::config()->cmd_zip . ' ' . $tmpFile->path() . ' ' . implode(" ", $fileNames);
     exec($cmdString, $outputArr, $retVal);
     if ($retVal > 0) {
         trigger_error("Creating ZIP file failed! " . implode("<br />", $outputArr), E_USER_ERROR);
     }
     \GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
     $tmpFile->output();
     $tmpFile->delete();
 }
Beispiel #10
0
 /**
  * Public files are files stored in GO::config()->file_storage_path.'public'
  * They are publicly accessible.
  * Public files are cached
  * 
  * @param String $path 
  */
 protected function actionDownloadPublicFile($params)
 {
     $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . 'public/' . $params['path']);
     if ($file->exists()) {
         \GO\Base\Util\Http::outputDownloadHeaders($file, false, !empty($params['cache']));
         $file->output();
     } else {
         echo "File not found!";
     }
 }
Beispiel #11
0
 protected function actionPhoto($params)
 {
     //fetching contact will check read permission
     $company = \GO\Addressbook\Model\Company::model()->findByPk($params['id']);
     \GO\Base\Util\Http::outputDownloadHeaders($company->getPhotoFile(), true, false);
     $company->getPhotoFile()->output();
 }
Beispiel #12
0
 protected function actionZipAllAttachments($params)
 {
     $account = Account::model()->findByPk($params['account_id']);
     //$imap  = $account->openImapConnection($params['mailbox']);
     $message = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params["mailbox"], $params["uid"]);
     $tmpFolder = \GO\Base\Fs\Folder::tempFolder(uniqid(time()));
     $atts = $message->getAttachments();
     while ($att = array_shift($atts)) {
         if (empty($att->content_id) || $att->disposition == 'attachment') {
             $att->saveToFile($tmpFolder);
         }
     }
     $archiveFile = $tmpFolder->parent()->createChild(GO::t('attachments', 'email') . '.zip');
     \GO\Base\Fs\Zip::create($archiveFile, $tmpFolder, $tmpFolder->ls());
     \GO\Base\Util\Http::outputDownloadHeaders($archiveFile, false);
     readfile($archiveFile->path());
     $tmpFolder->delete();
     $archiveFile->delete();
 }
Beispiel #13
0
 protected function actionExportEventAsIcs($event_id)
 {
     $eventModel = \GO\Calendar\Model\Event::model()->findByPk($event_id);
     if (!$eventModel) {
         throw new Exception('Could not find event with ID #' . $event_id . '.');
     }
     if ($eventModel->exception_for_event_id > 0) {
         $eventModel = \GO\Calendar\Model\Event::model()->findByPk($eventModel->exception_for_event_id);
     }
     if (!$eventModel) {
         throw new Exception('Could not find main recurring event of event #' . $event_id . '.');
     }
     \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\FS\File($eventModel->calendar->name . ' - ' . \GO\Base\Util\Date::get_timestamp($eventModel->start_time) . ' ' . $eventModel->name . '.ics'));
     echo "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Intermesh//NONSGML " . \GO::config()->product_name . " " . \GO::config()->version . "//EN\r\n";
     $t = new \GO\Base\VObject\VTimezone();
     echo $t->serialize();
     $v = $eventModel->toVObject();
     echo $v->serialize();
     $exceptionsStmt = \GO\Calendar\Model\Event::model()->findByAttributes(array('calendar_id' => $eventModel->calendar_id, 'exception_for_event_id' => $eventModel->id));
     foreach ($exceptionsStmt as $exceptionEventModel) {
         $vexc = $exceptionEventModel->toVObject();
         echo $vexc->serialize();
     }
     echo "END:VCALENDAR\r\n";
 }
Beispiel #14
0
 /**
  * Get an example file for importing users
  * 
  * @param array $params 
  */
 protected function actionGetImportExample($params)
 {
     $data = array();
     for ($i = 0; $i < 5; $i++) {
         $data[$i] = array('username' => 'user' . $i, 'password' => 'password' . $i, 'enabled' => $i % 3 ? 1 : 0, 'first_name' => 'firstname' . $i, 'middle_name' => 'middlename' . $i, 'last_name' => 'lastname' . $i, 'initials' => 'AE', 'title' => $i % 2 ? 'Mr.' : 'Mevr.', 'sex' => $i % 2 ? 'M' : 'F', 'birthday' => '0' . ($i + 1) . '-0' . ($i + 3) . '-8' . $i, 'email' => 'email' . $i . '@domain.com', 'company' => 'company', 'department' => 'department', 'function' => 'function', 'home_phone' => '123456789' . $i, 'work_phone' => '623451789' . $i, 'fax' => '423156789' . $i, 'cellular' => '061234567' . $i, 'country' => 'NL', 'state' => 'state', 'city' => 'city', 'zip' => 'zip', 'address' => 'Address', 'address_no' => $i, 'groups' => 'Everyone,Internal,Some_group', 'modules_read' => 'summary,email,addressbook,files', 'modules_write' => 'tasks');
     }
     \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\Fs\File("users.csv"));
     $csvFile = new \GO\Base\Csv\Writer('php://output');
     $header = true;
     foreach ($data as $row) {
         if ($header) {
             $csvFile->putRecord(array_keys($row));
             $header = false;
         }
         $csvFile->putRecord(array_values($row));
     }
 }
Beispiel #15
0
 protected function actionGetAgentPicture()
 {
     if (!isset($_GET['agent_contact_id'])) {
         throw new \GO\Base\Exception\NotFound();
     }
     $contact = \GO\Addressbook\Model\Contact::model()->findByPk($_GET['agent_contact_id'], false, true);
     if (!$contact) {
         throw new \GO\Base\Exception\NotFound();
     }
     \GO\Base\Util\Http::outputDownloadHeaders($contact->getPhotoFile(), true, false);
     $contact->getPhotoFile()->output();
 }
Beispiel #16
0
 private function _sendHeaders()
 {
     $file = new \GO\Base\Fs\File($this->title . '.csv');
     \GO\Base\Util\Http::outputDownloadHeaders($file);
 }
Beispiel #17
0
 public function render($return = false)
 {
     $fp = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select('t.*')->joinRelation('user');
     if (isset($this->startDate)) {
         $fp->getCriteria()->addCondition('date', $this->startDate, '>=', 't');
     }
     if (isset($this->endDate)) {
         $fp->getCriteria()->addCondition('date', $this->endDate, '<', 't');
     }
     //query all subprojects of given path
     if ($this->project) {
         $fp->getCriteria()->addRawCondition('t.project_id', "(SELECT id FROM pr2_projects WHERE path LIKE :path OR project_id = :project_id)", 'IN');
         $fp->getCriteria()->addBindParameter(':path', $this->project->path . '/%');
         $fp->getCriteria()->addBindParameter(':project_id', $this->project->id);
     }
     $stmt = \GO\Projects2\Model\TimeEntry::model()->find($fp);
     $csvFile = \GO\Base\Fs\CsvFile::tempFile($this->filename, $this->fileExtension());
     $attributes = array('user.name', 'date', 'comments', 'project.path', 'internal_fee', 'external_fee', 'units', 'travel_distance', 'travel_costs');
     $csvFile->putRecord($attributes);
     \GO\Projects2\Model\TimeEntry::$attributeOutputMode = 'formatted';
     foreach ($stmt as $timeEntry) {
         $record = array();
         foreach ($attributes as $attr) {
             $relations = explode('.', $attr);
             $attrName = array_pop($relations);
             $model = $timeEntry;
             foreach ($relations as $relation) {
                 $model = $model->{$relation};
             }
             $value = $model->{$attrName};
             //strip current project path from all children
             if ($this->project && $attrName == 'path') {
                 $value = substr($value, strlen(dirname($this->project->path)) + 1);
             }
             $record[] = $value;
         }
         $csvFile->putRecord($record);
     }
     if ($return) {
         return $csvFile->getContents();
     } else {
         \GO\Base\Util\Http::outputDownloadHeaders($csvFile, false);
         $csvFile->output();
     }
 }
Beispiel #18
0
 protected function actionHandleAttachedVCard($params)
 {
     $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
     $imap = $account->openImapConnection($params['mailbox']);
     $tmpFile = \GO\Base\Fs\File::tempFile($params['filename']);
     $imap->save_to_file($params['uid'], $tmpFile->path(), $params['number'], $params['encoding']);
     if (!isset($params['importVCard'])) {
         \GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
         echo $tmpFile->getContents();
         return;
     }
     $options = \Sabre\VObject\Reader::OPTION_FORGIVING + \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES;
     $card = \Sabre\VObject\Reader::read($tmpFile->getContents(), $options);
     $contact = new \GO\Addressbook\Model\Contact();
     $contact->importVObject($card, array(), false);
     //format utf-8 attributes
     foreach ($contact->getAttributes('raw') as $key => $value) {
         try {
             $contact->{$key} = utf8_decode($value);
         } catch (\Exception $e) {
         }
     }
     //GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
     return array('success' => true, 'contacts' => array($contact->getAttributes()));
     //echo $tmpFile->getContents();
 }
Beispiel #19
0
 protected function actionDownload($params)
 {
     $template = \GO\Files\Model\Template::model()->findByPk($params['id']);
     \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\Fs\File($template->name . '.' . $template->extension));
     echo $template->content;
 }
Beispiel #20
0
 protected function actionDownload($params)
 {
     \GO::session()->closeWriting();
     \GO::setMaxExecutionTime(0);
     if (isset($params['path'])) {
         $folder = \GO\Files\Model\Folder::model()->findByPath(dirname($params['path']));
         $file = $folder->hasFile(\GO\Base\Fs\File::utf8Basename($params['path']));
     } else {
         $file = \GO\Files\Model\File::model()->findByPk($params['id'], false, true);
     }
     if (!$file) {
         throw new \GO\Base\Exception\NotFound();
     }
     if (!empty($params['random_code'])) {
         if ($file->random_code != $params['random_code']) {
             throw new \GO\Base\Exception\NotFound();
         }
         if (time() > $file->expire_time) {
             throw new \Exception(\GO::t('downloadLinkExpired', 'files'));
         }
     } else {
         $public = substr($file->path, 0, 6) == 'public';
         if (!$public) {
             if (!\GO::user()) {
                 \GO\Base\Util\Http::basicAuth();
             }
             if (!$file->checkPermissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)) {
                 throw new \GO\Base\Exception\AccessDenied();
             }
         }
     }
     // Show the file inside the browser or give it as a download
     $inline = true;
     // Defaults to show inside the browser
     if (isset($params['inline']) && $params['inline'] == "false") {
         $inline = false;
     }
     \GO\Base\Util\Http::outputDownloadHeaders($file->fsFile, $inline, !empty($params['cache']));
     $file->open();
     $this->fireEvent('beforedownload', array(&$this, &$params, &$file));
     $file->fsFile->output();
 }
Beispiel #21
0
 public function actionExportIcs($params)
 {
     $calendar = \GO\Calendar\Model\Calendar::model()->findByPk($params["calendar_id"], false, true);
     if (!$calendar->public && !$calendar->checkPermissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)) {
         throw new \GO\Base\Exception\AccessDenied();
     }
     //		$c = new \GO\Base\VObject\VCalendar();
     //		$c->add(new \GO\Base\VObject\VTimezone());
     $months_in_past = isset($params['months_in_past']) ? intval($params['months_in_past']) : 0;
     $findParams = \GO\Base\Db\FindParams::newInstance()->select("t.*")->order('start_time', 'ASC');
     $findParams->getCriteria()->addCondition("calendar_id", $params["calendar_id"]);
     if (!empty($params['months_in_past'])) {
         $stmt = Event::model()->findForPeriod($findParams, \GO\Base\Util\Date::date_add(time(), 0, -$months_in_past));
     } else {
         $stmt = Event::model()->find($findParams);
     }
     \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\FS\File($calendar->name . '.ics'));
     echo "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Intermesh//NONSGML " . \GO::config()->product_name . " " . \GO::config()->version . "//EN\r\n";
     $t = new \GO\Base\VObject\VTimezone();
     echo $t->serialize();
     while ($event = $stmt->fetch()) {
         $v = $event->toVObject();
         echo $v->serialize();
     }
     echo "END:VCALENDAR\r\n";
 }