Your IP : 216.73.216.79


Current Path : /var/www/html/ekursusv2/frontend/runtime/frontendpage/
Upload File :
Current File : /var/www/html/ekursusv2/frontend/runtime/frontendpage/121_1741190774047815900-content-341.php

<?php 
/*** CONTENT_ID-341***/
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use backend\modules\fruserdynav2\models\FrontendUser;
use backend\modules\documentAutomation\models\Template;
use yii\helpers\ArrayHelper;
use backend\modules\refdynawebv2\models\Ref;

$id = Yii::$app->getRequest()->getQueryParam('id');

$model = FrontendUser::findOne(['uuid'=>$id]);
if(!empty($model)){
    
    $model->scenario = 'registration';
    
    if(empty($model->phone_country_code)){
        $modelref = Ref::find()->where(['=','cat','COUNTRY'])->andwhere(['=','code',$model->country])->one();
        if(!empty($modelref)){
            $modelphone = Ref::find()->where(['=','cat','PHONECODE'])->andwhere(['=','param1',$modelref->id])->one();
            if(!empty($modelphone)){
                $model->phone_country_code = $modelphone->code;
            }
        }
    }
    
    if($model->status == 0){
        
        if ($model->load(Yii::$app->request->post())) {
            
            $model->password_hash = Yii::$app->security->generatePasswordHash($model->password);
            $model->updated_at = date("Y-m-d H:i:s");
            $model->updated_by = Yii::$app->user->identity->id;
            $model->updated_user_type = 'frontend_user';
            $model->status = 1;
            
            $modelTemplate = Template::findOne(['code' => 'liaision-registration']);
            if (!empty($modelTemplate)) {
                
                //$to_mail = $model->email;
                $subject_mail = $modelTemplate->title;
                $content_mail = str_replace("#LIAISION_NAME#", $model->fullname, $modelTemplate->content);
                $content_mail = str_replace("#LIAISION_EMAIL#", $model->email, $content_mail);
                $content_mail = str_replace("#LIASION_COUNTRY#", \backend\modules\refdynawebv2\models\Ref::getDesc('COUNTRY', $model->country, 'descr_en'), $content_mail);
                
                $queryAdmin = new \yii\db\Query(); 
                $queryAdmin->select(['dmg_user.*'])
                    ->from('dmg_user')
                    ->innerJoin('auth_assignment','dmg_user.id=auth_assignment.user_id')
                    ->where(['IN','auth_assignment.item_name',['super-admin']])
                    ->andwhere(['=','dmg_user.status','10']);
                $modelAdmin = $queryAdmin->all();
                if(!empty($modelAdmin)){
                    foreach($modelAdmin as $rowAdmin){
                        $to_mail = $rowAdmin['email'];
                        if (!empty($to_mail))
                            Yii::$app->emailModule->sendemail($to_mail, $subject_mail, $content_mail);
                    }
                }
            }
            
            if ($model->save()) {
                echo "<script>
                    Swal.fire({
                      icon: 'success',
                      title: 'Success',
                      text: 'You can now log in using your email and password',
                    }).then((result) => {
                      window.location.href = '".$baseUrl."/portal-main/login';
                    });
                </script>";
            }
            
        }
        
        $form = ActiveForm::begin();
        echo '<style>.form-group{margin-bottom:1em;}</style>
            <div class="text-center mt-2">
                <h5 class="text-title">First Time Login</h5>
                <p class="text-muted">Enter all required information below And click the register button.</p>
            </div>';
            echo $form->field($model, 'fullname')->textInput(['class'=>'form-control','oninput'=>'this.value = this.value.toUpperCase()']);
            
            echo '<div class="row">';
            echo '<div class="col-sm-3">'.$form->field($model, 'phone_country_code')->dropdownList(
                            ArrayHelper::map(\backend\modules\refdynawebv2\models\Ref::find()
                                            ->where(['cat' => 'PHONECODE'])
                                            ->orderBy(['descr' => SORT_ASC])->all(), 'code', 'descr'), [
                         'class' => 'select2']).'</div>';
            echo '<div class="col-sm-9">'.$form->field($model, 'mobile_no')->textInput(['class'=>'form-control','autocomplete'=>'new-password']).'</div>';
            echo '</div>';
            
            echo '<div id="wrapper_password" style="position:relative;">';
            echo $form->field($model, 'password')->passwordInput(['class'=>'form-control','autocomplete'=>'new-password']);
            echo '<span id="toggle_password" class="toggle-password" onclick="togglepassword(\'password\')"><i class="fa fa-eye-slash" aria-hidden="true"></i></span>';
            echo '</div>';
            
            echo '<div id="wrapper_repeat_password" style="position:relative;">';
            echo $form->field($model, 'repeat_password')->passwordInput(['maxlength' => true,'autocomplete'=>'new-password']);
            echo '<span id="toggle_repeat_password" class="toggle-password"  onclick="togglepassword(\'repeat_password\')"><i class="fa fa-eye-slash" aria-hidden="true"></i></span>';
            echo '</div>';
            
            
            
            echo ' <div class="mt-5 text-center">
            <button class="btn btn-primary w-sm waves-effect waves-light" type="submit">Register</button>
        </div>';
        ActiveForm::end();
    
    } else {
        echo 'You have completed your registration. Please click <a href="/portal-main/login">here</a> to log in.';
    }
} else {
    echo 'Sorry, your information was not found. Please contact the secretariat for assistance.';
}

echo "
<style>
    .toggle-password{
        cursor : pointer;
        position : absolute;
        right : 1em;
        top : 55%;
    }
</style>
<script>
    function togglepassword(passwordtype){
        event.preventDefault();
        if($('#wrapper_'+passwordtype+' input').attr('type') == 'text'){
            $('#wrapper_'+passwordtype+' input').attr('type', 'password');
            $('#wrapper_'+passwordtype+' i').addClass( 'fa-eye-slash' );
            $('#wrapper_'+passwordtype+' i').removeClass( 'fa-eye' );
        } else if($('#wrapper_'+passwordtype+' input').attr('type') == 'password'){
            $('#wrapper_'+passwordtype+' input').attr('type', 'text');
            $('#wrapper_'+passwordtype+' i').removeClass( 'fa-eye-slash' );
            $('#wrapper_'+passwordtype+' i').addClass( 'fa-eye' );
        }
        
    }
</script>";
?>