Ejemplo n.º 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');
     }
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 3
0
 /**
  * Create a new Cronjob model
  */
 protected function actionCreate()
 {
     $model = new \GO\Base\Cron\CronJob();
     if (\GO\Base\Util\Http::isPostRequest()) {
         $model->setAttributes($_POST);
         $model->save();
         echo $this->renderSubmit($model);
     } else {
         echo $this->renderForm($model, array(), array('select' => false));
     }
 }
Ejemplo n.º 4
0
 protected function actionGetURL($path)
 {
     if (substr($path, 0, 1) == '/') {
         $path = substr($path, 1);
     }
     if (substr($path, -1, 1) == '/') {
         $path = substr($path, 0, -1);
     }
     $folderModel = \GO\Files\Model\Folder::model()->findByPath($path, true);
     return array('success' => true, 'url' => \GO\Base\Util\Http::addParamsToUrl($folderModel->getExternalURL(), array('GOSID' => session_id(), 'security_token' => \GO::session()->values['security_token'])));
 }
Ejemplo n.º 5
0
 /**
  * Update a new menu item
  * 
  * @param int $id
  * @param int $site_id
  */
 public function actionUpdate($id, $site_id)
 {
     $remoteComboFields = array();
     $model = $this->_loadModel($site_id, $id);
     if (!empty($model->content_id)) {
         $remoteComboFields['content_id'] = $model->content->title;
     }
     if (\GO\Base\Util\Http::isPostRequest()) {
         $model->setAttributes($_POST);
         $model->save();
     }
     echo $this->renderForm($model, $remoteComboFields);
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 8
0
 /**
  * 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());
     }
 }
Ejemplo n.º 9
0
 /**
  * Render the headers of the generated response
  * If headers are not set already. Set them to application/json
  */
 protected function setHeaders()
 {
     if (headers_sent()) {
         return;
     }
     header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
     //prevent caching
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     //resolves problem with IE GET requests
     // Iframe hack, weird Content-Type crap is happening here
     if (\GO\Base\Util\Http::isMultipartRequest()) {
         header('Content-Type: text/html; charset=UTF-8');
     } else {
         header('Content-type: application/json; charset=UTF-8');
         //tell the browser we are returning json
     }
 }
Ejemplo n.º 10
0
    public function actionData($params)
    {
        $response = array('success' => true, 'data' => array());
        try {
            $customCssFolder = new Folder(GO::config()->file_storage_path . 'customcss');
            if (!$customCssFolder->exists()) {
                $customCssFolder->create(0755);
            }
            $cssFile = new File(GO::config()->file_storage_path . 'customcss/style.css');
            $jsFile = new File(GO::config()->file_storage_path . 'customcss/javascript.js');
            if (Http::isPostRequest()) {
                if (isset($_POST['css'])) {
                    $cssFile->putContents($_POST['css']);
                }
                if (isset($_POST['javascript'])) {
                    $jsFile->putContents($_POST['javascript']);
                }
            }
            if ($cssFile->exists()) {
                $response['data']['css'] = $cssFile->getContents();
            } else {
                $response['data']['css'] = '/*
* Put custom styles here that will be applied to Group-Office. You can use the select file button to upload your logo and insert the URL in to this stylesheet.
*/

/* this will override the logo at the top right */
#headerLeft{
background-image:url(/insert/url/here) !important;
}

/* this will override the logo at the login screen */
.go-app-logo {
background-image:url(/insert/url/here) !important;
}';
            }
            if ($jsFile->exists()) {
                $response['data']['javascript'] = $jsFile->getContents();
            }
        } catch (Exception $e) {
            $response['feedback'] = $e->getMessage();
            $response['success'] = false;
        }
        echo $this->renderJson($response);
    }
