Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • ActionMetaData
  • ActionText
  • Admin
  • AmorphousModel
  • ApiHook
  • APIModel
  • ChartSetting
  • ContactForm
  • ContactList
  • Credentials
  • Criteria
  • Dropdowns
  • Events
  • EventsData
  • Fields
  • FormLayout
  • Imports
  • InlineEmail
  • LeadRouting
  • Locations
  • LoginForm
  • Maps
  • Modules
  • Notes
  • Notification
  • PhoneNumber
  • Profile
  • Record
  • Relationships
  • Roles
  • RoleToPermission
  • RoleToUser
  • RoleToWorkflow
  • Rules
  • Session
  • SessionLog
  • Social
  • Tags
  • TempFile
  • Tips
  • Tours
  • TrackEmail
  • TriggerLog
  • URL
  • ViewLog
  • Widgets
  • X2List
  • X2ListCriterion
  • X2ListItem
  • X2Model
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /*****************************************************************************************
  4:  * X2Engine Open Source Edition is a customer relationship management program developed by
  5:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  6:  * 
  7:  * This program is free software; you can redistribute it and/or modify it under
  8:  * the terms of the GNU Affero General Public License version 3 as published by the
  9:  * Free Software Foundation with the addition of the following permission added
 10:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 11:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 12:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 13:  * 
 14:  * This program is distributed in the hope that it will be useful, but WITHOUT
 15:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 16:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 17:  * details.
 18:  * 
 19:  * You should have received a copy of the GNU Affero General Public License along with
 20:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 21:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 22:  * 02110-1301 USA.
 23:  * 
 24:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 25:  * California 95067, USA. or at email address contact@x2engine.com.
 26:  * 
 27:  * The interactive user interfaces in modified source and object code versions
 28:  * of this program must display Appropriate Legal Notices, as required under
 29:  * Section 5 of the GNU Affero General Public License version 3.
 30:  * 
 31:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 32:  * these Appropriate Legal Notices must retain the display of the "Powered by
 33:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 34:  * technical reasons, the Appropriate Legal Notices must display the words
 35:  * "Powered by X2Engine".
 36:  *****************************************************************************************/
 37: 
 38: Yii::import('application.components.JSONEmbeddedModelFieldsBehavior');
 39: 
 40: /**
 41:  * This is the model class for table "x2_admin".
 42:  * @package application.models
 43:  */
 44: class Admin extends X2ActiveRecord {
 45: 
 46:     protected $_oldAttributes = array();
 47: 
 48:     /**
 49:      * Returns the static model of the specified AR class.
 50:      * @return Admin the static model class
 51:      */
 52:     public static function model($className = __CLASS__){
 53:         return parent::model($className);
 54:     }
 55: 
 56:     public static function getDoNotEmailLinkDefaultText () {
 57:         return Yii::t('admin', 'I do not wish to receive these emails.');
 58:     }
 59: 
 60:     public static function getDoNotEmailDefaultPage () {
 61:         $message = Yii::t(
 62:             'admin', 'You will no longer receive emails from this sender.');
 63:         return '<html><head><title>'.$message.
 64:             '</title></head><body>'.$message.'</body></html>';
 65:     }
 66: 
 67:     private $_googleIntegrationCredentials;
 68:     public function getGoogleIntegrationCredentials ($refresh=false) {
 69:         if (!isset ($this->_googleIntegrationCredentials) || $refresh) {
 70:             $credId = Yii::app()->settings->googleCredentialsId;
 71:             if ($credId && ($credentials = Credentials::model ()->findByPk ($credId))) {
 72:                 $this->_googleIntegrationCredentials = array (
 73:                      
 74:                     'clientId' => $credentials->auth->clientId,
 75:                     'clientSecret' => $credentials->auth->clientSecret,
 76:                 );
 77:             }
 78:         }
 79:         return $this->_googleIntegrationCredentials;
 80:     }
 81: 
 82:     /**
 83:      * @return string the associated database table name
 84:      */
 85:     public function tableName(){
 86:         return 'x2_admin';
 87:     }
 88: 
 89:     /**
 90:      * Saves attributes on initial model lookup
 91:      */
 92:     public function afterFind() {
 93:         $this->_oldAttributes = $this->getAttributes();
 94:         parent::afterFind();
 95:     }
 96: 
 97:     public function behaviors(){
 98:         $behaviors = array(
 99:             'JSONFieldsBehavior' => array (
100:                 'class' => 'application.components.JSONFieldsBehavior',
101:                 'transformAttributes' => array (
102:                     'twitterRateLimits',
103:                     'assetBaseUrls',
104:                 ),
105:             ),
106:             'JSONFieldsDefaultValuesBehavior' => array(
107:                 'class' => 'application.components.JSONFieldsDefaultValuesBehavior',
108:                 'transformAttributes' => array(
109:                     'actionPublisherTabs' => array(
110:                         'PublisherCommentTab' => true,
111:                         'PublisherActionTab' => true,
112:                         'PublisherCallTab' => true,
113:                         'PublisherTimeTab' => true,
114:                         'PublisherEventTab' => false,
115:                         'PublisherProductsTab' => false,
116:                     ),
117:                     
118:                 ),
119:                 'maintainCurrentFieldsOrder' => true
120:             ),
121:         );
122:         
123:         return $behaviors;
124:     }
125: 
126:     public function validateUniqueId ($attr) {
127:         $value = $this->$attr;
128:         // flush license key info cache when license key changes
129:         if (!isset ($this->_oldAttributes[$attr]) || $value !== $this->_oldAttributes[$attr]) {
130:             Yii::app()->cache2->delete ($this->getLicenseKeyInfoCacheKey ());
131:         }
132:     }
133: 
134:     /**
135:      * Custom validator for an array of URLs
136:      */
137:     public function validateUrlArray ($attr, $params) {
138:         $values = $this->$attr;
139:         $urlValidator = new CUrlValidator;
140:         $allowEmpty = array_key_exists ('allowEmpty', $params) && $params['allowEmpty'];
141: 
142:         if (is_array ($values)) {
143:             foreach ($values as $url) {
144:                 if ($urlValidator->validateValue ($url) || ($allowEmpty && empty($url)))
145:                     continue;
146:                 $this->addError (
147:                     $attr,
148:                     Yii::t('admin', 'The specified URL "{url}" is not in the correct format.', array(
149:                         '{url}' => CHtml::encode($url),
150:                     ))
151:                 );
152:             }
153:         }
154:     }
155: 
156:     /**
157:      * @return array validation rules for model attributes.
158:      */
159:     public function rules(){
160:         // NOTE: you should only define rules for those attributes that
161:         // will receive user inputs.
162:         return array(
163:             array('unique_id', 'validateUniqueId'),
164:             array('emailType,emailFromName, emailFromAddr', 'requiredIfSysDefault', 'field' => 'emailBulkAccount'),
165:             array('serviceCaseFromEmailName, serviceCaseFromEmailAddress', 'requiredIfSysDefault', 'field' => 'serviceCaseEmailAccount'),
166:             array('serviceCaseEmailSubject, serviceCaseEmailMessage', 'required'),
167:             array('timeout, webTrackerCooldown, chatPollTime, ignoreUpdates, rrId, onlineOnly, emailBatchSize, emailInterval, emailPort, installDate, updateDate, updateInterval, workflowBackdateWindow, workflowBackdateRange', 'numerical', 'integerOnly' => true),
168:             // accounts, sales,
169:             array('chatPollTime', 'numerical', 'max' => 100000, 'min' => 100),
170:             array('currency', 'length', 'max' => 3),
171:             array('emailUseAuth, emailUseSignature', 'length', 'max' => 10),
172:             array('emailType, emailSecurity,gaTracking_internal,gaTracking_public', 'length', 'max' => 20),
173:             array('webLeadEmail, leadDistribution, emailFromName, emailFromAddr, emailHost, emailUser, emailPass,externalBaseUrl,externalBaseUri', 'length', 'max' => 255),
174:             // array('emailSignature', 'length', 'max'=>512),
175:             array('batchTimeout', 'numerical', 'integerOnly' => true),
176:             array(
177:                 'massActionsBatchSize',
178:                 'numerical',
179:                 'integerOnly' => true,
180:                 'min' => 5,
181:                 'max' => 100,
182:             ),
183:             array('emailBulkAccount,serviceCaseEmailAccount', 'safe'),
184:             
185:             array('emailBulkAccount', 'setDefaultEmailAccount', 'alias' => 'bulkEmail'),
186:             array('serviceCaseEmailAccount', 'setDefaultEmailAccount', 'alias' => 'serviceCaseEmail'),
187:             array('webLeadEmailAccount','setDefaultEmailAccount','alias' => 'systemResponseEmail'),
188:             array('emailNotificationAccount','setDefaultEmailAccount','alias'=>'systemNotificationEmail'),
189:             array('emailSignature', 'length', 'max' => 4096),
190:             array('externalBaseUrl','url','allowEmpty'=>true),
191:             array('assetBaseUrls','validateUrlArray','allowEmpty'=>false),
192:             array('externalBaseUrl','match','pattern'=>':/$:','not'=>true,'allowEmpty'=>true,'message'=>Yii::t('admin','Value must not include a trailing slash.')),
193:             array('enableWebTracker, quoteStrictLock, workflowBackdateReassignment,disableAutomaticRecordTagging,enableAssetDomains, enableUnsubscribeHeader', 'boolean'),
194:             array('gaTracking_internal,gaTracking_public', 'match', 'pattern' => "/'/", 'not' => true, 'message' => Yii::t('admin', 'Invalid property ID')),
195:             array ('appDescription', 'length', 'max' => 255),
196:             array (
197:                 'appName,x2FlowRespectsDoNotEmail,doNotEmailPage,doNotEmailLinkText',
198:                 'safe'
199:             ),
200:             
201:             
202:                 // The following rule is used by search().
203:                 // Please remove those attributes that should not be searched.
204:                 // array('id, accounts, sales, timeout, webLeadEmail, menuOrder, menuNicknames, chatPollTime, menuVisibility, currency', 'safe', 'on'=>'search'),
205:         );
206:     }
207: 
208:     /**
209:      * @return array customized attribute labels (name=>label)
210:      */
211:     public function attributeLabels(){
212:         return array(
213:             'id' => Yii::t('admin', 'ID'),
214:             // 'accounts' => Yii::t('admin','Accounts'),
215:             // 'sales' => Yii::t('admin','Opportunities'),
216:             'timeout' => Yii::t('admin', 'Session Timeout'),
217:             'webLeadEmail' => Yii::t('admin', 'Web Lead Email'),
218:             'enableWebTracker' => Yii::t('admin', 'Enable Web Tracker'),
219:             'webTrackerCooldown' => Yii::t('admin', 'Web Tracker Cooldown'),
220:             'currency' => Yii::t('admin', 'Currency'),
221:             'chatPollTime' => Yii::t('admin', 'Notification Poll Time'),
222:             'ignoreUpdates' => Yii::t('admin', 'Ignore Updates'),
223:             'rrId' => Yii::t('admin', 'Round Robin ID'),
224:             'leadDistribution' => Yii::t('admin', 'Lead Distribution'),
225:             'onlineOnly' => Yii::t('admin', 'Online Only'),
226:             'disableAutomaticRecordTagging' => 
227:                 Yii::t('profile', 'Disable automatic record tagging?'),
228:             'emailBulkAccount' => Yii::t('admin', 'Send As (when sending bulk email)'),
229:             'emailFromName' => Yii::t('admin', 'Sender Name'),
230:             'emailFromAddr' => Yii::t('admin', 'Sender Email Address'),
231:             'emailBatchSize' => Yii::t('admin', 'Batch Size'),
232:             'emailInterval' => Yii::t('admin', 'Interval (Minutes)'),
233:             'emailUseSignature' => Yii::t('admin', 'Email Signatures'),
234:             'emailSignature' => Yii::t('admin', 'Default Signature'),
235:             'emailType' => Yii::t('admin', 'Method'),
236:             'emailHost' => Yii::t('admin', 'Hostname'),
237:             'emailPort' => Yii::t('admin', 'Port'),
238:             'emailUseAuth' => Yii::t('admin', 'Authentication'),
239:             'emailUser' => Yii::t('admin', 'Username'),
240:             'emailPass' => Yii::t('admin', 'Password'),
241:             'emailSecurity' => Yii::t('admin', 'Security'),
242:             'enableColorDropdownLegend' => Yii::t('admin', 'Colorize Dropdown Options?'),
243:             'installDate' => Yii::t('admin', 'Installed'),
244:             'updateDate' => Yii::t('admin', 'Last Update'),
245:             'updateInterval' => Yii::t('admin', 'Version Check Interval'),
246:             'googleIntegration' => Yii::t('admin', 'Activate Google Integration'),
247:             'inviteKey' => Yii::t('admin', 'Invite Key'),
248:             'workflowBackdateWindow' => Yii::t('admin', 'Process Backdate Window'),
249:             'workflowBackdateRange' => Yii::t('admin', 'Process Backdate Range'),
250:             'workflowBackdateReassignment' => Yii::t('admin', 'Process Backdate Reassignment'),
251:             'serviceCaseEmailAccount' => Yii::t('admin', 'Send As (to service requesters)'),
252:             'serviceCaseFromEmailName' => Yii::t('admin', 'Sender Name'),
253:             'serviceCaseFromEmailAddress' => Yii::t('admin', 'Sender Email Address'),
254:             'serviceCaseEmailSubject' => Yii::t('admin', 'Subject'),
255:             'serviceCaseEmailMessage' => Yii::t('admin', 'Email Message'),
256:             'gaTracking_public' => Yii::t('admin', 'Google Analytics Property ID (public)'),
257:             'gaTracking_internal' => Yii::t('admin', 'Google Analytics Property ID (internal)'),
258:             'serviceDistribution' => Yii::t('admin', 'Service Distribution'),
259:             'serviceOnlineOnly' => Yii::t('admin', 'Service Online Only'),
260:             'eventDeletionTime' => Yii::t('admin', 'Event Deletion Time'),
261:             'eventDeletionTypes' => Yii::t('admin', 'Event Deletion Types'),
262:             'properCaseNames' => Yii::t('admin', 'Proper Case Names'),
263:             'contactNameFormat' => Yii::t('admin', 'Contact Name Format'),
264:             'webLeadEmailAccount' => Yii::t('admin','Send As (to web leads)'),
265:             'emailNotificationAccount' => Yii::t('admin','Send As (when notifying users)'),
266:             'batchTimeout' => Yii::t('admin','Time limit on batch actions'),
267:             'massActionsBatchSize' => Yii::t('admin','Batch size for grid view mass actions'),
268:             'externalBaseUrl' => Yii::t('admin','External / Public Base URL'),
269:             'externalBaseUri' => Yii::t('admin','External / Public Base URI'),
270:             'appName' => Yii::t('admin','Application Name'),
271:             'x2FlowRespectsDoNotEmail' => Yii::t(
272:                 'app','Respect contacts\' "Do not email" settings?'),
273:             'doNotEmailLinkText' => Yii::t('admin','"Do not email" Link Text'),
274:             'doNotEmailLinkPage' => Yii::t('admin','"Do not email" Page'),
275:             'doNotEmailPage' => Yii::t('admin','Do Not Email Page'),
276:             'enableAssetDomains' => Yii::t('admin','Enable Asset Domains'),
277:              
278:             
279:         );
280:     }
281: 
282:     public function requiredIfSysDefault($attribute, $params){
283:         if(empty($this->$attribute) && $this->{$params['field']} == Credentials::LEGACY_ID)
284:             $this->addError($attribute, Yii::t('yii', '{attribute} cannot be blank.', array('{attribute}' => $this->getAttributeLabel($attribute))));
285:     }
286: 
287:     public function setDefaultEmailAccount($attribute, $params){
288:         if($this->$attribute != Credentials::LEGACY_ID){
289:             $cred = Credentials::model()->findByPk($this->$attribute);
290:             if($cred)
291:                 $cred->makeDefault(Credentials::$sysUseId[$params['alias']], 'email', false);
292:         } else{
293:             Yii::app()->db->createCommand()->delete('x2_credentials_default', 'userId=:uid AND serviceType=:st', array(':uid' => Credentials::$sysUseId[$params['alias']], ':st' => 'email'));
294:         }
295:     }
296: 
297:     /**
298:      * Record that a number of emails have been sent, to avoid going over the
299:      * bulk email batch size per interval.
300:      * 
301:      * @param integer $nEmail Number of emails that will have been sent
302:      */
303:     public function countEmail($nEmail = 1) {
304:         $now = time();
305:         if(empty($this->emailStartTime))
306:             $this->emailStartTime = $now;
307:         if($now-$this->emailStartTime > $this->emailInterval) {
308:             // Reset
309:             $this->emailStartTime = $now;
310:             $this->emailCount = 0;
311:         }
312:         $this->emailCount += $nEmail;
313:         $this->update(array('emailCount','emailStartTime'));
314:         return $this->emailCount;
315:     }
316: 
317:     /**
318:      * Returns true or false based on whether a number of emails to be sent will
319:      * exceed the batch maximum.
320:      *
321:      * @param integer $nEmail Number of emails to be sent
322:      */
323:     public function emailCountWillExceedLimit($nEmail=1) {
324:         $now = time();
325:         if($now-$this->emailStartTime > $this->emailInterval) {
326:             $this->emailStartTime = $now;
327:             $this->emailCount = 0;
328:         }
329:         return $this->emailCount + $nEmail > $this->emailBatchSize;
330:     }
331: 
332:     /**
333:      * @param array $value This should match the structure of the actionPublisherTabs property
334:      *  specified in the JSONFieldsDefaultValuesBehavior configuration
335:      */
336:     public function setActionPublisherTabs ($value) {
337:         $this->actionPublisherTabs = $value;
338:         $this->save ();
339:     }
340: 
341:     
342:     
343:     public function getDoNotEmailLinkText(){
344:         if(!empty($this->doNotEmailLinkText)){
345:             return $this->doNotEmailLinkText;
346:         }
347:         return self::getDoNotEmailLinkDefaultText ();
348:     }
349: 
350:      
351: 
352:     private function getLicenseKeyInfoCacheKey () {
353:         return 'Admin::getLicenseKeyInfoCacheKey';
354:     }
355: }
356: 
357: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0