<?php

/**
 * Override of theme_breadcrumb().
 */
function hlt_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    $output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>';
    return $output;
  }
}



/**
 * Override or insert variables into the maintenance page template.
 */
function hlt_preprocess_maintenance_page(&$vars) {
  // While markup for normal pages is split into page.tpl.php and html.tpl.php,
  // the markup for the maintenance page is all in the single
  // maintenance-page.tpl.php template. So, to have what's done in
  // hlt_preprocess_html() also happen on the maintenance page, it has to be
  // called here.
  hlt_preprocess_html($vars);
}

/**
 * Override or insert variables into the html template.
 */
function hlt_preprocess_html(&$vars) {
  // Toggle fixed or fluid width.
  if (theme_get_setting('hlt_width') == 'fluid') {
    $vars['classes_array'][] = 'fluid-width';
  }
  // Add conditional CSS for IE6.
  drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
}

/**
 * Override or insert variables into the html template.
 */
function hlt_process_html(&$vars) {
  // Hook into color.module
  if (module_exists('color')) {
    _color_html_alter($vars);
  }
}

/**
 * Override or insert variables into the page template.
 */
function hlt_preprocess_page(&$vars) {
  // Move secondary tabs into a separate variable.
  $vars['tabs2'] = array(
    '#theme' => 'menu_local_tasks',
    '#secondary' => $vars['tabs']['#secondary'],
  );
  unset($vars['tabs']['#secondary']);

  if (isset($vars['main_menu'])) {
    $vars['primary_nav'] = theme('links__system_main_menu', array(
      'links' => $vars['main_menu'],
      'attributes' => array(
        'class' => array('links', 'inline', 'main-menu'),
      ),
      'heading' => array(
        'text' => t('Main menu'),
        'level' => 'h2',
        'class' => array('element-invisible'),
      )
    ));
  }
  else {
    $vars['primary_nav'] = FALSE;
  }
  if (isset($vars['secondary_menu'])) {
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
      'links' => $vars['secondary_menu'],
      'attributes' => array(
        'class' => array('links', 'inline', 'secondary-menu'),
      ),
      'heading' => array(
        'text' => t('Secondary menu'),
        'level' => 'h2',
        'class' => array('element-invisible'),
      )
    ));
  }
  else {
    $vars['secondary_nav'] = FALSE;
  }

  // Prepare header.
  $site_fields = array();
  if (!empty($vars['site_name'])) {
    $site_fields[] = $vars['site_name'];
  }
  if (!empty($vars['site_slogan'])) {
    $site_fields[] = $vars['site_slogan'];
  }
  $vars['site_title'] = implode(' ', $site_fields);
  if (!empty($site_fields)) {
    $site_fields[0] = '<span>' . $site_fields[0] . '</span>';
  }
  $vars['site_html'] = implode(' ', $site_fields);

  // Set a variable for the site name title and logo alt attributes text.
  $slogan_text = $vars['site_slogan'];
  $site_name_text = $vars['site_name'];
  $vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text;
  
  
  
  
}

/**
 * Override or insert variables into the node template.
 */
function hlt_preprocess_node(&$variables) {

  if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {    
	$variables['classes_array'][] = 'node-full';
  }
  
}
/**
 * Override or insert variables into the comment template.
 */
function hlt_preprocess_comment(&$vars) {
  $vars['submitted'] = $vars['created'] . ' — ' . $vars['author'];
}

/**
 * Override or insert variables into the block template.
 */
function hlt_preprocess_block(&$vars) {

	$vars['title_attributes_array']['class'][] = 'title';
	$vars['classes_array'][] = 'clearfix';
}

/**
 * Override or insert variables into the page template.
 */
function hlt_process_page(&$vars) {
  // Hook into color.module
  if (module_exists('color')) {
    _color_page_alter($vars);
  }
}

/**
 * Override or insert variables into the region template.
 */
