diff -n counter-6.x-1.5/counter/counter.info fix_admin_form/counter/counter.info
d6 1
a6 1
package = "Statistics"
diff -n counter-6.x-1.5/counter/counter.module fix_admin_form/counter/counter.module
d1 206
a206 213
<?php
// $Id: counter.module,v 1.17 2009/01/04 05:06:40 thenicespider Exp $

/**
 * @file
 * The counter module used for displaying Site Counter.
 */

/**
 * Implementation of hook_help().
 */
function counter_help($section) {
  switch ($section) {
    case 'admin/help#Counter':
      $output = "The counter module used for displaying Site Counter.";
	return $output;
    case 'admin/modules#description':
      return 'The counter module used for displaying Site Counter';
    case 'admin/settings/counter':
      $output = '
        <p>Settings for the Site counter module. See the <a href="@site_counter_report">Site Counter Report</a> page for details of individual visits.</p>
      ';
      return t($output, array(
        '@site_counter_report' => url('counter/report'),
      ));
  }
}

/**
 * Implementation of hook_perm
 */
function counter_perm() {
  return array('access counter', 'administer counter');
}
 
/**
 * Menu callback. Prints a listing of active nodes on the site.
 */

function counter_menu() {
  $items = array();

  $items['admin/settings/counter'] = array(
    'title' => 'Counter settings',
    'description' => 'Show Site Counter, Client IP, and Unique Visitor.',
    'access arguments' => array('administer counter'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('counter_admin_settings'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'counter.settings.inc',
  );
  
  $items['counter/report'] = array(
    'title' => 'Counter Report',
    'description' => 'View Counter Report',
    'access arguments' => array('administer counter'),
    'page callback' => 'counter_report',
    'type' => MENU_NORMAL_ITEM,
    'file' => 'counter.report.inc',
  );
  
  return $items;
}

/**
 * Implementation of hook_block().
 *
 */
function counter_block($op = 'list', $delta = 0) {
  if ($op == 'list') 
  {
    $blocks[0]['info'] = 'Site Counter';
	return $blocks;
  }
  
  if ($op == 'view') 
  {
    $counter_show_site_counter   = variable_get('counter_show_site_counter',1);
    $counter_show_unique_visitor = variable_get('counter_show_unique_visitor',1);
	$counter_registered_user     = variable_get('counter_registered_user',1);
    $counter_unregistered_user   = variable_get('counter_unregistered_user',1);
    $counter_published_node      = variable_get('counter_published_node',1);
    $counter_unpublished_node    = variable_get('counter_unpublished_node',1);
    $counter_show_ip             = variable_get('counter_show_ip',1);
    $counter_show_counter_since  = variable_get('counter_show_counter_since',1);
    
    $counter_show_administer_only = variable_get('counter_show_administer_only',0);
    $counter_record_interval      = variable_get('counter_record_interval',0);
    
    $counter_initial_counter        = variable_get('counter_initial_counter', 0);
    $counter_initial_unique_visitor = variable_get('counter_initial_unique_visitor', 0);
    $counter_initial_since          = variable_get('counter_initial_since', '');
    
    switch($delta) {
      case 0:
        $block['subject'] = 'Counter';    
        
        $output  = '';
        
		$counter_ip = $_SERVER['REMOTE_ADDR'];		
		
		$counter_page = arg(0);	
		if (arg(1)<>'') { $counter_page .= ",".arg(1); }
		if (arg(2)<>'') { $counter_page .= ",".arg(2); }
		if (arg(3)<>'') { $counter_page .= ",".arg(3); }
		
		if ($counter_record_interval == 0) { $counter_date = date('Y-m-d');}
		if ($counter_record_interval == 1) { $counter_date = date('Y-m-d H:i');}
		if ($counter_record_interval == 2) { $counter_date = date('Y-m-d H:i:s');}
		
		//Check database
		$sql = " SELECT count(*) AS total FROM {counter}"
              ." WHERE counter_ip='%s' AND counter_date='%s' AND counter_page='%s'";
             
        $results = db_query($sql,$counter_ip,$counter_date,$counter_page);

		$data = db_fetch_object($results);
		$counter_check = $data->total;
		  
		if (!$counter_check) {
		  $sql = " INSERT IGNORE INTO {counter}  "
                ." (counter_ip, counter_date, counter_page) VALUES "
                ." ('%s', '%s', '%s') ";
             
          $results = db_query($sql,$counter_ip,$counter_date,$counter_page);		
		}
		  
		$output  .= '<ul>';
		if ($counter_show_site_counter) {
		  $sql = " SELECT count(*) as total FROM {counter} c ";
          $results = db_query($sql);
          $data = db_fetch_object($results);
		  $counter_total = $data->total;
          $output .= '<li>'.t('Site Counter: '). ($counter_initial_counter+$counter_total).'</li>';
		}
		
		if ($counter_show_unique_visitor) {
		  $sql = " SELECT count(*) as total FROM (SELECT counter_ip FROM {counter} GROUP BY counter_ip) c";
          $results = db_query($sql);
          $data = db_fetch_object($results);
		  $counter_unique = $data->total;  
		  $output .= '<li>'.t('Unique Visitor: '). ($counter_initial_unique_visitor+$counter_unique).'</li>';
		}
		
		if ($counter_registered_user) {
		  $sql = " SELECT count(*) as total FROM {users} WHERE status=1 and uid<>0";
          $results = db_query($sql);
          $data    = db_fetch_object($results);
		  $total   = $data->total;
		  $output .= '<li>'.t('Registered Users: '). ($total).'</li>';
		}
		
		if ($counter_unregistered_user) {
		  $sql = " SELECT count(*) as total FROM {users} WHERE status=0 and uid<>0";
          $results = db_query($sql);
          $data    = db_fetch_object($results);
		  $total   = $data->total;
		  $output .= '<li>'.t('Unregistered Users: '). ($total).'</li>';
		}
		
		if ($counter_published_node) {
		  $sql = " SELECT count(*) as total FROM {node} WHERE status=1";
          $results = db_query($sql);
          $data    = db_fetch_object($results);
		  $total   = $data->total;
		  $output .= '<li>'.t('Published Nodes: '). ($total).'</li>';
		}
		
		if ($counter_unpublished_node) {
		  $sql = " SELECT count(*) as total FROM {node} WHERE status=0";
          $results = db_query($sql);
          $data    = db_fetch_object($results);
		  $total   = $data->total;
		  $output .= '<li>'.t('Unpublished Nodes: '). ($total).'</li>';
		}
		
		if ($counter_show_ip) {
		  $output .= '<li>'.t("Your IP: ").$counter_ip.'</li>';	
		}
		
		if ($counter_show_counter_since) {
		  $sql = " SELECT counter_date FROM {counter} order by counter_date ASC LIMIT 1";
          $results = db_query($sql);
          $data = db_fetch_object($results);
		  $counter_since = $data->counter_date;
		  
		  if ($counter_initial_since=="") {
		    $output .= '<li>'.t("Since: "). $counter_since.'</li>';	
		  } else {
		    $output .= '<li>'.t("Since: "). $counter_initial_since.'</li>';	
		  }		  
		  
		}
				
		$output  .= '</ul>';    
            
        $block['content'] = $output;
        
        break;  
    }
    
    if ($counter_show_administer_only && !user_access('administer counter')) {
		return;
	} else {
	  return $block;	
	}
    
  }
}



?>
diff -n counter-6.x-1.5/counter/counter.settings.inc fix_admin_form/counter/counter.settings.inc
d1 21
a21 86
<?php
// $Id: counter.settings.inc,v 1.2 2009/01/04 05:06:40 thenicespider Exp $
/**
 * @file
 * Settings page callback file for the counter module.
 */

/**
 * Menu callback;
 */
 
function counter_admin_settings() {
  $form = array();
  // only administrators can access this function
  
  // Generate the form - settings applying to all patterns first
  $form['counter_settings'] = array(
    '#type' => 'fieldset',
    '#weight' => -30,
    '#title' => t('Basic settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#description' => t('Display the following information in the Site Counter Block')
  );
  
  $form['counter_settings']['counter_show_site_counter'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Site Counter'),
    '#default_value' => variable_get('counter_show_site_counter', 1),
    '#description' => t('Show Site Counter')
  );    
    
  $form['counter_settings']['counter_show_unique_visitor'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Unique Visitors'),
    '#default_value' => variable_get('counter_show_unique_visitor', 1),
    '#description' => t('Show Unique Visitors based on their IP')
  );
  
  $form['counter_settings']['counter_registered_user'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Registered Users'),
    '#default_value' => variable_get('counter_registered_user', 1),
    '#description' => t('Show Registered Users')
  );
  
  $form['counter_settings']['counter_unregistered_user'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Unregistered Users'),
    '#default_value' => variable_get('counter_unregistered_user', 1),
    '#description' => t('Show Unregistered Users')
  );
  
  $form['counter_settings']['counter_published_node'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Published Nodes'),
    '#default_value' => variable_get('counter_published_node', 1),
    '#description' => t('Show Published Nodes')
  );
  
  $form['counter_settings']['counter_unpublished_node'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Unpublished Nodes'),
    '#default_value' => variable_get('counter_unpublished_node', 1),
    '#description' => t('Show Unpublished Users')
  );
  
  $form['counter_settings']['counter_show_ip'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Client IP'),
    '#default_value' => variable_get('counter_show_ip', 1),
    '#description' => t('Show Client IP')
  );
 
  $form['counter_settings']['counter_show_counter_since'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Site Counter Since'),
    '#default_value' => variable_get('counter_show_counter_since', 1),
    '#description' => t('Show the first entry date in the Site Counter')
  );
  
  $form['counter_advanced'] = array(
    '#type' => 'fieldset',
    '#weight' => -20,
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
d23 121
a143 55
  );
  
  $form['counter_advanced']['counter_show_administer_only'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Site Counter Result for Administer group only'),
    '#default_value' => variable_get('counter_show_administer_only', 0),
    '#description' => t("Show Site Counter Result for group with 'administer counter' rights only. This setting usefull if you want to hide Counter block from public users")
  );    
  
  $form['counter_advanced']['counter_record_interval'] = array(
      '#type' => 'select',
      '#title' => t('Save record interval'),
      '#default_value' => variable_get('counter_record_interval', 0),
      '#options' => array('day', 'minute', 'second'),
      '#description' => t("Counter will save access per interval, if you choose 'day' then same IP that access same page will be "
	                     ."save as 1 record per day, i.e: "
						 ."<ul>"
						 ."<li>Per day &nbsp;&nbsp;&nbsp;&nbsp;: User A access 'node/12' 25 times per day --> save as 1 record</li>"
						 ."<li>Per minute: User A access 'node/12' 25 times on 22:03 and 5 times on 22:07 ---> save as 2 records</li>"
						 ."<li>Per second: User A access 'node/12' 2 times on 22:03:01 and 3 times on 22:03:02 ---> save as 2 records</li>"
						 ."</ul><b>Caution!</b> Set interval to second may cause your database size too big, because every second access will be saved"),
      );
      
  $form['counter_initial'] = array(
    '#type' => 'fieldset',
    '#weight' => -10,
    '#title' => t('Initial Values'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#description' => t("Set initial values for Site Counter.")
  );
  
  $form['counter_initial']['counter_initial_counter'] = array(
    '#type' => 'textfield',
    '#title' => t('Initial value of Site Counter'),
    '#default_value' => variable_get('counter_initial_counter', 0),
    '#description' => t('Initial value of Site Counter')
  );
  
  $form['counter_initial']['counter_initial_unique_visitor'] = array(
    '#type' => 'textfield',
    '#title' => t('Initial value of Unique Visitor'),
    '#default_value' => variable_get('counter_initial_unique_visitor', 0),
    '#description' => t('Initial value of Unique Visitor')
  );
  
  $form['counter_initial']['counter_initial_since'] = array(
    '#type' => 'textfield',
    '#title' => t("Replace 'Since' value with this string"),
    '#default_value' => variable_get('counter_initial_since', ''),
    '#description' => t("If you leave this field blank than Counter module will use the first date of Counter record. This field type is textfield, so you can enter: '2008-08-12 or 12 August 2008 06:39'.")
  );
  
  return system_settings_form($form);
}
