1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
37:
38: Yii::import('application.models.embedded.JSONEmbeddedModel');
39:
40: 41: 42: 43: 44: 45: 46:
47: class EmailAccount extends JSONEmbeddedModel {
48:
49: public $email = '';
50: public $imapNoValidate = false;
51: public $imapPort = 143;
52: public $imapSecurity = '';
53: public $imapServer = '';
54: public $password = '';
55: public $port = 25;
56: public $security = '';
57: public $senderName = '';
58: public $server = '';
59: public $user = '';
60: public $enableVerification = true;
61:
62: public function attributeLabels(){
63: return array(
64: 'senderName' => Yii::t('app', 'Sender Name'),
65: 'email' => Yii::t('app', 'Email address'),
66: 'server' => Yii::t('app', 'Server'),
67: 'port' => Yii::t('app', 'Port'),
68: 'security' => Yii::t('app', 'Security type'),
69: 'user' => Yii::t('app', 'User name (if different from email address)'),
70: 'password' => Yii::t('app', 'Password'),
71: 'imapPort' => Yii::t('app','IMAP Port'),
72: 'imapServer' => Yii::t('app','IMAP Server'),
73: 'imapSecurity' => Yii::t('app','IMAP Security'),
74: 'imapNoValidate' => Yii::t('app','Disable SSL Validation'),
75: );
76: }
77:
78: public function detailView(){
79: echo "\"{$this->senderName}\" <{$this->email}> • {$this->server}:{$this->port}".($this->security != '' ?' • '.Yii::t('app','secured with')." {$this->security}" : '');
80: }
81:
82: public function modelLabel() {
83: return Yii::t('app','Email Account');
84: }
85:
86: public function renderInput ($attr) {
87: switch($attr){
88: case 'senderName':
89: echo CHtml::activeTextField($this, $attr, $this->htmlOptions($attr));
90: break;
91: case 'email':
92: echo CHtml::activeTextField($this, $attr, $this->htmlOptions($attr));
93: break;
94: case 'server':
95: echo CHtml::activeTextField($this, $attr, $this->htmlOptions($attr));
96: break;
97: case 'imapServer':
98: echo CHtml::activeTextField($this, $attr, $this->htmlOptions($attr));
99: break;
100: case 'port':
101: echo CHtml::activeNumberField($this, $attr, $this->htmlOptions($attr));
102: break;
103: case 'imapPort':
104: echo CHtml::activeNumberField($this, $attr, $this->htmlOptions($attr));
105: break;
106: case 'security':
107: echo CHtml::activeDropDownList($this, $attr,array(''=>'None','tls'=>'TLS','ssl'=>'SSL'), $this->htmlOptions($attr));
108: break;
109: case 'imapSecurity':
110: echo CHtml::activeDropDownList($this, $attr,array(''=>'None','tls'=>'TLS','ssl'=>'SSL'), $this->htmlOptions($attr));
111: break;
112: case 'imapNoValidate':
113: echo CHtml::activeCheckBox($this, $attr, $this->htmlOptions($attr));
114: break;
115: case 'user':
116: echo CHtml::activeTextField($this, $attr, $this->htmlOptions($attr));
117: break;
118: case 'password':
119: echo X2Html::x2ActivePasswordField ($this, $attr, $this->htmlOptions ($attr), true);
120: break;
121: }
122: }
123:
124: 125: 126:
127: public function renderInputs() {
128: $this->password = null;
129: echo CHtml::activeLabel ($this, 'senderName');
130: $this->renderInput ('senderName');
131: echo CHtml::activeLabel ($this, 'email');
132: $this->renderInput ('email');
133: echo CHtml::activeLabel ($this, 'server');
134: $this->renderInput ('server');
135: echo CHtml::activeLabel ($this, 'port');
136: $this->renderInput ('port');
137: echo CHtml::activeLabel ($this, 'security');
138: $this->renderInput ('security');
139: echo CHtml::activeLabel ($this, 'user');
140: $this->renderInput ('user');
141: echo CHtml::activeLabel ($this, 'password');
142: $this->renderInput ('password');
143: echo '<br/>';
144: echo '<br/>';
145: echo CHtml::tag ('h3', array (), Yii::t('app', 'IMAP Configuration'));
146: echo '<hr/>';
147: echo CHtml::activeLabel($this, 'imapPort');
148: $this->renderInput ('imapPort');
149: echo CHtml::activeLabel($this, 'imapSecurity');
150: $this->renderInput ('imapSecurity');
151: echo CHtml::activeLabel($this, 'imapNoValidate');
152: $this->renderInput ('imapNoValidate');
153: echo CHtml::activeLabel($this, 'imapServer');
154: $this->renderInput ('imapServer');
155: echo CHtml::errorSummary($this);
156: }
157:
158: 159: 160: 161: 162:
163: public function emailUser($attribute,$params=array()) {
164: if(empty($this->$attribute) && !empty($this->email))
165: $this->$attribute = $this->email;
166: }
167:
168: public function rules() {
169: return array(
170: array('port','numerical','integerOnly'=>1,'min'=>1),
171: array('email','email'),
172: array('user','emailUser'),
173: array('server,user,email','length','min'=>1,'max'=>500,'allowEmpty'=>0),
174: array('password','required'),
175: array('senderName,server,port,security,user,email,password,imapPort,imapServer,imapSecurity,imapNoValidate','safe'),
176: );
177: }
178:
179: }
180:
181: ?>
182: