/**
	 * Returns the JavaScript needed for performing client-side validation.
	 * @param CModel $object the data object being validated
	 * @param string $attribute the name of the attribute to be validated.
	 * @return string the client-side validation script.
	 * @see CActiveForm::enableClientValidation
	 * @since 1.1.7
	 */
	public function clientValidateAttribute($object,$attribute)
	{
		if($this->pattern===null)
			throw new CException(Yii::t('yii','The "pattern" property must be specified with a valid regular expression.'));

		$message=$this->message!==null ? $this->message : Yii::t('yii','{attribute} is invalid.');
		$message=strtr($message, array(
			'{attribute}'=>$object->getAttributeLabel($attribute),
		));

		$pattern=$this->pattern;
		$pattern=preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern);
		$delim=substr($pattern, 0, 1);
		$endpos=strrpos($pattern, $delim, 1);
		$flag=substr($pattern, $endpos + 1);
		if ($delim!=='/')
			$pattern='/' . str_replace('/', '\\/', substr($pattern, 1, $endpos - 1)) . '/';
		else
			$pattern = substr($pattern, 0, $endpos + 1);
		if (!empty($flag))
			$pattern .= preg_replace('/[^igm]/', '', $flag);

		return "
if(".($this->allowEmpty ? "$.trim(value)!='' && " : '').($this->not ? '' : '!')."value.match($pattern)) {
	messages.push(".CJSON::encode($message).");
}
";
	}
	/**
	 * Returns the JavaScript needed for performing client-side validation.
	 * @param CModel $object the data object being validated
	 * @param string $attribute the name of the attribute to be validated.
	 * @return string the client-side validation script.
	 * @see CActiveForm::enableClientValidation
	 * @since 1.1.7
	 */
	public function clientValidateAttribute($object,$attribute)
	{
		$message=$this->message;
		if($this->requiredValue!==null)
		{
			if($message===null)
				$message=Yii::t('yii','{attribute} must be {value}.');
			$message=strtr($message, array(
				'{value}'=>$this->requiredValue,
				'{attribute}'=>$object->getAttributeLabel($attribute),
			));
			return "
if(value!=" . CJSON::encode($this->requiredValue) . ") {
	messages.push(".CJSON::encode($message).");
}
";
		}
		else
		{
			if($message===null)
				$message=Yii::t('yii','{attribute} cannot be blank.');
			$message=strtr($message, array(
				'{attribute}'=>$object->getAttributeLabel($attribute),
			));
			return "
if($.trim(value)=='') {
	messages.push(".CJSON::encode($message).");
}
";
		}
	}
 /**
  * Validates a single attribute.
  * 
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->isEmpty($value)) {
         if ($this->allowEmpty) {
             return;
         } else {
             $arrValidators = $object->getValidators($attribute);
             foreach ($arrValidators as $objValidator) {
                 // do not duplicate error message if attribute is already required
                 if ($objValidator instanceof CRequiredValidator) {
                     return;
                 }
             }
             $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} cannot be blank.');
             $this->addError($object, $attribute, $message);
         }
     } else {
         $return = $this->validateIBAN($value);
         if (true !== $return) {
             $message = $this->message !== null ? $this->message : $this->getErrorMessage($return, $value);
             $this->addError($object, $attribute, $message);
         }
     }
 }
 public function renderInput(CModel $model, $attribute, array $htmlOptions = array())
 {
     $action = new Actions();
     $action->setAttributes($model->getAttributes(), false);
     $defaultOptions = array('id' => $this->resolveId($attribute));
     $htmlOptions = X2Html::mergeHtmlOptions($defaultOptions, $htmlOptions);
     return preg_replace('/Actions(\\[[^\\]]*\\])/', get_class($this->formModel) . '$1', $action->renderInput($attribute, $htmlOptions));
 }
 /**
  * Returns input container class for any given attribute, depending on validation conditions.
  * @param CModel $model the data model
  * @param string $attribute the attribute name
  */
 public function fieldClass($model, $attribute)
 {
     $class = 'control-group';
     if ($model->getError($attribute)) {
         $class .= ' error';
     }
     return $class;
 }
