Beispiel #1
0
 protected function beforeSave()
 {
     if ($this->isNew && !empty($this->domain->max_aliases)) {
         if ($this->domain->getSumAliases() >= $this->domain->max_aliases) {
             throw new \Exception('The maximum number of aliases for this domain has been reached.');
         }
     }
     return parent::beforeSave();
 }
Beispiel #2
0
 protected function beforeSave()
 {
     if ($this->isModified("password")) {
         $this->password = '******' . crypt($this->password);
     }
     $parts = explode('@', $this->username);
     $this->maildir = $this->domain->domain . '/' . $parts[0] . '/';
     return parent::beforeSave();
 }
Beispiel #3
0
 protected function beforeSave()
 {
     $folderModel = Folder::model()->findByPk($this->folder_id);
     $existingBookmarkModel = Bookmark::model()->findSingleByAttributes(array('user_id' => \GO::user()->id, 'folder_id' => $folderModel->id));
     if (!empty($existingBookmarkModel)) {
         throw new \Exception(str_replace('%fn', $folderModel->name, \GO::t('bookmarkAlreadyExists', 'files')));
     }
     return parent::beforeSave();
 }
 protected function beforeSave()
 {
     if ($this->isNew && empty($this->sort)) {
         $record = $this->findSingle(array('fields' => 'MAX(`sort`) AS sort', 'where' => 'field_id=:field_id', 'bindParams' => array('field_id' => $this->field_id)));
         if ($record) {
             $this->sort = intval($record->sort);
         }
     }
     return parent::beforeSave();
 }
Beispiel #5
0
 protected function beforeSave()
 {
     $this->mtime = $this->file->fsFile->mtime();
     $this->path = $this->file->getVersionStoragePath() . '/' . date('Ymd_Gis', $this->file->fsFile->mtime()) . '_' . $this->file->name;
     $lastVersion = $this->_findLastVersion();
     if ($lastVersion) {
         $this->version = $lastVersion->version + 1;
     }
     return parent::beforeSave();
 }
Beispiel #6
0
 protected function beforeSave()
 {
     if ($this->isNew) {
         $this->version = $this->moduleManager->databaseVersion();
         $this->admin_menu = $this->moduleManager->adminModule();
     }
     return parent::beforeSave();
 }
Beispiel #7
0
 protected function beforeSave()
 {
     if ($this->rrule != "") {
         $rrule = new \GO\Base\Util\Icalendar\Rrule();
         $rrule->readIcalendarRruleString($this->start_time, $this->rrule);
         $this->repeat_end_time = intval($rrule->until);
     }
     //if this is not the organizer event it may only be modified by the organizer
     if (!$this->is_organizer && !$this->updatingRelatedEvent && !$this->_isImport && !$this->isNew && $this->isModified($this->getRelevantMeetingAttributes())) {
         //			$organizerEvent = $this->getOrganizerEvent();
         //			if($organizerEvent && !$organizerEvent->checkPermissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION) || !$organizerEvent && !$this->is_organizer){
         //				\GO::debug($this->getModifiedAttributes());
         //				\GO::debug($this->_attributes);
         throw new \GO\Base\Exception\AccessDenied();
         //			}
     }
     //		//Don't set reminders for the superadmin
     //		if($this->calendar->user_id==1 && \GO::user()->id!=1 && !\GO::config()->debug)
     //			$this->reminder=0;
     if ($this->isResource()) {
         // If resource is added by its admin, automatically set it to CONFIRMED.
         $adminUserIds = array();
         $groupAdminsStmt = $this->calendar->group->admins;
         while ($adminUser = $groupAdminsStmt->fetch()) {
             $adminUserIds[] = $adminUser->id;
         }
         if (in_array(\GO::user()->id, $adminUserIds) && $this->getIsNew()) {
             $this->status = 'CONFIRMED';
         }
         if ($this->status == 'CONFIRMED') {
             $this->background = 'CCFFCC';
         } else {
             $this->background = 'FF6666';
         }
     }
     return parent::beforeSave();
 }
Beispiel #8
0
 protected function beforeSave()
 {
     if ($this->isModified('password')) {
         $decrypted = \GO\Base\Util\Crypt::decrypt($this->getOldAttributeValue('password'));
         if ($decrypted == $this->password) {
             $this->resetAttribute('password');
         } else {
             $encrypted = \GO\Base\Util\Crypt::encrypt($this->password);
             if ($encrypted) {
                 $this->password = $encrypted;
                 $this->password_encrypted = 2;
                 //deprecated. remove when email is mvc style.
             }
         }
         unset(GO::session()->values['emailModule']['accountPasswords'][$this->id]);
     }
     //		if (!empty($this->id) && !empty(GO::session()->values['emailModule']['accountPasswords'][$this->id]))
     //			unset(GO::session()->values['emailModule']['accountPasswords'][$this->id]);
     if ($this->isModified('smtp_password')) {
         $encrypted = \GO\Base\Util\Crypt::encrypt($this->smtp_password);
         if ($encrypted) {
             $this->smtp_password = $encrypted;
         }
     }
     if (($this->isNew || $this->isModified("host") || $this->isModified("port") || $this->isModified("username") || $this->isModified("password")) && $this->checkImapConnectionOnSave) {
         $imap = $this->openImapConnection();
         $this->mbroot = $imap->check_mbroot($this->mbroot);
         $this->_createDefaultFolder('sent');
         $this->_createDefaultFolder('trash');
         //	$this->_createDefaultFolder('spam');
         $this->_createDefaultFolder('drafts');
     }
     if (empty($this->store_password)) {
         $this->_session_password = $this->password;
         $this->password = '';
         $this->password_encrypted = 0;
     }
     if (empty($this->store_smtp_password)) {
         $this->_session_smtp_password = $this->smtp_password;
         $this->smtp_password = '';
     }
     return parent::beforeSave();
 }
