Preview: Controlleradmin.php
                Size: 2.88 KB
              
              
                
              
            
            /home/jambtst2015/public_html/protected/components/Controlleradmin.php
            <?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controlleradmin extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
	
	var $fields;            /** columns names retrieved after parsing */
    var $separator = ',';    /** separator used to explode each line */
    var $enclosure = '"';    /** enclosure used to decorate each field */
    var $max_row_size = 4096;    /** maximum row size to be used for decoding */
	
	public function beforeAction($e){
	  $isAdmin = Yii::app()->user->getState("isAdmin");
	  $action = $this->action->Id;
	  if($isAdmin=='' && $action!='login'){
		  $this->redirect(Yii::app()->user->returnUrl.'webadmin/login');
		  return false;
	  }elseif($isAdmin!='' && $action=='login'){
		  $this->redirect(Yii::app()->user->returnUrl.'webadmin/');
	  	  return true;
	  }else{
		  return true;
	  }
    }
	
	/**
	 * This is the import csv file data
	*/
	
	public function parse_file($p_Filepath, $p_NamedFields = true) {
        $content = false;
        $file = fopen($p_Filepath, 'r');
        if($p_NamedFields) {
            $this->fields = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure);
        }
        while( ($row = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure)) != false ) {
            if( $row[0] != null ) { // skip empty lines
                if( !$content ) {
                    $content = array();
                }
                if( $p_NamedFields ) {
                    $items = array();
					$value = '';
					//print_r($this->fields);
                    // I prefer to fill the array with values of defined fields
                    foreach( $this->fields as $id => $field ) {
                        if( isset($row[$id]) ) {
							//$field = str_replace(" ","_",strtolower($field));
							$field = trim(strtolower($field));
							$field = str_replace(" ","_",$field);
							$value = trim($row[$id]);
                            //$items[$field] = trim($row[$id]);
							$items[$field] = $value;
                        }
                    }
                    $content[] = $items;
                } else {
                    $content[] = $row;
                }
            }
        }
        fclose($file);
        return $content;
    }
}
                                          Directory Contents
Dirs: 0 × Files: 12