<style>
 
</style>
<div class="col-xs-12 col-sm-offset-1 col-sm-10">
 <?php

 Yii::app()->setLanguage(isset(Yii::app()->session['lang']) ? Yii::app()->session['lang'] : 'ar'); 
 $lang=Yii::app()->getLanguage();
 

?> 
<?php

if(!empty($_POST['search'])){
	$arMSG="نتائج البحث المتعلقة ب ".strip_tags($_POST['search']);
	$enMSG="Results for:".strip_tags($_POST['search']);
	echo '<div> ';
	echo $lang=="en"?$enMSG:$arMSG;
	echo '</div>';
 $search=$_POST['search'];

  // echo $search.'hiiii';
$criteria= new CDbCriteria();
$criteriaPerson = new CDbCriteria();

$criteria->compare('title', $search, true, 'OR');
$criteria->compare('content', $search, true, 'OR');
$criteria->compare('en_title', $search, true, 'OR'); 
$criteria->compare('en_content', $search, true, 'OR');



$articles=Article::model()->findAll($criteria);
$pagesdd=Page::model()->findAll($criteria);


$criteriaPerson->compare('name_ar', $search, true, 'OR');
$criteriaPerson->compare('job_title_ar', $search, true, 'OR');
$criteriaPerson->compare('description_ar', $search, true, 'OR');
$criteriaPerson->compare('name_en', $search, true, 'OR'); 
$criteriaPerson->compare('job_title_en', $search, true, 'OR');
$criteriaPerson->compare('description_en', $search, true, 'OR');
$criteriaPerson->compare('type', $search, true, 'OR');

// var_dump($criteria);
// echo '<br>';
// var_dump($criteriaPerson);
// die;


$persons=Person::model()->findAll($criteriaPerson);


$resultNumber = $articles != null ? count($articles) : 0;

 
echo '<br>';

if($resultNumber !=0)
{
  //echo '<h1>Articles</h1>';
  foreach($articles as $article)
  {
    //if($article->attachment_title==NULL)
		if(TRUE)
    {
      echo '<a href="'.Yii::app()->request->baseUrl.'/article/view/slug/'.$article->slug.'">';
    }
    else
    {
    echo '<a href="'.Yii::app()->request->baseUrl.'/uploads/Article/files/'.$article->attachment_title.'" target="_blank">';
    }
      if($lang=='en')
      {
          echo $article->en_title;
          if($article->en_title==Null)
          {
              echo $article->title;
          }
      }
      else
      {
         echo $article->title;
      }
          
//    echo ($lang=='en'?$article->en_title:$article->title). 
      echo  '</a>'; 
  }
}

$page_results_number = $pagesdd != null ? count($pagesdd) : 0;

if($page_results_number)
{
  //echo '<h1> Pages </h1>';
  foreach($pagesdd as $page)
  {
    echo '<a href="'.Yii::app()->request->baseUrl.'/page/view/'.$page->slug.'">';
 if($lang == 'en'){
    echo  $page->en_title;
     if($page->en_title == Null){
       echo  $page->title;
     }
 }
    else
      {
           echo  $page->title;
      }
         
    echo '</a>';
    
  }
}

$persons_results_number = $persons != null ? count($persons) : 0;

if($persons_results_number)
{
  
//  "1"=>"أعضاء الادارة التنفيذية",
// "2"=>"اعضاء مجلس الادارة",
// "3"=>"اعضاء هيئة الرقابة الشرعية", )
 // "0"=>"موظف الشهر"

  foreach($persons as $person)
  {
    
    echo '
          <div class="person_search_conten">
            <div class="person_search_name">';
            if($person->type==1)
            {
              $link="/page/view/executive-administration";
            }elseif($person->type==2)
            {
              $link= "/page/view/board-of-directors";
            }elseif($person->type==3)
            {
              $link="/page/view/members-of-the-legitimate-censorship-board" ;
            }
            echo '
            
              <a href="'.Yii::app()->request->baseUrl.$link.'">
                '.($lang=='ar'?$person->name_ar:$person->name_en).'
                
            
              <p>'.($lang=='ar'?$person->job_title_ar:$person->job_title_en).'</p>
            
            </a>
            </div>
            

          </div>
    
    ';
   
  }
}

}

?> 
</div>