Ejemplo n.º 11
0
 public function __construct()
 {
     if (!empty($_REQUEST['startdate'])) {
         $this->startDate = \GO\Base\Util\Date::to_unixtime($_REQUEST['startdate']);
     }
     if (!empty($_REQUEST['enddate'])) {
         $this->endDate = \GO\Base\Util\Date::date_add(\GO\Base\Util\Date::to_unixtime($_REQUEST['enddate']), 1);
     }
     if ($this->supportsStatusFilter()) {
         if (\GO\Base\Util\Http::isPostRequest()) {
             $this->statuses = !empty($_POST['status_id']) ? $_POST['status_id'] : array();
             \GO::config()->save_setting(get_class($this), json_encode($this->statuses), \GO::user()->id);
         } else {
             $statuses = \GO::config()->get_setting(get_class($this), \GO::user()->id);
             if ($statuses) {
                 $this->statuses = json_decode($statuses);
             }
         }
     }
 }
Ejemplo n.º 12
0
    protected function actionDownloadWin7($params)
    {
        $url = \GO::url('email/message/mailto', array('mailto' => '-mailto-'), false, false, false);
        //this is necessary because we don't want %1 to be urlencoded.
        $url = str_replace('-mailto-', '%1', $url);
        $data = 'Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\\mailto]
@="URL:MailTo Protocol"
"EditFlags"=hex:02,00,00,00
"URL Protocol"=""

[HKEY_CLASSES_ROOT\\mailto\\DefaultIcon]
@=""

[HKEY_CLASSES_ROOT\\mailto\\shell]

[HKEY_CLASSES_ROOT\\mailto\\shell\\open]

[HKEY_CLASSES_ROOT\\mailto\\shell\\open\\command]
@="rundll32.exe url.dll,FileProtocolHandler ' . $url . '\\"

[HKEY_CLASSES_ROOT\\Group-Office.Url.mailto]
@="MailTo Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\\Group-Office.Url.mailto\\DefaultIcon]
@=""
[HKEY_CLASSES_ROOT\\Group-Office.Url.mailto\\shell]
[HKEY_CLASSES_ROOT\\Group-Office.Url.mailto\\shell\\open]
"FriendlyAppName"="Group-Office"
[HKEY_CLASSES_ROOT\\Group-Office.Url.mailto\\shell\\open\\command]
@="rundll32.exe url.dll,FileProtocolHandler ' . $url . '"
[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto]
[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice]
"Progid"="Group-Office.Url.mailto"
';
        \GO\Base\Util\Http::downloadFile(new \GO\Base\Fs\MemoryFile('Group-Office_email.reg', $data));
    }
Ejemplo n.º 13
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');
     }
 }
Ejemplo n.º 14
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');
     }
 }
Ejemplo n.º 15
0
 protected function actionProfile()
 {
     $user = \GO::user();
     $contact = $user->contact;
     //set additional required fields
     $contact->setValidationRule('address', 'required', true);
     $contact->setValidationRule('zip', 'required', true);
     $contact->setValidationRule('city', 'required', true);
     //		$user->setValidationRule('passwordConfirm', 'required', false);
     $user->setValidationRule('password', 'required', false);
     \GO::config()->password_validate = false;
     if ($contact->company) {
         $company = $contact->company;
     } else {
         $company = new \GO\Addressbook\Model\Company();
         $company->addressbook_id = $contact->addressbook_id;
     }
     if (\GO\Base\Util\Http::isPostRequest()) {
         if (!empty($_POST['currentPassword']) && !empty($_POST['User']['password'])) {
             if (!$user->checkPassword($_POST['currentPassword'])) {
                 GOS::site()->notifier->setMessage('error', "Huidig wachtwoord onjuist");
                 unset($_POST['User']['password']);
                 unset($_POST['User']['passwordConfirm']);
             }
         } else {
             unset($_POST['User']['password']);
             unset($_POST['User']['passwordConfirm']);
         }
         $user->setAttributes($_POST['User']);
         $contact->setAttributes($_POST['Contact']);
         $company->setAttributes($_POST['Company']);
         $company->checkVatNumber = true;
         if (!empty($_POST['Company']['postAddressIsEqual'])) {
             $company->setPostAddressFromVisitAddress();
         }
         if (!GOS::site()->notifier->hasMessage('error') && $user->validate() && $contact->validate() && $company->validate()) {
             \GO::setIgnoreAclPermissions();
             //allow guest to create user
             $user->save();
             $company->save();
             $contact->company_id = $company->id;
             $contact->save();
             GOS::site()->notifier->setMessage('success', GOS::t('formEditSuccess'));
         } else {
             GOS::site()->notifier->setMessage('error', "Please check the form for errors");
         }
     }
     $company->post_address_is_address = false;
     if ($company->address == $company->post_address && $company->address_no == $company->post_address_no && $company->city == $company->post_city) {
         $company->post_address_is_address = true;
     }
     //clear values for form
     $user->password = "";
     $user->passwordConfirm = "";
     echo $this->render('profile', array('user' => $user, 'contact' => $contact, 'company' => $company));
 }