function hlt_preprocess_region(&$vars) {
  if ($vars['region'] == 'header') {
    $vars['classes_array'][] = 'clearfix';
  }  
}
/* To alter the block view */
function hlt_block_view_alter(&$data, $block) {
  global $user;	
  if($block->delta == "menu-footer-menu-")
  {
	$content = $data['content'];
	$rows = array();
	foreach($content as $key => $row)
	{
		$title = $row['#title'];
		if($title == "Calendar ")
		{
			if(!$user->uid)
			{
				$row['#href'] = 'user/login';
			}
		}	
		$rows[$key] = $row;	
	}
	
	$data['content'] = $rows;	
  }  	
}
function hlt_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_block_form') {
    $form['search_block_form']['#title'] = t('Search'); // Change the text on the label element
    $form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty
    
    //$form['search_block_form']['#default_value'] = t('Search'); // Set a default value for the textfield
    $form['actions']['submit']['#value'] = t('GO!'); // Change the text on the submit button
    $form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/img/search-icon.png');
	$form['actions']['submit']['#attributes']['class'][] = "search-icon";
    // Add extra attributes to the text box
	$form['search_block_form']['#attributes']['class'][] = "search col-sm-12";	
    $form['search_block_form']['#attributes']['placeholder'] = "Search";    
	$form['search_block_form']['#attributes']['required'] = "required";    
    // Prevent user from searching the default text
	
    $form['#attributes']['onsubmit'] = "if(this.search_block_form.value=='' || this.search_block_form.value==' ' ){ alert('Please enter a search items'); return false; }";

    // Alternative (HTML5) placeholder attribute instead of using the javascript
    $form['search_block_form']['#attributes']['placeholder'] = t('Search');
	
   }
   if ($form_id == 'webform_client_form_13') 
   { 
		$form['actions']['submit']['#attributes']['class'][] = 'btn btn-custom';
		$form['#submit'][] = 'my_submit_handler';		
   }
} 

function hlt_theme() {
  $items = array();
    
  $items['user_login'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'hlt') . '/templates',
    'template' => 'user-login',
    'preprocess functions' => array(
       'hlt_preprocess_user_login'
    ),
  );
  
  $items['user_pass'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'hlt') . '/templates',
    'template' => 'user-pass',
    'preprocess functions' => array(
      'hlt_preprocess_user_pass'
    ),
  );
  return $items;
}

function hlt_preprocess_user_login(&$vars) {
  $vars['intro_text'] = t('Sign in');
  
}
function hlt_preprocess_user_pass(&$vars) {
  $vars['intro_text'] = t('Reset Password');
}
/* To redirect the page to contact us with success message */
function my_submit_handler(&$form, &$form_state) 
{
  $_SESSION['confirm'] = 1;
  $form_state['redirect'] = 'contactus';
}
function hlt_date_nav_title($params) 
{
	$granularity = $params['granularity'];
	$view = $params['view'];
	$date_info = $view->date_info;
	$link = !empty($params['link']) ? $params['link'] : FALSE;
	$format = !empty($params['format']) ? $params['format'] : NULL;
	switch ($granularity) 
	{
		case 'year':
			$title = $date_info->year;
			$date_arg = $date_info->year;
		break;
		case 'month':
			$format = !empty($format) ? $format : (empty($date_info->mini) ? 'F Y' : 'F Y');
			$title = date_format_date($date_info->min_date, 'custom', $format);
			$date_arg = $date_info->year .'-'. date_pad($date_info->month);
		break;
		case 'day':
			$format = !empty($format) ? $format : (empty($date_info->mini) ? 'l, F j Y' : 'l, F j');
			$title = date_format_date($date_info->min_date, 'custom', $format);
			$date_arg = $date_info->year .'-'. date_pad($date_info->month) .'-'. date_pad($date_info->day);
		break;
		case 'week':
			$format = !empty($format) ? $format : (empty($date_info->mini) ? 'F j Y' : 'F j');
			$title = t('Week of @date', array('@date' => date_format_date($date_info->min_date, 'custom', $format)));
			$date_arg = $date_info->year .'-W'. date_pad($date_info->week);
		break;
	}
	if (!empty($date_info->mini) || $link) 
	{
		// Month navigation titles are used as links in the mini view.
		$attributes = array('title' => t('View full page month'));
		$url = date_pager_url($view, $granularity, $date_arg, TRUE);
		return l($title, $url, array('attributes' => $attributes));
	}
	else 
	{
		return $title;
	}
}

