}
 if (!empty($filled_surveys) && is_array($filled_surveys)) {
     $allow_ids = cw_array_merge($allow_ids, $filled_surveys);
 }
 $surveys = cw_query_hash("SELECT {$tables['surveys']}.* FROM {$tables['surveys']}, {$tables['survey_questions']} WHERE {$tables['surveys']}.valid_from_date < {$now} AND {$tables['surveys']}.expires_data > {$now} AND {$tables['surveys']}.survey_id = {$tables['survey_questions']}.survey_id AND ({$tables['surveys']}.survey_type = 'P'" . (empty($customer_id) ? "" : " OR {$tables['surveys']}.survey_type = 'R'") . " OR ({$tables['surveys']}.survey_type = 'H' AND {$tables['surveys']}.survey_id IN ('" . implode("','", $allow_ids) . "'))) GROUP BY {$tables['surveys']}.survey_id ORDER BY {$tables['surveys']}.orderby", "survey_id", false);
 $count_surveys = 0;
 $count_filled = 0;
 if (!empty($surveys)) {
     foreach ($surveys as $sid => $v) {
         list($is_valid, $messages) = cw_check_survey($sid);
         if (!$is_valid) {
             unset($surveys[$sid]);
             continue;
         }
         $count_surveys++;
         if (cw_check_survey_filling($sid)) {
             $surveys[$sid]['is_filled'] = true;
             $count_filled++;
         }
         if (!empty($filled_surveys) && in_array($sid, $filled_surveys) && $v['publish_results'] == 'Y') {
             $id = array_search($sid, $filled_surveys);
             $rid = cw_query_first_cell("SELECT survey_result_id FROM {$tables['survey_results']} WHERE survey_result_id = '{$id}' AND survey_id = '{$sid}'");
             if (!empty($rid)) {
                 $surveys[$sid]['is_view_results'] = true;
             } else {
                 cw_unset($filled_surveys, $id);
             }
         }
         $surveys[$sid]['survey'] = cw_get_languages_alt("survey_name_" . $sid, false, true);
     }
     if (!empty($surveys)) {
cw_load('surveys');
$filled_surveys =& cw_session_register('filled_surveys');
if (!isset($config['survey_sending_remainder']) || $config['survey']['survey_send_by_c_area_period'] < $config['survey_sending_remainder']) {
    cw_array2insert("config", array("name" => "survey_sending_remainder", "value" => $config['survey']['survey_send_by_c_area_period']), true);
    $config['survey_sending_remainder'] = $config['survey']['survey_send_by_c_area_period'];
}
if (defined("NEW_SESSION")) {
    $config['survey_sending_remainder']--;
    if ($config['survey']['survey_send_by_c_area'] && $config['survey_sending_remainder'] <= 0) {
        cw_send_survey_invitations_list();
        $config['survey_sending_remainder'] = $config['survey']['survey_send_by_c_area_period'];
    }
    cw_array2update("config", array("value" => $config['survey_sending_remainder']), "name = 'survey_sending_remainder'");
}
# Get survey for menu box
$avail_surveys = cw_get_surveys_ids(false, 1);
if (count($avail_surveys)) {
    $menu_surveys = array();
    foreach ($avail_surveys as $sid) {
        $survey = cw_get_survey($sid);
        if ($survey['valid'] && !cw_check_survey_filling($sid)) {
            $menu_surveys[$sid] = $survey;
            if ($config['survey']['survey_menu_only_one'] == 'Y') {
                break;
            }
        }
    }
    $smarty->assign('menu_surveys', $menu_surveys);
    $smarty->assign('surveys_is_avail', true);
}