Ejemplo n.º 16
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();
 }
Ejemplo n.º 17
0
 private function _sendHeaders()
 {
     $file = new \GO\Base\Fs\File($this->title . '.csv');
     \GO\Base\Util\Http::outputDownloadHeaders($file);
 }
Ejemplo n.º 18
0
 /**
  * Checks if a user is logged in, if the user has permission to the module and if the user has access to a specific action.
  * 
  * @param string $action
  * @return boolean boolean
  */
 protected function _checkPermission($action)
 {
     $allowGuests = $this->allowGuests();
     if (!in_array($action, $allowGuests) && !in_array('*', $allowGuests)) {
         //check for logged in user
         if (!GO::user()) {
             \GO\Base\Util\Http::basicAuth();
             return false;
         }
         $this->checkSecurityToken();
         //check module permission
         $allowWithoutModuleAccess = $this->allowWithoutModuleAccess();
         if (!in_array($action, $allowWithoutModuleAccess) && !in_array('*', $allowWithoutModuleAccess)) {
             $module = $this->getModule();
             if ($module && !$module->permissionLevel) {
                 return false;
             }
         }
     }
     return $this->_checkRequiredPermissionLevels($action);
 }
Ejemplo n.º 19
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!";
     }
 }
Ejemplo n.º 20
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();
 }
Ejemplo n.º 21
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();
 }
Ejemplo n.º 22
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();
 }
Ejemplo n.º 23
0
 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();
 }
Ejemplo n.º 24
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;
 }
