function storeAttributeCSV($data)
 {
     $oParticipantAttributeName = new ParticipantAttributeName();
     $oParticipantAttributeName->attribute_type = $data['attribute_type'];
     $oParticipantAttributeName->defaultname = $data['defaultname'];
     $oParticipantAttributeName->visible = $data['visible'];
     $oParticipantAttributeName->save();
     $iAttributeID = $oParticipantAttributeName->attribute_id;
     $oParticipantAttributeNameLang = new ParticipantAttributeNameLang();
     $oParticipantAttributeNameLang->attribute_id = $iAttributeID;
     $oParticipantAttributeNameLang->attribute_name = $data['defaultname'];
     $oParticipantAttributeNameLang->lang = Yii::app()->session['adminlang'];
     $oParticipantAttributeNameLang->save();
     return $iAttributeID;
 }
 /**
  * Get an array of CPDB attributes
  * 
  * @param mixed $sLanguageFilter
  */
 function getVisibleAttributes($sLanguageFilter = null)
 {
     if ($sLanguageFilter == null) {
         $sLanguageFilter = Yii::app()->session['adminlang'];
     }
     $output = array();
     //First get all the distinct id's that are visible
     $ids = ParticipantAttributeName::model()->findAll("visible = 'TRUE'");
     //Then find a language for each one - the current $lang, if possible, english second, otherwise, the first in the list
     foreach ($ids as $id) {
         $langs = ParticipantAttributeNameLang::model()->findAll("attribute_id = :attribute_id", array(":attribute_id" => $id->attribute_id));
         $language = null;
         foreach ($langs as $lang) {
             //If we can find a language match, set the language and exit
             if ($lang->lang == $sLanguageFilter) {
                 $language = $lang->lang;
                 $attribute_name = $lang->attribute_name;
                 break;
             }
             if ($lang->lang == "en") {
                 $language = $lang->lang;
                 $attribute_name = $lang->attribute_name;
             }
         }
         if ($language == null) {
             $language = $langs[0]->lang;
             $attribute_name = $langs[0]->attribute_name;
         }
         $output[] = array("attribute_id" => $id->attribute_id, "attribute_type" => $id->attribute_type, "visible" => $id->visible, "attribute_name" => $attribute_name, "lang" => $language);
     }
     return $output;
 }