Beispiel #9
0
 protected function beforeSave()
 {
     //check permissions on the filesystem
     if ($this->isNew) {
         if (!$this->folder->fsFolder->isWritable()) {
             throw new \Exception("Folder " . $this->folder->path . " is read only on the filesystem. Please check the file system permissions (hint: chown -R www-data:www-data /home/groupoffice)");
         }
     } else {
         if ($this->isModified('name') || $this->isModified('folder_id')) {
             if (!$this->_getOldFsFile()->isWritable()) {
                 throw new \Exception("File " . $this->path . " is read only on the filesystem. Please check the file system permissions (hint: chown -R www-data:www-data /home/groupoffice)");
             }
         }
     }
     if (!$this->isNew) {
         if ($this->isModified('name')) {
             //rename filesystem file.
             //throw new \Exception($this->getOldAttributeValue('name'));
             $oldFsFile = $this->_getOldFsFile();
             if ($oldFsFile->exists()) {
                 $oldFsFile->rename($this->name);
             }
             $this->notifyUsers($this->folder_id, FolderNotificationMessage::RENAME_FILE, $this->folder->path . '/' . $this->getOldAttributeValue('name'), $this->folder->path . '/' . $this->name);
         }
         if ($this->isModified('folder_id')) {
             if (!isset($oldFsFile)) {
                 $oldFsFile = $this->_getOldFsFile();
             }
             if (!$oldFsFile->move(new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . dirname($this->path)))) {
                 throw new \Exception("Could not rename folder on the filesystem");
             }
             //get old folder objekt
             $oldFolderId = $this->getOldAttributeValue('folder_id');
             $oldFolder = Folder::model()->findByPk($oldFolderId);
             $this->notifyUsers(array($this->getOldAttributeValue('folder_id'), $this->folder_id), FolderNotificationMessage::MOVE_FILE, $oldFolder->path . '/' . $this->name, $this->path);
         }
     }
     if ($this->isModified('locked_user_id')) {
         $old_locked_user_id = $this->getOldAttributeValue('locked_user_id');
         if (!empty($old_locked_user_id) && $old_locked_user_id != \GO::user()->id && !\GO::user()->isAdmin()) {
             throw new \GO\Files\Exception\FileLocked();
         }
     }
     $this->extension = $this->fsFile->extension();
     //make sure extension is not too long
     $this->cutAttributeLength("extension");
     $this->size = $this->fsFile->size();
     //$this->ctime = $this->fsFile->ctime();
     $this->mtime = $this->fsFile->mtime();
     $existingFile = $this->folder->hasFile($this->name);
     if ($existingFile && $existingFile->id != $this->id) {
         throw new \Exception(sprintf(\GO::t('filenameExists', 'files'), $this->path));
     }
     return parent::beforeSave();
 }
Beispiel #10
0
 protected function beforeSave()
 {
     if (!$this->customfieldtype->hasLength()) {
         //user may not set length so take the default
         $this->max_length = $this->customfieldtype->getMaxLength();
     }
     if ($this->isNew) {
         $this->sort_index = $this->count();
     }
     $this->addressbook_ids = preg_replace('/[^\\d^,]/', '', $this->addressbook_ids);
     if (strlen($this->addressbook_ids) > 0 && $this->addressbook_ids[0] == ',') {
         $this->addressbook_ids = substr($this->addressbook_ids, 1);
     }
     if (strlen($this->addressbook_ids) > 0 && $this->addressbook_ids[strlen($this->addressbook_ids) - 1] == ',') {
         $this->addressbook_ids = substr($this->addressbook_ids, 0, -1);
     }
     return parent::beforeSave();
 }
Beispiel #11
0
 protected function beforeSave()
 {
     if ($this->isNew) {
         $holiday = Holiday::localeFromCountry($this->language);
         if ($holiday !== false) {
             $this->holidayset = $holiday;
         }
     }
     if (!$this->isNew && empty($this->holidayset) && ($contact = $this->createContact())) {
         $holiday = Holiday::localeFromCountry($contact->country);
         if ($holiday !== false) {
             $this->holidayset = $holiday;
         }
     }
     if ($this->isModified('password') && !empty($this->password)) {
         $this->_unencryptedPassword = $this->password;
         $this->password = $this->_encryptPassword($this->password);
         $this->password_type = 'crypt';
         $this->digest = md5($this->username . ":" . GO::config()->product_name . ":" . $this->_unencryptedPassword);
     }
     return parent::beforeSave();
 }