Ejemplo n.º 25
0
 /**
  * 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();
 }
Ejemplo n.º 26
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();
     }
 }
Ejemplo n.º 27
0
 protected function beforeSave()
 {
     if (!empty($this->homepage)) {
         $this->homepage = \GO\Base\Util\Http::checkUrlForHttp($this->homepage);
     }
     if (empty($this->color)) {
         $this->color = "000000";
     }
     return parent::beforeSave();
 }
Ejemplo n.º 28
0
 /**
  * Render the JSON outbut for a submit action to be used by ExtJS Form submit
  * @param \GO\Base\Db\ActiveRecord $$data['model']
  * @return \GO\Base\Data\JsonResponse Response object
  */
 public function renderSubmit($data)
 {
     $response = array('feedback' => '', 'success' => true, 'validationErrors' => array(), 'data' => array());
     //Init data array
     foreach ($data as $modelName => $model) {
         if (is_array($model)) {
             $response['data'][$modelName] = $model;
         } else {
             $response['data'][$modelName] = $model->getAttributes();
         }
         // $modelName cannot be the same as the reserved results
         if ($modelName == 'feedback' || $modelName == 'success' || $modelName == 'validationErrors') {
             throw new \Exception('Cannot use "' . $modelName . '" as key for your data. Please change the key.');
         }
         if (is_a($model, "\\GO\\Base\\Model")) {
             //$ret = $this->beforeSubmit($response, $model, $params);
             //$modifiedAttributes = $model->getModifiedAttributes();
             if (!$model->hasValidationErrors() && !$model->isNew) {
                 //model was saved
                 $response['id'] = $model->pk;
                 //If the model has it's own ACL id then we return the newly created ACL id.
                 //The model automatically creates it.
                 if ($model->aclField() && !$model->isJoinedAclField) {
                     $response[$model->aclField()] = $model->{$model->aclField()};
                 }
                 //TODO: move the link saving to the model someday
                 if (!empty(\GO::request()->post['link']) && $model->hasLinks()) {
                     //a link is sent like  \GO\Notes\Model\Note:1
                     //where 1 is the id of the model
                     $linkProps = explode(':', \GO::request()->post['link']);
                     $linkModel = \GO::getModel($linkProps[0])->findByPk($linkProps[1]);
                     $model->link($linkModel);
                 }
             } else {
                 // model was not saved
                 $response['success'] = false;
                 //can't use <br /> tags in response because this goes wrong with the extjs fileupload hack with an iframe.
                 $response['feedback'] = sprintf(\GO::t('validationErrorsFound'), strtolower($model->localizedName)) . "\n\n" . implode("\n", $model->getValidationErrors()) . "\n";
                 if (\GO\Base\Util\Http::isAjaxRequest(false)) {
                     $response['feedback'] = nl2br($response['feedback']);
                 }
                 $response['errors'] = array(sprintf(\GO::t('validationErrorsFound'), strtolower($model->localizedName)) . "\n\n" . implode("\n", $model->getValidationErrors()) . "\n");
                 $response['validationErrors'][$modelName] = $model->getValidationErrors();
             }
         } else {
             $response[$modelName] = $model;
         }
     }
     return new \GO\Base\Data\JsonResponse($response);
 }
Ejemplo n.º 29
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();
 }
Ejemplo n.º 30
0
 /**
  * Render the JSON outbut for a submit action to be used by ExtJS Form submit
  * @param \GO\Base\Db\ActiveRecord $model
  * @return \GO\Base\Data\JsonResponse Response object
  */
 public function renderSubmit($model)
 {
     $response = array('feedback' => '', 'success' => true);
     //$ret = $this->beforeSubmit($response, $model, $params);
     //$modifiedAttributes = $model->getModifiedAttributes();
     if (!$model->hasValidationErrors() && !$model->isNew) {
         //model was saved
         $response['id'] = $model->pk;
         //If the model has it's own ACL id then we return the newly created ACL id.
         //The model automatically creates it.
         if ($model->aclField() && !$model->isJoinedAclField) {
             $response[$model->aclField()] = $model->{$model->aclField()};
         }
         if ($model->aclOverwrite()) {
             $response[$model->aclOverwrite()] = $model->{$model->aclOverwrite()};
         }
         //TODO: move the link saving to the model someday
         if (!empty($_POST['link']) && $model->hasLinks()) {
             //a link is sent like  \GO\Notes\Model\Note:1
             //where 1 is the id of the model
             $linkProps = explode(':', $_POST['link']);
             $linkModel = \GO::getModel($linkProps[0])->findByPk($linkProps[1]);
             $model->link($linkModel);
         }
     } else {
         // model was not saved
         $response['success'] = false;
         //can't use <br /> tags in response because this goes wrong with the extjs fileupload hack with an iframe.
         $response['feedback'] = sprintf(\GO::t('validationErrorsFound'), strtolower($model->localizedName)) . "\n\n" . implode("\n", $model->getValidationErrors()) . "\n";
         if (\GO\Base\Util\Http::isAjaxRequest(false)) {
             $response['feedback'] = nl2br($response['feedback']);
         }
         $response['validationErrors'] = $model->getValidationErrors();
     }
     $this->fireEvent('submit', array(&$this, &$response, &$model));
     return new \GO\Base\Data\JsonResponse($response);
 }