 Yii::import('ext.phpexcelreader.JPhpExcelReader');
           $data=new JPhpExcelReader($filePath);
           for($i=2;$i<= $data->rowcount(0);$i++){
                  $is_empty = TRUE;
               for($j=0;$j<6 ;$j++){
                   if($data->val($i,$j)!=""){
                       $is_empty=FALSE;
                        break;
                   }
               }
			   
			   
			   
			   //controller
			   
			   
			    public function actionUploadFile($shift_id)
	{
            $uploaded_file_url = "";
            $shift_name = Shift::model()->findByPk($shift_id)->Name;
            $model=new ShiftFile('single');
            if(isset($_POST['ShiftFile']))
            {
                $date = date('Y-m-d H:i:s');
                $model->attributes=$_POST['ShiftFile'];
                $model->shift_id = $shift_id;
                $model->date = $date;
                if($model->validate()){
                    $model->file = CUploadedFile::getInstance($model,'file');
                    $formatted_file_name = $date."_".($model->file->name);
                    $model->file_name = str_replace(":","_",$formatted_file_name); // the ":" is not allowed in the file name
                    $model->file->saveAs('./protected/upload/'.$model->file_name);
                    $result = EmployeeShift::model()->validateExcel('./protected/upload/'.$model->file_name, $model->FromDate, $model->ToDate);
                   if($result!=NULL){
                       $model->addError('', $result);
                   }

                    //need to add fromDate,toDate
                    if($model->validate('',false))
                    {
                        $model->save();
                        $uploaded_file_url = Yii::app()->request->baseUrl."/protected/upload/".$model->file_name;
                        //need to use fromDate,toDate in attrubite for readExcel Method
                        EmployeeShift::Model()->readExcel('./protected/upload/'.$model->file_name,$shift_id,$model->FromDate, $model->ToDate);

                        Yii::app()->user->setFlash('success', Yii::t('default','The file '.$model->file->name.' has been uploaded successfully.'));
                    }

                else{
                    Yii::app()->user->setFlash('error', CHtml::errorSummary($model));
                }
               }
            else{
                Yii::app()->user->setFlash('error', CHtml::errorSummary($model));
            }
            }
            $this->render('uploadFile', array('model'=>$model, 'shift_name'=>$shift_name,
                                               'uploaded_file_url'=>$uploaded_file_url));
	}

	
	
	/view
	
	
	
	
	<?php
    $this->breadcrumbs=array(
            Yii::t('default','Shift')=>array('/shift/index'),
            $shift_name=>array('/shift/index'),
            Yii::t('default','Upload File')
    );
    
    $this->widget('bootstrap.widgets.BootAlert');

    $form = $this->beginWidget(
        'ext.bootstrap.widgets.BootActiveForm',
        array(
            'id' => 'upload-form',
            'enableAjaxValidation' => false,
            'htmlOptions' => array('enctype' => 'multipart/form-data'),
        )
    );

    if($uploaded_file_url != ""){
        echo "<br/>";
        echo CHtml::link('View File',$uploaded_file_url);
        echo "<br/><br/>";
    }
    
    echo $form->fileFieldRow($model, 'file');

    echo $form->labelEx($model,'FromDate');
    $form->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model'=>$model,
            'attribute'=>'FromDate',
            'options'=>array(
                'showAnim'=>'fold',
                'dateFormat'=>'yy-mm-dd',
            ),
            'htmlOptions'=>array('class'=>'span3'),
            'themeUrl'=>Yii::app()->request->baseUrl.'/css/jqueryui',
            'theme'=>'ABCTheme',
    ));

    echo $form->labelEx($model,'ToDate');
    $form->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model'=>$model,
            'attribute'=>'ToDate',
            'options'=>array(
                'showAnim'=>'fold',
                'dateFormat'=>'yy-mm-dd',
            ),
            'htmlOptions'=>array('class'=>'span3'),
            'themeUrl'=>Yii::app()->request->baseUrl.'/css/jqueryui',
            'theme'=>'ABCTheme',
    ));
    
    ?>
    <div class="row buttons">
            <?php echo CHtml::submitButton('Upload Reference Points',array('class'=>'btn btn-success',
                                            'onclick'=>
                                            "return confirm('Are you sure you want to upload the reference points listed in the selected file?\\nAll the currently existed reference points that are between the (From Date) and (To Date) will be removed and replaced by the reference points in the excel file.')")); ?>
    </div>
    <?php
    $this->endWidget();
?>