Exemple #6
0
 /**
  * get error info from model
  * 
  * @param CModel $model
  * @return string
  * @see CModel
  */
 public static function errorModelSummery($model, $attribute = null)
 {
     if (is_null($attribute)) {
         return self::errorSummery($model->getErrors());
     } else {
         $aryError = $model->getError($attribute, false);
         return empty($aryError) ? '' : self::errorSummery(array($aryError));
     }
 }
 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } else {
         $message = Yii::t('validator', 'This value must be repeated exactly.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
 }
 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } else {
         $message = Yii::t('validator', 'This is not a valid phone number.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
 }
Exemple #9
0
 /**
  * Validates the attribute of the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     if ($this->setOnEmpty && !$this->isEmpty($object->{$attribute})) {
         return;
     }
     if (!$object->hasAttribute($this->translitAttribute)) {
         throw new CException(Yii::t('yiiext', 'Active record "{class}" is trying to select an invalid column "{column}". Note, the column must exist in the table or be an expression with alias.', array('{class}' => get_class($object), '{column}' => $this->translitAttribute)));
     }
     $object->{$attribute} = self::latin($object->getAttribute($this->translitAttribute));
 }
 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     if ($this->compareValue !== null) {
         $compareTo = $compareValue = $this->compareValue;
     } else {
         $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute;
         $compareValue = $object->{$compareAttribute};
         $compareTo = $object->getAttributeLabel($compareAttribute);
     }
     switch ($this->operator) {
         case '=':
         case '==':
             if ($this->strict && $value !== $compareValue || !$this->strict && $value != $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be repeated exactly.');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo));
             }
             break;
         case '!=':
             if ($this->strict && $value === $compareValue || !$this->strict && $value == $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '>':
             if ($value <= $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '>=':
             if ($value < $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '<':
             if ($value >= $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be less than "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '<=':
             if ($value > $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         default:
             throw new CException(Yii::t('yii', 'Invalid operator "{operator}".', array('{operator}' => $this->operator)));
     }
 }
 protected function validateValue(CModel $object, $value, $attribute)
 {
     // exception added for case where validator is added to AmorphousModel
     if (!$object instanceof X2Model) {
         return;
     }
     $field = $object->getField($attribute);
     $linkType = $field->linkType;
     $model = X2Model::model($linkType);
     if (!$model || !$model->findByPk($value)) {
         $this->error(Yii::t('admin', 'Invalid {fieldName}', array('{fieldName}' => $field->attributeLabel)));
         return false;
     }
 }
 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } elseif (isset($this->min, $this->max)) {
         $message = Yii::t('validator', 'You must select between {min} and {max} choices.');
     } elseif (isset($this->min)) {
         $message = Yii::t('validator', 'You must select at least {min} choices.');
     } elseif (isset($this->max)) {
         $message = Yii::t('validator', 'You cannot have more than {max} choices selected.');
     } else {
         $message = Yii::t('validator', 'Invalid amount of choices selected.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{min}' => $this->min, '{max}' => $this->max));
 }
 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } elseif (isset($this->min, $this->max)) {
         $message = Yii::t('validator', 'The value must gave between {min} and {max} characters.');
     } elseif (isset($this->min)) {
         $message = Yii::t('validator', 'The value is too short (minimum is {min} characters).');
     } elseif (isset($this->max)) {
         $message = Yii::t('validator', 'The value is too long (maximum is {max} characters).');
     } else {
         $message = Yii::t('validator', 'The value is invalid.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{min}' => $this->min, '{max}' => $this->max));
 }
Exemple #14
0
 public function beginControlGroup(CModel $model, $attributes, $htmlOptions = array())
 {
     if (!isset($htmlOptions['class'])) {
         $htmlOptions['class'] = 'control-group';
     }
     if (!is_array($attributes)) {
         $attributes = explode(',', str_replace(' ', '', $attributes));
     }
     foreach ($attributes as $attr) {
         if ($model->hasErrors($attr)) {
             $htmlOptions['class'] .= ' error';
         }
     }
     return CHtml::tag('div', $htmlOptions, false, false);
 }
Exemple #15
0
 public function __construct()
 {
     parent::__construct();
     # CONFIGURE TABLE WITH PREFIX
     //$db_config = Config::get_database();
     //$prefix = $db_config['prefix'] == '' ? '' : $db_config['prefix'];
     $this->table = 'photonews_detail';
     //$prefix . "_photonews_detail";
     $this->news_table = "news";
     //"news_" . date('Y'); //$prefix . "_news_" . date('Y');
     $this->news_rubric = 'news_rubrics';
     //$prefix ."_news_rubrics";
     $this->taq_news = 'tag_news';
     //$prefix ."_tag_news";
     $this->keyword = 'news_keywords';
     //$prefix ."_news_keywords";
     $this->user_table = 'users';
     //$prefix ."_users";
     $this->photo_table = 'photo';
     //$prefix ."_photo";
     $this->photonews_detail = 'photonews_detail';
     //$prefix ."_photonews_detail";
     # END CONFIGURE
     mysql_query("SET time_zone='+07:00';");
 }
 public function Action_index()
 {
     // 检测用户是否登录
     if (AdminController::isLogin()) {
         return CResponse::getInstance()->redirect(array('c' => 'admin', 'a' => 'index'));
     }
     if ($_POST) {
         // 获取参数
         $username = $this->Args('username', 'string');
         $password = $this->Args('password', 'string');
         // 检查登陆
         $userCheckStatus = CModel::factory('adminUserModel')->userCheck($username, $password);
         // 检查失败
         if (false == $userCheckStatus['status']) {
             // 登录失败
             $this->assign('userLoginStatus', $userCheckStatus);
         } else {
             // 允许登陆
             $userLoginStatus = CModel::factory('adminUserModel')->userLogin($userCheckStatus);
             if ($userLoginStatus['status'] == false) {
                 $this->assign('userLoginStatus', $userLoginStatus);
             } else {
                 // 登录成功
                 CResponse::getInstance()->redirect($userLoginStatus['urlPram']);
             }
         }
     }
     $this->display();
 }
 protected function setupBelongsTo($relationDetails)
 {
     // get and verify the relation foreign key field
     if (isset($relationDetails[2]) && $relationDetails[2]) {
         $this->_modelAttribute = $relationDetails[2];
     } else {
         throw new CException(Yii::t('yii', 'The {relation} relation in {model} does not specify a foreign key field for the {class} widget.', array('{relation}' => $this->relation, '{model}' => get_class($this->model), '{class}' => get_class($this))));
     }
     // see if empty is allowed
     if ($this->model->isAttributeRequired($this->_modelAttribute)) {
         $this->allowEmpty = false;
     }
     // set up the name and ID for the widget
     $this->resolveWidgetName();
     // sets the right name for the multi widget
     $this->resolveWidgetId();
     // sets the right id for the multi widget
     // attributes to pass to widget
     $widgetAttrs = array();
     // set default values based on data type
     if ($this->widgetDataFormat == self::DATA_FORMAT_TEXT) {
         $widgetAttrs['htmlOptions'] = array('value' => $this->getRelatedData()->{$this->relationDisplayField});
     } else {
         // self::DATA_FORMAT_ARRAY
         $widgetAttrs['value'] = $this->getAllRelatedListData();
     }
     // set up variables for the widget
     $widgetAttrs['model'] = $this->model;
     $widgetAttrs['attribute'] = $this->_modelAttribute;
     // merge the widget properties
     $this->widgetProperties = CMap::mergeArray($this->widgetProperties, $widgetAttrs);
 }
 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  * @return string the client-side validation script.
  * @see CActiveForm::enableClientValidation
  * @since 1.1.7
  */
 public function clientValidateAttribute($object, $attribute)
 {
     if (!is_array($this->range)) {
         throw new CException(Yii::t('yii', 'The "range" property must be specified with a list of values.'));
     }
     if (($message = $this->message) === null) {
         $message = $this->not ? Yii::t('yii', '{attribute} is in the list.') : Yii::t('yii', '{attribute} is not in the list.');
     }
     $message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
     $range = array();
     foreach ($this->range as $value) {
         $range[] = (string) $value;
     }
     $range = CJSON::encode($range);
     return "\nif(" . ($this->allowEmpty ? "\$.trim(value)!='' && " : '') . ($this->not ? "\$.inArray(value, {$range})>=0" : "\$.inArray(value, {$range})<0") . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
 }
Exemple #19
0
 public function runMultilingual()
 {
     // check if action is configured
     $this->checkConditions(array('model', 'deleteCriteria', 'deleteParams', 'nonAjaxRedirect'));
     $models = $this->model->findAll($this->deleteCriteria, $this->deleteParams);
     if (!empty($models)) {
         foreach ($models as $model) {
             $model->delete();
         }
     }
     if (isAjax()) {
         $this->getController()->successfulAjaxResponse();
     } else {
         $this->getController()->redirect($this->nonAjaxRedirect);
     }
 }
Exemple #20
0
 public function __unset($name)
 {
     if (in_array($name, $this->attributeNames())) {
         unset($this->_attributes[$name]);
     } else {
         parent::__unset($name);
     }
 }
Exemple #21
0
 /**
  * For multilingual site mode
  */
 public function runMultilingual()
 {
     // check if action is configured
     $this->checkConditions(array('model', 'updateRecordId', 'tableModelClassName'));
     /** @var $controller BackendController */
     $controller = $this->getController();
     $this->model->setTableModelClassName($this->tableModelClassName);
     $this->model->loadData($this->updateRecordId);
     if ($this->redirectUrl) {
         $controller->setRedirectUrl($this->redirectUrl);
     }
     $controller->setModel($this->model);
     if (isPostOrAjaxRequest()) {
         $controller->processUpdate();
     }
     $controller->render($this->view, array('model' => $controller->getModel(), 'pageTitle' => $this->pageTitle, 'formId' => $this->formId, 'formView' => $this->formView, 'formAction' => $this->formAction, 'imageUploadHandlerUrl' => $this->imageUploadHandlerUrl, 'coverPreviewWidth' => $this->coverPreviewWidth, 'coverPreviewHeight' => $this->coverPreviewHeight));
 }
 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  * @return string the client-side validation script.
  * @see CActiveForm::enableClientValidation
  * @since 1.1.7
  */
 public function clientValidateAttribute($object, $attribute)
 {
     $message = $this->message;
     if ($this->requiredValue !== null) {
         if ($message === null) {
             $message = Yii::t('yii', '{attribute} phải là {value}.');
         }
         $message = strtr($message, array('{value}' => $this->requiredValue, '{attribute}' => $object->getAttributeLabel($attribute)));
         return "\nif(value!=" . CJSON::encode($this->requiredValue) . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
     } else {
         if ($message === null) {
             $message = Yii::t('yii', '{attribute} không thể trống.');
         }
         $message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
         return "\nif(jQuery.trim(value)=='') {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
     }
 }
Exemple #23
0
 /**
  * For multilingual site mode
  */
 public function runMultilingual()
 {
     // check if action is configured
     $this->checkConditions(array('model', 'tableModelClassName'));
     /** @var $controller BackendController */
     $controller = $this->getController();
     if ($this->redirectUrl) {
         $controller->setRedirectUrl($this->redirectUrl);
     }
     $controller->setModel($this->model);
     if (isPostOrAjaxRequest()) {
         // in case of multilingual site we will use form model to gather data and save to data storage (DB)
         $this->model->setTableModelClassName($this->tableModelClassName);
         $controller->processCreate();
     }
     $controller->render($this->view, array('model' => $controller->getModel(), 'pageTitle' => $this->pageTitle, 'formId' => $this->formId, 'formView' => $this->formView, 'formAction' => $this->formAction, 'innerLinks' => $this->innerLinks, 'imageUploadHandlerUrl' => $this->imageUploadHandlerUrl, 'coverPreviewWidth' => $this->coverPreviewWidth, 'coverPreviewHeight' => $this->coverPreviewHeight));
 }
 public function __set($name, $value)
 {
     if (array_key_exists($name, $this->data)) {
         $this->data[$name] = $value;
     } else {
         parent::__set($name, $value);
     }
 }
Exemple #25
0
 /**
  * 管理员登录
  */
 protected function login()
 {
     $username = $this->input->post('username', true);
     $password = $this->input->post('password', true);
     $this->_user->username = trim($username);
     $this->_user->password = $password;
     $modLogin = CModel::make('admin/loginman_model', 'loginman_model');
     $boolean = $modLogin->authenticate($this->_user);
     return $boolean === true && $modLogin->save();
 }
 /**
  * Validates a single attribute.
  *
  * @param CModel $object    the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  */
 protected function validateAttribute($object, $attribute)
 {
     if (!$object->isAttributeDirty($attribute)) {
         return;
     }
     if ($this->model === null) {
         //currently unsupported
         return;
     }
     if ($this->message === null) {
         $this->message = '{attribute} can not be edited because it is already in use';
     }
     if ($this->foreignKey === null) {
         $this->foreignKey = $object->tableName() . '_id';
     }
     if ($this->validateContainedInModel($object->id)) {
         $this->addError($object, $attribute, $this->message);
     }
 }
 /**
  * Get elements from model.
  * @static
  * @param CModel $model
  * @return array
  */
 public static function getModelElements($model)
 {
     $elements = array();
     $scenario = $model->getScenario();
     foreach ($model->getFormElements() as $name => $element) {
         $on = array();
         if (isset($element['on']) && is_array($element['on'])) {
             $on = $element['on'];
         } else {
             if (isset($element['on'])) {
                 $on = preg_split('/[\\s,]+/', $element['on'], -1, PREG_SPLIT_NO_EMPTY);
             }
         }
         if (empty($on) || in_array($scenario, $on)) {
             unset($element['on']);
             $elements[$name] = $element;
         }
     }
     return $elements;
 }
 /**
  * 工厂方法
  */
 public static function factory($modelName = null)
 {
     if (empty($modelName)) {
         return CModel::getInstance();
     }
     if (!isset(self::$modelList[$modelName])) {
         self::$modelList[$modelName] = new $modelName();
         return self::$modelList[$modelName];
     }
     return self::$modelList[$modelName];
 }
 public function setAttributes($values, $safeOnly = false)
 {
     foreach ($values as $k => $v) {
         if (!in_array($k, $this->attributeNames())) {
             // this exception is thrown when an invalid attribute is specified
             // in the EYuiForm widget array fielddefs or pages.
             throw new Exception("invalid attribute name: " . $k . ", value=" . $v);
         }
     }
     parent::setAttributes($values, false);
 }
Exemple #30
0
 public function __construct()
 {
     parent::__construct();
     # CONFIGURE TABLE WITH PREFIX
     //$db_config = Config::get_database();
     //$prefix = $db_config['prefix'] == '' ? '' : $db_config['prefix'];
     $this->table = 'photo';
     //$prefix . "_photo";
     # END CONFIGURE
     mysql_query("SET time_zone='+07:00';");
 }