Sure would be awsome if you can help out
User Registry Model
<?php
/**
* This is the model class for table "{{user_registry}}".
*
* The followings are the available columns in table '{{user_registry}}':
* @property integer $id_user_registry
* @property string $firstname
* @property string $lastname
* @property string $company
* @property integer $postcode
* @property string $city
* @property string $state
* @property string $country
* @property string $addressstreet
* @property string $email
* @property string $email2
* @property integer $tel
* @property integer $fax
* @property integer $cel
* @property string $notes
* @property string $creation_date
* @property integer $id_user
* @property integer $company_role
* @property integer $group
*/
class UserRegistry extends CActiveRecord
{
public $user_name;
public $password;
public $role;
public $confirmpassword;
public $groups;
const ROLE_PRI = 4;
const ROLE_MEM = 5;
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return UserRegistry the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{user_registry}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('postcode, tel, fax, associate, role, cel, id_user, group', 'numerical', 'integerOnly'=>true),
array('firstname, lastname, company, city, state, country, user_name, password, confirmpassword', 'length', 'max'=>45),
array('addressstreet, email, email2, company_role', 'length', 'max'=>255),
array('notes', 'length', 'max'=>455),
array('creation_date, groups', 'safe'),
array('email','email'),
array('email2','email'),
array('email', 'unique'),
array('email2', 'unique'),
array('creation_date','default',
'value'=>new CDbExpression('NOW()'),
'setOnEmpty'=>false,
'on'=>'insert'),
array('creation_date','default',
'value'=>new CDbExpression('NOW()'),
'setOnEmpty'=>false,
'on'=>'update'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_user_registry, groups, firstname, lastname, company, postcode, city, state, country, addressstreet, email, email2, tel, fax, cel, notes, creation_date, id_user, company_role, group', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'groupsB' => array(self::MANY_MANY, 'Group', 'tbl_bridge_group(id_user_registry, id_group)'),
'idUser' => array(self::BELONGS_TO, 'User', 'id_user'),
// 'bridgeGroups' => array(self::HAS_MANY, 'BridgeGroup', 'id_user_registry'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id_user_registry' => __('Id User Registry'),
'firstname' => __('First Name'),
'lastname' => __('Last Name'),
'company' => __('Company'),
'postcode' => __('Postcode'),
'city' => __('City'),
'state' => __('State'),
'country' => __('Country'),
'addressstreet' => __('Street Address'),
'email' => __('Email'),
'email2' => __('Second Email'),
'tel' => __('Tel'),
'fax' => __('Fax'),
'cel' => __('Cel'),
'notes' => __('Notes'),
'creation_date' => __('Creation Date'),
'id_user' => __('User Login'),
'company_role' => __('Company Role'),
'group' => __('Group'),
'user_name'=>'User Name',
'password'=>'Password',
'groups'=>__('Groups'),
'role'=>__('Privileges'),
'associate'=>__('Alternate')
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id_user_registry',$this->id_user_registry);
$criteria->compare('firstname',$this->firstname,true);
$criteria->compare('lastname',$this->lastname,true);
$criteria->compare('company',$this->company,true);
$criteria->compare('postcode',$this->postcode);
$criteria->compare('city',$this->city,true);
$criteria->compare('state',$this->state,true);
$criteria->compare('country',$this->country,true);
$criteria->compare('addressstreet',$this->addressstreet,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('email2',$this->email2,true);
$criteria->compare('tel',$this->tel);
$criteria->compare('fax',$this->fax);
$criteria->compare('cel',$this->cel);
$criteria->compare('notes',$this->notes,true);
$criteria->compare('creation_date',$this->creation_date,true);
$criteria->compare('id_user',$this->id_user);
$criteria->compare('company_role',$this->company_role);
$criteria->compare('group',$this->group);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public function getRoleOptions(){
return array(
self::ROLE_PRI => Lookup::item('role', self::ROLE_PRI),
self::ROLE_MEM => Lookup::item('role', self::ROLE_MEM)
);
}
}
User Model
<?php
/**
* This is the model class for table "tbl_user".
*
* The followings are the available columns in table 'tbl_user':
* @property integer $id_user
* @property integer $role
* @property string $user_name
* @property string $password
* @property string $last_login_date
* @property string $email
* @property string $tel
*
* The followings are the available model relations:
* @property TblEventLog[] $tblEventLogs
* @property TblLicensee[] $tblLicensees
*/
class User extends CActiveRecord {
public $confirmPassword;
const ROLE_ADMINISTRATOR = 0;
const ROLE_CA = 1;
const ROLE_GI = 2;
const ROLE_USR = 3;
const ROLE_PRI = 4;
const ROLE_MEM = 5;
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return User the static model class
*/
public static function model($className = __CLASS__) {
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName() {
return '{{user}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('role, user_name, password, confirmPassword', 'required'),
array('role, id_user_registry', 'numerical', 'integerOnly' => true),
array('user_name, password, email, tel', 'length', 'max' => 45),
array('last_login_date, full_name', 'safe'),
array('user_name', 'unique'),
array('user_name', 'length', 'min' => 3),
array('user_name', 'length', 'max' => 45),
array('email', 'email'),
array('confirmPassword', 'compare', 'compareAttribute' => 'password'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_user, role, user_name, password, last_login_date, email, tel', 'safe', 'on' => 'search'),
);
}
/**
* @return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'tblProjects' => array(self::HAS_MANY, 'TblProject', 'id_user'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'id_user' => 'Id User',
'role' => 'Role',
'user_name' => 'User Name',
'password' => 'Password',
'last_login_date' => 'Last Login Date',
'email' => 'Email',
'tel' => 'Tel',
'confirmPassword' => 'Confirm Password',
'full_name' => 'Full Name',
'id_user_registry' => 'id user registry',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id_user', $this->id_user);
$criteria->compare('role', $this->role);
$criteria->compare('user_name', $this->user_name, true);
$criteria->compare('last_login_date', $this->last_login_date, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('tel', $this->tel, true);
$criteria->compare('full_name', $this->full_name, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pagesize' => 100,),
));
}
public function validatePassword($password) {
return $this->hashPassword($password) == $this->password;
}
public function hashPassword($password) {
return md5($password);
}
protected function beforeSave() {
if (parent::beforeSave()) {
$this->password = $this->hashPassword($this->password);
return true;
} else {
return false;
}
}
public function updateLoginDate() {
$this->last_login_date = date('Y-m-d H:i:s');
$this->save(false, array('last_login_date'));
}
public function getRoleOptions() {
return array(self::ROLE_ADMINISTRATOR => Lookup::item('role', self::ROLE_ADMINISTRATOR),
self::ROLE_CA => Lookup::item('role', self::ROLE_CA),
self::ROLE_GI => Lookup::item('role', self::ROLE_GI),
self::ROLE_USR => Lookup::item('role', self::ROLE_USR),
self::ROLE_PRI => Lookup::item('role', self::ROLE_PRI)
);
}
}