/** * The code that needs to be called when the cron is running * * @param GO\Base\Cron\CronJob $cronJob * @param GO\Base\Model\User $user */ public function run(GO\Base\Cron\CronJob $cronJob, GO\Base\Model\User $user = null) { $filesStmt = File::model()->find(FindParams::newInstance()->ignoreAcl()->criteria(FindCriteria::newInstance()->addCondition('expire_time', time(), '<')->addCondition('expire_time', '0', '>')->addCondition('random_code', '', '!=')->addCondition('delete_when_expired', '1'))); foreach ($filesStmt as $fileModel) { $fileModel->delete(); } }
public function formatRawOutput($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model) { $column = $model->getColumn($key); if (!$column) { return null; } $fieldId = $column['customfield']->id; $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->order('mf.order')->joinModel(array('model' => 'GO\\Site\\Model\\MultifileFile', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'file_id', 'tableAlias' => 'mf'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('model_id', $model->model_id, '=', 'mf')->addCondition('field_id', $fieldId, '=', 'mf')); return \GO\Files\Model\File::model()->find($findParams, 'false', true); }
public function formatDisplay($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model) { $html = ""; if (!empty($attributes[$key])) { $file = \GO\Files\Model\File::model()->findByPath($attributes[$key]); if ($file) { if (!\GO\Customfields\Model\AbstractCustomFieldsRecord::$formatForExport) { $html = '<a href="#" onclick="GO.linkHandlers[\'GO\\Files\\Model\\File\'].call(this,\'' . $attributes[$key] . '\');">' . basename($attributes[$key]) . '</a>' . '<a href="#" onclick=\'' . $file->getDefaultHandler()->getHandler($file) . '\' style="display:block;float: right;" class="go-icon btn-edit"> </a>'; //$html='<a href="#" title="'.$attributes[$key].'">'.$attributes[$key].'</a>'; } else { $html = $attributes[$key]; } } } return $html; }
protected function actionCreateFile($params) { $filename = \GO\Base\Fs\File::stripInvalidChars($params['filename']); if (empty($filename)) { throw new \Exception("Filename can not be empty"); } $template = \GO\Files\Model\Template::model()->findByPk($params['template_id']); $folder = \GO\Files\Model\Folder::model()->findByPk($params['folder_id']); $path = \GO::config()->file_storage_path . $folder->path . '/' . $filename; if (!empty($template->extension)) { $path .= '.' . $template->extension; } $fsFile = new \GO\Base\Fs\File($path); $fsFile->putContents($template->content); $fileModel = \GO\Files\Model\File::importFromFilesystem($fsFile); if (!$fileModel) { throw new Exception("Could not create file"); } return array('id' => $fileModel->id, 'success' => true); }
/** * Creates a new file in the directory * * data is a readable stream resource * * @param string $name Name of the file * @param resource $data Initial payload * @return void */ public function createFile($name, $data = null) { \GO::debug("FSD::createFile({$name})"); $folder = $this->_getFolder(); if (!$folder->checkPermissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION)) { throw new Sabre\DAV\Exception\Forbidden(); } $newFile = new \GO\Base\Fs\File($this->path . '/' . $name); if ($newFile->exists()) { throw new \Exception("File already exists!"); } $tmpFile = \GO\Base\Fs\File::tempFile(); $tmpFile->putContents($data); if (!\GO\Files\Model\File::checkQuota($tmpFile->size())) { $tmpFile->delete(); throw new Sabre\DAV\Exception\InsufficientStorage(); } // $newFile->putContents($data); $tmpFile->move($folder->fsFolder, $name); $folder->addFile($name); }
public function actionRecent($params) { $start = !empty($params['start']) ? $params['start'] : 0; $limit = !empty($params['limit']) ? $params['limit'] : 20; $store = \GO\Base\Data\Store::newInstance(\GO\Files\Model\File::model()); $store->getColumnModel()->formatColumn('path', '$model->path', array(), array('first_name', 'last_name')); $store->getColumnModel()->formatColumn('weekday', '$fullDays[date("w", $model->mtime)]." ".\\GO\\Base\\Util\\Date::get_timestamp($model->mtime, false);', array('fullDays' => \GO::t('full_days')), array('first_name', 'last_name')); $store->setStatement(\GO\Files\Model\File::model()->findRecent($start, $limit)); $response = $store->getData(); $store->setStatement(\GO\Files\Model\File::model()->findRecent()); $response['total'] = $store->getTotal(); return $response; }
/** * Download an attachment from the current ticket/message * The file will be outputted to the broser with downloadheaders * * @throws \GO\Base\Exception\AccessDenied */ protected function actionDownloadAttachment() { // Find the cuttent ticket $ticket = \GO\Tickets\Model\Ticket::model()->findSingleByAttributes(array('ticket_number' => $_GET['ticket_number'], 'ticket_verifier' => $_GET['ticket_verifier'])); // Throw an AccessDenied exception when the ticket is not found if (!$ticket) { throw new \GO\Base\Exception\AccessDenied(); } // Get the file from the GET['file'] parameter. $file = \GO\Files\Model\File::model()->findSingleByAttributes(array('id' => $_GET['file'], 'folder_id' => $ticket->files_folder_id)); // If the file is found then output it to the browser if ($file) { $fsFile = $file->fsFile; \GO\Base\Util\Http::outputDownloadHeaders($fsFile, false); $fsFile->output(); } }
public static function checkFolderTrigger(&$self, &$response, &$model, &$params, $modifiedAttributes) { $trigger = Model\Trigger::model()->findSingleByAttributes(array('model_type_id' => \GO\Files\Model\File::model()->modelTypeId(), 'model_attribute' => 'folder_id', 'model_attribute_value' => $model->id)); if (!empty($params['wf_process_id'])) { if (!$trigger) { \GO::debug('NO EXISTING TRIGGER FOUND, CREATE NEW TRIGGER'); $trigger = new Model\Trigger(); $trigger->model_type_id = \GO\Files\Model\File::model()->modelTypeId(); $trigger->model_attribute = 'folder_id'; $trigger->model_attribute_value = $model->id; } $trigger->process_id = $params['wf_process_id']; $trigger->save(); } elseif ($trigger) { $trigger->delete(); } }
public function getHandler(\GO\Files\Model\File $file) { return 'window.open("' . $file->getDownloadUrl(false, true) . '");'; }
protected function actionSave($id) { // throw new \GO\Base\Exception\AccessDenied(); $file = \GO\Files\Model\File::model()->findByPk($id); if (!$file) { throw new \GO\Base\Exception\NotFound(); } if (empty($_FILES)) { throw new Exception("Server did not recieve a file. Perhaps the file was too large?"); } $upfile = array_shift($_FILES); if (empty($upfile['tmp_name'])) { throw new Exception("Server did not recieve a file. Perhaps the file was too large?"); } $file->replace(new \GO\Base\Fs\File($upfile['tmp_name']), false); //GOTA java program will check for the following string. Anything else will //be treated as an error. // echo 'SUCCESS'; $response['success'] = true; return $response; }
/** * Delete the current file * * @return void */ public function delete() { $this->checkWritePermission(true); $file = \GO\Files\Model\File::model()->findByPath($this->relpath); $file->delete(); }
protected function actionRemoveDuplicates($params) { if (!\GO::modules()->tools) { throw new \GO\Base\Exception\AccessDenied(); } \GO::session()->runAsRoot(); \GO\Base\Fs\File::setAllowDeletes(false); //VERY IMPORTANT: \GO\Files\Model\Folder::$deleteInDatabaseOnly = true; \GO\Files\Model\File::$deleteInDatabaseOnly = true; $this->lockAction(); \GO::session()->closeWriting(); //close writing otherwise concurrent requests are blocked. $checkModels = array("GO\\Calendar\\Model\\Event" => array('name', 'start_time', 'end_time', 'calendar_id', 'rrule'), "GO\\Tasks\\Model\\Task" => array('name', 'start_time', 'due_time', 'tasklist_id', 'rrule', 'user_id'), "GO\\Addressbook\\Model\\Contact" => array('first_name', 'middle_name', 'last_name', 'addressbook_id', 'company_id', 'email'), "GO\\Files\\Model\\Folder" => array('name', 'parent_id')); echo '<p style="color:red;"><font style="font-size:18px;" >Warning: This script only checks for duplicate items on the displayed columns!</font></p>'; foreach ($checkModels as $modelName => $checkFields) { if (empty($params['model']) || $modelName == $params['model']) { echo '<h1>' . $modelName . '</h1>'; $checkFieldsStr = 't.' . implode(', t.', $checkFields); $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select('t.id, count(*) AS n, ' . $checkFieldsStr)->group($checkFields)->having('n>1'); $stmt1 = \GO::getModel($modelName)->find($findParams); echo '<table border="1">'; echo '<tr><td>ID</th><th>' . implode('</th><th>', $checkFields) . '</th></tr>'; $count = 0; while ($dupModel = $stmt1->fetch()) { $select = 't.id'; if (\GO::getModel($modelName)->hasFiles()) { $select .= ', t.files_folder_id'; } $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select($select . ', ' . $checkFieldsStr)->order('id', 'ASC'); $criteria = $findParams->getCriteria(); foreach ($checkFields as $field) { $criteria->addCondition($field, $dupModel->getAttribute($field)); } $stmt = \GO::getModel($modelName)->find($findParams); $first = true; while ($model = $stmt->fetch()) { echo '<tr><td>'; if (!$first) { echo '<span style="color:red">'; } echo $model->id; if (!$first) { echo '</span>'; } echo '</th>'; foreach ($checkFields as $field) { echo '<td>' . $model->getAttribute($field, 'html') . '</td>'; } echo '</tr>'; if (!$first) { if (!empty($params['delete'])) { if ($model->hasLinks() && $model->countLinks()) { echo '<tr><td colspan="99">Skipped delete because model has links</td></tr>'; } elseif (($filesFolder = $model->getFilesFolder(false)) && ($filesFolder->hasFileChildren() || $filesFolder->hasFolderChildren())) { echo '<tr><td colspan="99">Skipped delete because model has folder or files</td></tr>'; } else { $model->delete(true); } } $count++; } $first = false; } } echo '</table>'; echo '<p>Found ' . $count . ' duplicates</p>'; echo '<br /><br /><a href="' . \GO::url('maintenance/removeDuplicates', array('delete' => true, 'model' => $modelName)) . '">Click here to delete the newest duplicates marked in red for model ' . $modelName . '.</a>'; } } if (empty($params['model'])) { echo '<br /><br /><a href="' . \GO::url('maintenance/removeDuplicates', array('delete' => true)) . '">Click here to delete the newest duplicates marked in red.</a>'; } else { echo '<br /><br /><a href="' . \GO::url('maintenance/removeDuplicates') . '">Show all models.</a>'; } }
protected function actionEditinglist() { $empty_editing = true; if ($list = \GO::session()->values['googledrive']['editing']) { if (!count(\GO::session()->values['googledrive']['editing']) < 1) { $empty_editing = false; } } if (!$empty_editing) { $list = \GO::session()->values['googledrive']['editing']; $response['success'] = true; $response['values'] = []; $response['names'] = []; foreach ($list as $k => $v) { $goFile = \GO\Files\Model\File::model()->findByPk($k); array_push($response['values'], $k); array_push($response['names'], $goFile->name); } } else { throw new Exception("No hay archivos abiertos"); $response['success'] = false; } return $response; }
public function getHandler(\GO\Files\Model\File $file) { return 'window.location.href="' . $file->getDownloadUrl(true, true) . '";'; }
/** * Check if this folder has files. * * @return boolean */ public function hasFileChildren() { $file = File::model()->findSingleByAttribute('folder_id', $this->id); return $file != false; }
public static function initListeners() { \GO\Files\Model\File::model()->addListener('save', 'GO\\Filesearch\\FilesearchModule', 'save'); \GO\Files\Model\File::model()->addListener('delete', 'GO\\Filesearch\\FilesearchModule', 'delete'); }
public function start(\GO\Base\Model\User $user = null, $reset = false) { if ($user === null) { $user = GO::user(); } GO::session()->runAsRoot(); GO::setMaxExecutionTime(0); self::log("Dropbox sync for user " . $user->username); $dbxUser = User::model()->findByPk($user->id); if ($reset) { $dbxUser->delta_cursor = ""; $folder = self::getHomeFolder($user); $folder->removeChildren(); } $dbxClient = self::getClient($user); self::log("Getting Dropbox Changes"); $hasMore = true; while ($hasMore) { $delta = $dbxClient->Delta(empty($dbxUser->delta_cursor) ? null : $dbxUser->delta_cursor); // var_dump($delta); // exit(); if (!isset($delta)) { throw new \Exception("Could not get delta from Dropbox!"); } $hasMore = $delta->has_more; foreach ($delta->entries as $entry) { flush(); //$entry[1]['path'] = with case. Otherwise we just have a string to lowered path for deleting $dbxPath = isset($entry[1]->path) ? $entry[1]->path : $entry[0]; $goPath = self::dbxToGoPath($dbxPath, $user); if (!isset($entry[1])) { //should be deleted $file = File::model()->findByPath($goPath, false); if ($file) { self::log("Deleting file on Group-Office " . $goPath); $file->delete(); } else { $folder = Folder::model()->findByPath($goPath, false, array(), false); if ($folder) { self::log("Deleting folder on Group-Office " . $goPath); $folder->delete(); } else { self::log("Could not find path for delete file on Group-Office " . $goPath); } } } else { if ($entry[1]->is_dir) { self::log("Create folder on Group-Office " . $entry[1]->path . " -> " . $goPath); $folder = Folder::model()->findByPath($goPath, true); } else { self::log("Download from Dropbox " . $entry[1]->path . " -> " . $goPath); $folder = Folder::model()->findByPath(dirname($goPath), true, array(), false); $name = \GO\Base\Fs\File::utf8Basename($goPath); $path = $folder->fsFolder->createChild($name)->path(); //$f = fopen($path, "w+b"); $fileMetadata = $dbxClient->DownloadFile($entry[0], $path); //fclose($f); touch($path, strtotime($fileMetadata->modified)); //todo needs optimize $folder->syncFilesystem(); } } } } $dbxUser->delta_cursor = $delta->cursor; $dbxUser->save(); self::log("Applying Group-Office changes to Dropbox"); $folder = self::getHomeFolder($user); $goSnapshot = self::getGroupOfficeSnapShot($folder); $dbxSnapshot = self::getDropboxSnapshot($user); foreach ($goSnapshot as $path => $props) { $dbxPath = self::goToDbxPath($props['path'], $user); $dbxPathToLower = strtolower($dbxPath); if (!isset($dbxSnapshot[$dbxPathToLower]) || $dbxSnapshot[$dbxPathToLower]['mtime'] < $props['mtime']) { if (is_file(GO::config()->file_storage_path . $props['path'])) { self::log("Upload to Dropbox " . $path . " -> " . $dbxPath); $localPath = GO::config()->file_storage_path . $props['path']; $meta = $dbxClient->UploadFile($localPath, $dbxPath, true); if (!isset($meta)) { throw new \Exception("Failed to create file '" . $dbxPath . "' on Dropbox"); } } elseif (!isset($dbxSnapshot[$dbxPathToLower])) { self::log("Create folder on Dropbox " . $path . " -> " . $dbxPath); $folderMetaData = $dbxClient->CreateFolder($dbxPath); if (!isset($folderMetaData)) { throw new \Exception("Failed to create folder '" . $dbxPath . "' on Dropbox"); } } } } //reverse sort for deleting so that deeper files are deleted first. krsort($dbxSnapshot); foreach ($dbxSnapshot as $path => $props) { $goPath = strtolower(self::dbxToGoPath($path, $user)); if (!isset($goSnapshot[$goPath])) { self::log("Deleting on dropbox " . $path); if (!$dbxClient->Delete($path)) { throw new \Exception("Failed to delete '" . $path . "'"); } } } //get delta again so we won't process our own changes next sync $delta = $dbxClient->Delta($dbxUser->delta_cursor); $dbxUser->delta_cursor = $delta->cursor; $dbxUser->save(); self::log("Done!"); }
public function fileIsSupported(\GO\Files\Model\File $file) { return $file->isImage(); }
function process_form() { \GO::$ignoreAclPermissions = true; $this->check_required(); if (!isset($_POST['salutation'])) { $_POST['salutation'] = isset($_POST['sex']) ? \GO::t('default_salutation_' . $_POST['sex']) : \GO::t('default_salutation_unknown'); } //user registation // if(!empty($_POST['username'])){ // $credentials = array ('username','first_name','middle_name','last_name','title','initials','sex','email', // 'home_phone','fax','cellular','address','address_no', // 'zip','city','state','country','company','department','function','work_phone', // 'work_fax'); // // if($_POST['password1'] != $_POST['password2']) // { // throw new Exception(\GO::t('error_match_pass','users')); // } // // foreach($credentials as $key) // { // if(!empty($_REQUEST[$key])) // { // $userCredentials[$key] = $_REQUEST[$key]; // } // } // $userCredentials['password']=$_POST['password1']; // // $userModel = new \GO\Base\Model\User(); // $userModel->setAttributes($userCredentials); // $userModel->save(); // foreach($this->user_groups as $groupId) { // $currentGroupModel = \GO\Base\Model\Group::model()->findByPk($groupId); // if($groupId>0 && $groupId!=\GO::config()->group_everyone && !$currentGroupModel->hasUser($userModel->id)) { // $currentGroupModel->addUser($userModel->id); // } // } // foreach($this->visible_user_groups as $groupId) { // $userAclModel = \GO\Base\Model\Acl::model()->findByPk($userModel->acl_id); // if($groupId>0 && !empty($userAclModel) && $userAclModel->hasGroup($groupId)) { // $userAclModel->addGroup($groupId); // } // } // // \GO::session()->login($userCredentials['username'], $userCredentials['password']); // } if (!empty($_POST['email']) && !\GO\Base\Util\String::validate_email($_POST['email'])) { throw new Exception(\GO::t('invalidEmailError')); } if (!empty($_REQUEST['addressbook'])) { // require($GO_LANGUAGE->get_language_file('addressbook')); // require_once($GO_MODULES->modules['addressbook']['class_path'].'addressbook.class.inc.php'); // $ab = new addressbook(); // // $addressbook = $ab->get_addressbook_by_name($_REQUEST['addressbook']); $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findSingleByAttribute('name', $_REQUEST['addressbook']); if (!$addressbookModel) { throw new Exception('Addressbook not found!'); } $credentials = array('first_name', 'middle_name', 'last_name', 'title', 'initials', 'sex', 'email', 'email2', 'email3', 'home_phone', 'fax', 'cellular', 'comment', 'address', 'address_no', 'zip', 'city', 'state', 'country', 'company', 'department', 'function', 'work_phone', 'work_fax', 'salutation', 'url_linkedin', 'url_facebook', 'url_twitter', 'skype_name'); foreach ($credentials as $key) { if (!empty($_REQUEST[$key])) { $contactCredentials[$key] = $_REQUEST[$key]; } } if (isset($contactCredentials['comment']) && is_array($contactCredentials['comment'])) { $comments = ''; foreach ($contactCredentials['comment'] as $key => $value) { if ($value == 'date') { $value = date($_SESSION['GO_SESSION']['date_format'] . ' ' . $_SESSION['GO_SESSION']['time_format']); } if (!empty($value)) { $comments .= trim($key) . ":\n" . trim($value) . "\n\n"; } } $contactCredentials['comment'] = $comments; } if ($this->no_urls && isset($contactCredentials['comment']) && stripos($contactCredentials['comment'], 'http')) { throw new Exception('Sorry, but to prevent spamming we don\'t allow URL\'s in the message'); } $contactCredentials['addressbook_id'] = $addressbookModel->id; $contactCredentials['email_allowed'] = isset($_POST['email_allowed']) ? '1' : '0'; if (!empty($contactCredentials['company']) && empty($contactCredentials['company_id'])) { $companyModel = \GO\Addressbook\Model\Company::model()->findSingleByAttributes(array('name' => $contactCredentials['company'], 'addressbook_id' => $contactCredentials['addressbook_id'])); if (empty($companyModel)) { $companyModel = new \GO\Addressbook\Model\Company(); $companyModel->addressbook_id = $contactCredentials['addressbook_id']; $companyModel->name = $contactCredentials['company']; // bedrijfsnaam $companyModel->user_id = \GO::user()->id; $companyModel->save(); $contactCredentials['company_id'] = $companyModel->id; } } if (isset($_POST['birthday'])) { try { $contactCredentials['birthday'] = \GO\Base\Util\Date::to_db_date($_POST['birthday'], false); } catch (Exception $e) { throw new Exception(\GO::t('birthdayFormatMustBe') . ': ' . $_SESSION['GO_SESSION']['date_format'] . '.'); } if (!empty($_POST['birthday']) && $contactCredentials['birthday'] == '0000-00-00') { throw new Exception(\GO::t('invalidDateError')); } } unset($contactCredentials['company']); $existingContactModel = false; if (!empty($_POST['contact_id'])) { $existingContactModel = \GO\Addressbook\Model\Contact::model()->findByPk($_POST['contact_id']); } elseif (!empty($contactCredentials['email'])) { $existingContactModel = \GO\Addressbook\Model\Contact::model()->findSingleByAttributes(array('email' => $contactCredentials['email'], 'addressbook_id' => $contactCredentials['addressbook_id'])); } if ($existingContactModel) { $this->contact_id = $contactId = $existingContactModel->id; $filesFolderId = $existingContactModel->files_folder_id = $existingContactModel->getFilesFolder()->id; /* * Only update empty fields */ if (empty($_POST['contact_id'])) { foreach ($contactCredentials as $key => $value) { if ($key != 'comment') { if (!empty($existingContactModel->{$key})) { unset($contactCredentials[$key]); } } } } $contactCredentials['id'] = $contactId; if (!empty($existingContactModel->comment) && !empty($contactCredentials['comment'])) { $contactCredentials['comment'] = $existingContactModel->comment . "\n\n----\n\n" . $contactCredentials['comment']; } if (empty($contactCredentials['comment'])) { unset($contactCredentials['comment']); } $existingContactModel->setAttributes($contactCredentials); $existingContactModel->save(); } else { $newContactModel = new \GO\Addressbook\Model\Contact(); $newContactModel->setAttributes($contactCredentials); $newContactModel->save(); $this->contact_id = $contactId = $newContactModel->id; $filesFolderId = $newContactModel->files_folder_id = $newContactModel->getFilesFolder()->id; $newContactModel->save(); if (isset($_POST['contact_id']) && empty($userId) && \GO::user()->id > 0) { $userId = $this->user_id = \GO::user()->id; } if (!empty($userId)) { $userModel = \GO\Base\Model\User::model()->findByPk($userId); $userModel->contact_id = $contactId; $userModel->save(); } } if (!$contactId) { throw new Exception(\GO::t('saveError')); } if (\GO::modules()->isInstalled('files')) { $folderModel = \GO\Files\Model\Folder::model()->findByPk($filesFolderId); $path = $folderModel->path; $response['files_folder_id'] = $filesFolderId; $full_path = \GO::config()->file_storage_path . $path; foreach ($_FILES as $key => $file) { if ($key != 'photo') { //photo is handled later if (is_uploaded_file($file['tmp_name'])) { $fsFile = new \GO\Base\Fs\File($file['tmp_name']); $fsFile->move(new \GO\Base\Fs\Folder($full_path), $file['name'], false, true); $fsFile->setDefaultPermissions(); \GO\Files\Model\File::importFromFilesystem($fsFile); } } } } if (\GO::modules()->isInstalled('customfields')) { $cfFields = array(); foreach ($_POST as $k => $v) { if (strpos($k, 'col_') === 0) { $cfFields[$k] = $v; } } $contactCfModel = \GO\Addressbook\Customfields\Model\Contact::model()->findByPk($contactId); if (!$contactCfModel) { $contactCfModel = new \GO\Addressbook\Customfields\Model\Contact(); $contactCfModel->model_id = $contactId; } $contactCfModel->setAttributes($cfFields); $contactCfModel->save(); } if (isset($_POST['mailings'])) { foreach ($_POST['mailings'] as $mailingName) { if (!empty($mailingName)) { $addresslistModel = \GO\Addressbook\Model\Addresslist::model()->findSingleByAttribute('name', $mailingName); if (empty($addresslistModel)) { throw new Exception('Addresslist not found!'); } $addresslistModel->addManyMany('contacts', $contactId); } } } if ($this->contact_id > 0) { if (isset($_FILES['photo']['tmp_name']) && is_uploaded_file($_FILES['photo']['tmp_name'])) { $fsFile = new \GO\Base\Fs\File($_FILES['photo']['tmp_name']); $fsFile->move(new \GO\Base\Fs\Folder(\GO::config()->tmpdir), $_FILES['photo']['name'], false, false); $contactModel = \GO\Addressbook\Model\Contact::model()->findByPk($contactId); $contactModel->setPhoto(\GO::config()->tmpdir . $_FILES['photo']['name']); } } if (!isset($_POST['contact_id'])) { /** * Send notification of new contact to (1) users specified by 'notify_users' * in the form itself and to (2) the addressbook owner if so specified. */ // Send the email to the admin users in the language of the addressbook owner. $oldLanguage = \GO::language()->getLanguage(); \GO::language()->setLanguage($addressbookModel->user->language); $usersToNotify = isset($_POST['notify_users']) ? explode(',', $_POST['notify_users']) : array(); if (!empty($_POST['notify_addressbook_owner'])) { $usersToNotify[] = $addressbookModel->user_id; } $mailTo = array(); foreach ($usersToNotify as $userToNotifyId) { $userModel = \GO\Base\Model\User::model()->findByPk($userToNotifyId); $mailTo[] = $userModel->email; } if (count($mailTo)) { $viewContactUrl = \GO::createExternalUrl('addressbook', 'showContact', array($contactId)); $contactModel = \GO\Addressbook\Model\Contact::model()->findByPk($contactId); $companyModel = \GO\Addressbook\Model\Company::model()->findByPk($contactModel->company_id); if (!empty($companyModel)) { $companyName = $companyModel->name; } else { $companyName = ''; } $values = array('address_no', 'address', 'zip', 'city', 'state', 'country'); $formatted_address = nl2br(\GO\Base\Util\Common::formatAddress('{country}', '{address}', '{address_no}', '{zip}', '{city}', '{state}')); foreach ($values as $val) { $formatted_address = str_replace('{' . $val . '}', $contactModel->{$val}, $formatted_address); } $body = \GO::t('newContactFromSite', 'addressbook') . ':<br />'; $body .= \GO::t('name', 'addressbook') . ': ' . $contactModel->addressbook->name . '<br />'; $body .= "<br />" . $contactModel->name; $body .= "<br />" . $formatted_address; if (!empty($contactModel->home_phone)) { $body .= "<br />" . \GO::t('phone') . ': ' . $contactModel->home_phone; } if (!empty($contactModel->cellular)) { $body .= "<br />" . \GO::t('cellular') . ': ' . $contactModel->cellular; } if (!empty($companyName)) { $body .= "<br /><br />" . $companyName; } if (!empty($contactModel->work_phone)) { $body .= "<br />" . \GO::t('workphone') . ': ' . $contactModel->work_phone; } $body .= '<br /><a href="' . $viewContactUrl . '">' . \GO::t('clickHereToView', 'addressbook') . '</a>' . "<br />"; $mailFrom = !empty($_POST['mail_from']) ? $_POST['mail_from'] : \GO::config()->webmaster_email; $mailMessage = \GO\Base\Mail\Message::newInstance(\GO::t('newContactAdded', 'addressbook'), $body, 'text/html')->setFrom($mailFrom, \GO::config()->title); foreach ($mailTo as $v) { $mailMessage->addTo($v); } \GO\Base\Mail\Mailer::newGoInstance()->send($mailMessage); } // Restore the language \GO::language()->setLanguage($oldLanguage); } // // // Maybe make this workable with GO 4.0 later.... // // // if(isset($_POST['confirmation_template'])) // { // if(empty($_POST['email'])) // { // throw new Exception('Fatal error: No email given for confirmation e-mail!'); // } // // $url = create_direct_url('addressbook', 'showContact', array($contactId)); // $body = $lang['addressbook']['newContactFromSite'].'<br /><a href="'.$url.'">'.$lang['addressbook']['clickHereToView'].'</a>'; // // global $smarty; // $email = $smarty->fetch($_POST['confirmation_template']); // // $pos = strpos($email,"\n"); // // $subject = trim(substr($email, 0, $pos)); // $body = trim(substr($email,$pos)); // // require_once(\GO::config()->class_path.'mail/GoSwift.class.inc.php'); // $swift = new GoSwift($_POST['email'], $subject); // $swift->set_body($body); // $swift->set_from(\GO::config()->webmaster_email, \GO::config()->title); // $swift->sendmail(); // } if (isset($_POST['confirmation_email']) && !empty($_POST['email'])) { if (strpos($_POST['confirmation_email'], '../') !== false || strpos($_POST['confirmation_email'], '..\\') !== false) { throw new Exception('Invalid path'); } $path = \GO::config()->file_storage_path . $_POST['confirmation_email']; if (!file_exists($path)) { $path = dirname(\GO::config()->get_config_file()) . '/' . $_POST['confirmation_email']; } //$email = file_get_contents($path); //$messageModel = \GO\Email\Model\SavedMessage::model()->createFromMimeFile($path); // $htmlBodyString = \GO\Addressbook\Model\Template::model()->replaceUserTags($messageModel->getHtmlBody()); // $htmlBodyString = \GO\Addressbook\Model\Template::model() // ->replaceContactTags( // $htmlBodyString, // \GO\Addressbook\Model\Contact::model()->findByPk($contactId), // false); // $messageModel->body = $mailMessage = \GO\Base\Mail\Message::newInstance()->loadMimeMessage(file_get_contents($path)); $htmlBodyString = $mailMessage->getBody(); foreach ($this->confirmation_replacements as $tag => $replacement) { $htmlBodyString = str_replace('{' . $tag . '}', $replacement, $htmlBodyString); } $htmlBodyString = \GO\Addressbook\Model\Template::model()->replaceUserTags($htmlBodyString, true); $htmlBodyString = \GO\Addressbook\Model\Template::model()->replaceContactTags($htmlBodyString, \GO\Addressbook\Model\Contact::model()->findByPk($contactId), false); $mailMessage->setBody($htmlBodyString); $mailMessage->setFrom($mailMessage->getFrom(), $mailMessage->getSender()); $mailMessage->addTo($_POST['email']); \GO\Base\Mail\Mailer::newGoInstance()->send($mailMessage); } } }
protected function actionImages($params) { if (isset($params["id"])) { $currentFile = \GO\Files\Model\File::model()->findByPk($params["id"]); } else { $currentFile = \GO\Files\Model\File::model()->findByPath($params["path"]); } $folder = $currentFile->folder(); $thumbParams = json_decode($params['thumbParams'], true); $response["success"] = true; $response['images'] = array(); $response['index'] = $index = 0; if (!isset($params["sort"])) { $params["sort"] = "name"; } if (!isset($params["dir"])) { $params["dir"] = "ASC"; } $findParams = \GO\Base\Db\FindParams::newInstance()->order($params["sort"], $params["dir"]); $stmt = $folder->files($findParams); while ($file = $stmt->fetch()) { if ($file->isImage()) { if ($file->id == $currentFile->id) { $response['index'] = $index; } $index++; $response['images'][] = array("name" => $file->name, "download_path" => $file->downloadUrl, "src" => $file->getThumbUrl($thumbParams)); } } return $response; }
/** * This method will (re)calculate the used diskspace for this user * @param integer $bytes The amount of bytes to add to the users used diskspace (negative for substraction) * @return User itself for chaining eg. $user->calculatedDiskUsage()->save() */ public function calculatedDiskUsage($bytes = false) { if (GO::modules()->isInstalled('files')) { if (!$bytes) { //recalculated $fp = \GO\Base\Db\FindParams::newInstance()->select('SUM(size) as total_size')->joinModel(array('model' => 'GO\\Files\\Model\\Folder', 'localTableAlias' => 't', 'localField' => 'folder_id', 'tableAlias' => 'd'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('quota_user_id', $this->id, '=', 'd')); $sumFilesize = \GO\Files\Model\File::model()->findSingle($fp); $fpVer = \GO\Base\Db\FindParams::newInstance()->select('SUM(size_bytes) as total_size')->joinModel(array('model' => 'GO\\Files\\Model\\File', 'localTableAlias' => 't', 'localField' => 'file_id', 'tableAlias' => 'f'))->joinModel(array('model' => 'GO\\Files\\Model\\Folder', 'localTableAlias' => 'f', 'localField' => 'folder_id', 'tableAlias' => 'd'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('quota_user_id', $this->id, '=', 'd')); $sumVersionsize = \GO\Files\Model\Version::model()->findSingle($fpVer); //GO::debug($sumFilesize->total_size); if ($sumFilesize) { $this->disk_usage = $sumFilesize->total_size + $sumVersionsize->total_size; } } else { $this->disk_usage += $bytes; } } else { throw new \Exceptions('Can not calculated diskusage without the files module'); } return $this; }