Beispiel #12
0
 protected function beforeSave()
 {
     //check permissions on the filesystem
     if ($this->isNew) {
         if (!$this->fsFolder->firstExistingParent()->isWritable()) {
             throw new \Exception("Folder " . $this->fsFolder->firstExistingParent()->stripFileStoragePath() . " (Creating " . $this->name . ") is read only on the filesystem. Please check the file system permissions (hint: chown -R www-data:www-data /home/groupoffice)");
         }
     } else {
         if ($this->isModified('name') || $this->isModified('parent_id')) {
             if ($this->_getOldFsFolder() && $this->_getOldFsFolder()->exists() && !$this->_getOldFsFolder()->isWritable()) {
                 throw new \Exception("Folder " . $this->path . " is read only on the filesystem. Please check the file system permissions (hint: chown -R www-data:www-data /home/groupoffice)");
             }
         }
     }
     if (!$this->systemSave && !$this->isNew && $this->readonly) {
         if ($this->isModified('name') || $this->isModified('folder_id')) {
             return false;
         }
     }
     if ($this->parent) {
         $existingFolder = $this->parent->hasFolder($this->name);
         if ($existingFolder && $existingFolder->id != $this->id) {
             throw new \Exception(\GO::t('folderExists', 'files') . ': ' . $this->path);
         }
     }
     if ($this->isNew && empty($this->quota_user_id)) {
         $shared_folder = $this;
         while (!$shared_folder->isSomeonesHomeFolder() && $shared_folder->parent_id != 0) {
             $shared_folder = $shared_folder->parent;
         }
         $this->quota_user_id = $shared_folder->user_id;
     }
     return parent::beforeSave();
 }
Beispiel #13
0
 protected function beforeSave()
 {
     //$this->params = $this->_paramsToJson();
     $this->nextrun = $this->_calculateNextRun();
     //if the cron happens within a minute then substract one minute for immediate testing.
     if (GO::config()->debug && PHP_SAPI != 'cli') {
         if ($this->nextrun < time() + 61) {
             $this->nextrun -= 60;
         }
     }
     GO::debug('CRONJOB (' . $this->name . ') NEXTRUN : ' . $this->getAttribute('nextrun', 'formatted'));
     return parent::beforeSave();
 }
Beispiel #14
0
 protected function beforeSave()
 {
     // Check for a user with this email address
     if ($this->isNew && $this->user_id === null) {
         $user = \GO\Base\Model\User::model()->findSingleByAttribute('email', $this->email);
         if ($user) {
             $this->user_id = $user->id;
         }
     }
     if ($this->is_organizer) {
         $this->status = self::STATUS_ACCEPTED;
     }
     return parent::beforeSave();
 }
Beispiel #15
0
 protected function beforeSave()
 {
     if (!empty($this->userInputPassword1)) {
         $this->password = crypt($this->userInputPassword1);
         $encrypted = Crypt::encrypt($this->content, $this->userInputPassword1);
         if ($encrypted === false) {
             throw new \Exception("Could not encrypt note. Is mcrypt for php installed?");
         }
         $this->content = $encrypted;
     } else {
         $this->password = "";
     }
     return parent::beforeSave();
 }
Beispiel #16
0
 public function beforeSave()
 {
     if ($this->isModified('status')) {
         $this->setCompleted($this->status == Task::STATUS_COMPLETED, false);
     }
     return parent::beforeSave();
 }
Beispiel #17
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();
 }
Beispiel #18
0
 protected function beforeSave()
 {
     if ($this->isNew) {
         $this->sort_index = $this->count();
     }
     return parent::beforeSave();
 }
Beispiel #19
0
 protected function beforeSave()
 {
     if (!empty($this->homepage)) {
         $this->homepage = \GO\Base\Util\Http::checkUrlForHttp($this->homepage);
     }
     $this->_autoSalutation();
     if (strtolower($this->sex) == strtolower(\GO::t('female', 'addressbook'))) {
         $this->sex = 'F';
     }
     $this->sex = $this->sex == 'M' || $this->sex == 'F' ? $this->sex : 'M';
     //Auto create company if company_id is a String and can't be found.
     if (!empty($this->company_name)) {
         $company = Company::model()->findSingleByAttributes(array('addressbook_id' => $this->addressbook_id, 'name' => $this->company_name));
         if (!$company) {
             $company = new Company();
             $company->name = $this->company_name;
             $company->addressbook_id = $this->addressbook_id;
             $company->save();
         }
         $this->company_id = $company->id;
     }
     $this->_prefixSocialMediaLinks();
     if (empty($this->color)) {
         $this->color = "000000";
     }
     return parent::beforeSave();
 }