public function update($id)
 {
     // Validate
     // read more on validation at http://laravel.com/docs/validation
     $rules = array('que_name' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         return Redirect::to('questions/' . $id . '/edit')->withErrors($validator);
     } else {
         // store
         $questions = new questions();
         $questions->que_name = Input::get('que_name');
         $questions->save();
         // Redirect
         Session::flash('message', 'Successfully created Questions!');
         return Redirect::to('questions');
     }
 }
 public function getEmailContent($UseIn, $panelistID = 0)
 {
     $message_body = "";
     $subject = "";
     //if language and country are 0 then send in default language.
     //If country id not equal to 0 then
     $sql = "SELECT * FROM " . $this->viewName() . " WHERE use_in = {$UseIn} and isactive = 1 ";
     $cmd = Yii::app()->db->createCommand($sql);
     $cnt = $cmd->queryScalar();
     $rows = $cmd->queryAll();
     $dr = $cmd->query();
     if ($cnt > 0) {
         while (($r = $dr->read()) !== false) {
             //while ($r = mysql_fetch_array($dataReader)) {
             $message_body = $r['content_text'];
             $subject = $r['subject_text'];
             $email_bodyid = $r['email_bodyid'];
             $email_subjectid = $r['email_subjectid'];
         }
         $panelistID = (int) $panelistID;
         $preferLanguageCode = Yii::app()->lang->langcode;
         //Get panel list communication language
         if ($panelistID > 0) {
             //$sql="SELECT id as question_id,short_title FROM {{profile_question}} WHERE short_title LIKE 'Prefered-Language'";
             $dr = questions::model()->communication_language()->findAll();
             if (count($dr) > 0) {
                 $question_id = (int) $dr[0]['id'];
                 //$question_id = (int) 1;
             } else {
                 $question_id = 0;
             }
             if ($question_id > 0) {
                 $columnname = "question_id_{$question_id}";
                 $qus_language_answer = Yii::app()->db->createCommand("select {$columnname} from {{panellist_answer}} WHERE panellist_id = {$panelistID}")->queryRow();
                 if (count($qus_language_answer) > 0) {
                     $preferLanguageCode = $qus_language_answer[$columnname];
                 } else {
                     $preferLanguageCode = Yii::app()->lang->langcode;
                 }
             }
         } else {
             //if there is no panel list then use the default language
             $preferLanguageCode = Yii::app()->lang->langcode;
         }
         if ($preferLanguageCode != "") {
             //$EmailLanguageCode = $preferLanguageCode;
             //$tempEmailLanguageCode = $preferLanguageCode;
             $sql = "SELECT * FROM {{translation_email_body}} WHERE language_code_dest = '{$preferLanguageCode}'\n                    AND email_bodyid = {$email_bodyid}";
             $qur_translate = Yii::app()->db->createCommand($sql)->queryRow();
             if (count($qur_translate) > 0) {
                 $message_body = $qur_translate['translated_body'];
             } else {
                 //$message_body = 'Email body translation not found for language code = $preferLanguageCode, Please inform your webmaster';
                 $message_body = '';
             }
             $sql = "SELECT * FROM {{translation_email_subjects}} WHERE language_code_dest = '{$preferLanguageCode}'\n                    AND email_subjectid = {$email_subjectid}";
             $qur_translate = Yii::app()->db->createCommand($sql)->queryRow();
             if (count($qur_translate) > 0) {
                 $subject = $qur_translate['translated_subject'];
             } else {
                 //$subject = 'Email subject translation not found for language code = $preferLanguageCode, Please inform your webmaster';
                 $subject = '';
             }
         }
         if (strlen($message_body) == 0) {
             throw new Exception("There is some problem regarding to get the email body");
         }
         if (strlen($subject) == 0) {
             throw new Exception("There is some problem regarding to get the email subject");
         }
     } else {
         throw new Exception("No Email Template found for these email point.");
     }
     return array("SUBJECT" => $subject, "BODY" => $message_body);
 }
 function mod()
 {
     $clang = Yii::app()->lang;
     if (!Permission::model()->hasGlobalPermission('panellist', 'update')) {
         Yii::app()->setFlashMessage($clang->gT("You do not have sufficient rights to access this page."), 'error');
         $this->getController()->redirect(array("admin/index"));
     }
     App()->getClientScript()->registerCssFile(Yii::app()->getConfig('styleurl') . "jquery.dataTables.css");
     App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . 'jquery.dataTables.min.js');
     $clang = Yii::app()->lang;
     $action = isset($_GET['action']) ? $_GET['action'] : '';
     $aData = array();
     $aViewUrls = array();
     if (Permission::model()->hasGlobalPermission('panellist', 'update')) {
         if ($action == "editquestion") {
             // Project details
             $question_id = (int) Yii::app()->request->getPost("question_id");
             $category_id = (int) Yii::app()->request->getPost("category");
             $short_title = flattenText($_POST['question_short_title'], false, true, 'UTF-8', true);
             $title = flattenText($_POST['question_title'], false, true, 'UTF-8', true);
             $field_type = flattenText($_POST['question_field_type'], false, true, 'UTF-8', true);
             $IsOther = flattenText(Yii::app()->request->getPost("question_is_other"));
             $is_other = 0;
             if ($IsOther) {
                 $is_other = 1;
             }
             $is_other_field_type = flattenText($_POST['question_field_other_type'], false, true, 'UTF-8', true);
             $outdate_threshold = (int) $_POST['question_outdate_threshold'];
             $priority = flattenText($_POST['question_priority'], false, true, 'UTF-8', true);
             $IsProfile = flattenText(Yii::app()->request->getPost("question_is_profile"));
             $is_profile = 0;
             if ($IsProfile) {
                 $is_profile = 1;
             }
             $IsProject = flattenText(Yii::app()->request->getPost("question_is_project"));
             $is_project = 0;
             if ($IsProject) {
                 $is_project = 1;
             }
             $IsActive = flattenText(Yii::app()->request->getPost("IsActive"));
             $is_active = 0;
             if ($IsActive) {
                 $is_active = 1;
             }
             $sort_order = flattenText($_POST['sort_order'], false, true, 'UTF-8', true);
             if ($short_title == '') {
                 $aViewUrls['message'] = array('title' => $clang->gT("Failed to add Question"), 'message' => $clang->gT("Question Name is invalid."), 'class' => 'warningheader');
             } else {
                 $oUser = questions::model()->findByPk($question_id);
                 $oUser->category_id = $category_id;
                 $oUser->short_title = $short_title;
                 $oUser->title = $title;
                 $oUser->field_type = $field_type;
                 $oUser->is_other = $is_other;
                 $oUser->is_other_field_type = $is_other_field_type;
                 $oUser->outdate_threshold = $outdate_threshold;
                 $oUser->priority = $priority;
                 $oUser->is_profile = $is_profile;
                 $oUser->is_project = $is_project;
                 $oUser->IsActive = $is_active;
                 $oUser->sorder = $sort_order;
                 $oUser->modified_date = Date('y-m-d h:i:s');
                 $NewQuestion = $oUser->save();
                 if ($NewQuestion) {
                     Yii::app()->setFlashMessage($clang->gT("Profile Question Updated successfully"));
                     $this->getController()->redirect(array("admin/profilequestion/index"));
                 }
             }
         } else {
             if (isset($_GET['question_id'])) {
                 $aData['row'] = 0;
                 $aData['usr_arr'] = array();
                 // Project detail
                 $question_id = (int) $_GET['question_id'];
                 $action = $_GET['action'];
                 $sresult = profilequestionview($question_id);
                 // only use in view_editcompany
                 $aData['question_id'] = $question_id;
                 $aData['mur'] = $sresult;
                 $aData['imageurl'] = Yii::app()->getConfig("adminimageurl");
                 $answerlist = profileanswer_view($question_id);
                 $aData['answer_arr'] = $answerlist;
                 $this->_renderWrappedTemplate('panellist/questions', 'editquestion_view', $aData);
                 return;
             }
         }
     }
     Yii::app()->setFlashMessage(Yii::app()->lang->gT("You do not have sufficient rights to access this page."), 'error');
     $this->getController()->redirect(array("admin/profilequestion/index"));
 }
function Question($cat_id, $style = '', $quetype = false, $quelist = FALSE)
{
    $test = '';
    $question_type = array();
    $question_list = array();
    $sql = questions::model()->isactive()->findAll(array("condition" => "category_id = '{$cat_id}'", 'order' => 'sorder'));
    foreach ($sql as $key => $value) {
        if ($quetype) {
            $question_type[$value['id']] = $value['field_type'];
        }
        if ($quelist) {
            $question_list[$value['id']] = $value['title'];
        }
        $test .= CreateUi($value['id'], $value['title'], $value['field_type'], $style);
    }
    if ($quetype) {
        return $question_type;
    }
    if ($quelist) {
        return $question_list;
    }
    return $test;
}