<?php
/**
 * IMPORTANT NOTE
 * The code of this system is closed and a private proprietary of Flex Solutions.
 * A written authorization/license from Flex Solutions is required before using or modifying this code.
 * Email: sales@flexsolution.biz, Phone: +962795342585, Website: http://www.flexsolutions.biz
 */
 
/**
 * This is the model class for table "setting".
 *
 * The followings are the available columns in table 'setting':
 * @property integer $id
 * @property string $name
 * @property string $value
 *  *
 * @author Amaney
 * @package application.models
 */
class Setting extends TidansActiveRecord {

    public $first_ldap_server,
    $second_ldap_server, $first_authentication_ldap_server, $second_authentication_ldap_server,
    $ldap_port,
    $base_dn,
    $backup_file_path,
    $max_document_size,
    $tid_daily_fine,
    $grace_period,
    $documents_path,
    $vehicle_type_of_asset,
    $radio_active_type_of_asset,
    $dashboard_update,
    $under_transfer_renewal_stage;

    /**
     * @return string the associated database table name
     */
    public function tableName() {
	return 'setting';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
	return array(
	    array('documents_path,radio_active_type_of_asset,vehicle_type_of_asset,max_document_size,grace_period', 'required', 'on' => 'settings'),
	    array('dashboard_update,max_document_size,ldap_port,grace_period', 'numerical', 'integerOnly' => true),
	    array('tid_daily_fine', 'numerical'),
	     array('update_process_date,value', 'safe', 'on' => 'update'),
	    // array('allowed_document_types', 'allowedDocumentTypesValidate'),
	    //  array('', 'match','pattern'=>'/^[\p{L}\p{N},]+$/'),
	    // array('deleted_documents_path,expired_documents_path,ldap_photos_directory,default_time_zone,first_ldap_server, second_ldap_server, ldap_port ,base_dn, backup_file_path, max_document_size, allowed_document_types, max_activation_period_for_badges, first_authentication_ldap_server,second_authentication_ldap_server,person_photos_path,printing_mode,person_documents_path,allow_inactive_badges', 'required', "on" => "settings"),
	    array('under_transfer_renewal_stage,dashboard_update,radio_active_type_of_asset,vehicle_type_of_asset,documents_path,id, name, value, first_ldap_server, second_ldap_server, ldap_port ,base_dn, backup_file_path, max_document_size ,first_authentication_ldap_server, second_authentication_ldap_server', 'safe'),
	);
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
	return array(
	    'first_ldap_server' => Yii::t('default', 'First LDAP Server'),
	    'second_ldap_server' => Yii::t('default', 'Second LDAP Server'),
	    'first_authentication_ldap_server' => Yii::t('default', 'First Authentication Server'),
	    'second_authentication_ldap_server' => Yii::t('default', 'Second Authentication Server'),
	    'ldap_port' => Yii::t('default', 'LDAP Port'),
	    'base_dn' => Yii::t('default', 'Base DN'),
	    'backup_file_path' => Yii::t('default', 'Backup File Path'),
	    'max_document_size' => Yii::t('default', 'Max Document Size'),
	    'grace_period' => Yii::t('default', 'Grace Period'),
	    'tid_daily_fine' => Yii::t('default', 'TID Daily Fine'),
	    'documents_path' => Yii::t('default', "Documents Path"),
	    'vehicle_type_of_asset' => Yii::t('default', 'Vehicle Type of Asset'),
	    'radio_active_type_of_asset' => Yii::t('default', 'Radio Active Type of Asset'),
	    'name' => 'Name',
	    'value' => 'Value',
	    'dashboard_update' => Yii::t('default', 'Dashboard Update Frequency'),
	    'under_transfer_renewal_stage' => Yii::t('default', 'Under Transfer of Privilege Process Stage'),
	    'update_process_last_run_date'=>'',
	);
    }

    public function attributeLabelsPopover() {
	return array(
	    'first_ldap_server' => Yii::t('default', 'tooltip_first_ldap_server'),
	    'second_ldap_server' => Yii::t('default', 'tooltip_second_ldap_server'),
	    'first_authentication_ldap_server' => Yii::t('default', 'tooltip_first_authentication_ldap_server'),
	    'second_authentication_ldap_server' => Yii::t('default', 'tooltip_second_authentication_ldap_server'),
	    'ldap_port' => Yii::t('default', 'tooltip_ldap_port'),
	    'base_dn' => Yii::t('default', 'tooltip_base_dn'),
	    'backup_file_path' => Yii::t('default', 'tooltip__backup_file_path'),
	    'max_document_size' => Yii::t('default', 'tooltip_max_document_size'),
	);
    }

    /**
     * @return array of all system settings
     */
    public static function getSettingsArray() {
	$settings_array = array();
	foreach (Setting::model()->findAll() as $setting) {
	    $settings_array[$setting->name] = $setting->value;
	}
	return $settings_array;
    }

    /**
     * @return String the max document size
     */
    public static function getDocumentSizeLimit() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['max_document_size'];
    }

    /**
     * @return String the daily fine
     */
    public static function getFine() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['tid_daily_fine'];
    }

    /**
     * @return String the daily fine
     */
    public static function getdashboardUpdatePeriod() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['dashboard_update'];
    }

    /**
     * @return String the grace period
     */
    public static function getGracePeriod() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['grace_period'];
    }

    /**
     * @return String the vehicle type of asset
     */
    public static function getVehicleTypeOfAsset() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['vehicle_type_of_asset'];
    }

    /**
     * @return String the radio active type of asset
     */
    public static function getRadioActiveTypeOfAsset() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['radio_active_type_of_asset'];
    }


     /**
     * @return String the under transfer of privilege renewal stage
     */
    public static function getUnderTransferOfPrivilege() {
	$settings_array = Setting::getSettingsArray();
	return $settings_array['under_transfer_renewal_stage'];
    }

    /**
     * @return String the path of person documents
     */
    public static function getDocumentsPath() {
	$settings_array = Setting::getSettingsArray();
	$document_path = $settings_array['documents_path'];
	$slash = ( substr($document_path, -1) == "\\") ? "" : "\\";
	return $document_path . $slash;
    }

   
     /**
     * @return String the update process date
     */
    public static function getUpdateProcessDate() {
        $settings_array = Setting::getSettingsArray();
        return $settings_array['update_process_last_run_date'];
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return Setting the static model class
     */
    public static function model($className=__CLASS__) {
	return parent::model($className);
    }

    protected function beforeValidate() {
	return true;
    }

}
