1. PHP / Говнокод #1534

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    <?php
    ...
    
    $date1['year'] = ($_POST['year1']>=2006 && $_POST['year1']<=2037) ? $_POST['year1'] : (($_GET['year1']>=2006 && $_GET['year1']<=2037) ? $_GET['year1'] : date('Y'));
    $date1['month'] = ($_POST['month1']>=1 && $_POST['month1']<=12) ? $_POST['month1'] : (($_GET['month1']>=1 && $_GET['month1']<=12) ? $_GET['month1'] : date('n'));
    $date1['day'] = $type>2 ? 1 : (($_POST['day1']>=1 && $_POST['day1']<=31) ? $_POST['day1'] : (($_GET['day1']>=1 && $_GET['day1']<=31) ? $_GET['day1'] : date('j')));
    $date1['hour'] = $type>1 ? 0 : ((isset($_POST['hour1']) && $_POST['hour1']>=0 && $_POST['hour1']<=23) ? $_POST['hour1'] : ((isset($_GET['hour1']) && $_GET['hour1']>=0 && $_GET['hour1']<=23) ? $_GET['hour1'] : 0));
    $date1['min'] = $type ? 0 : ((isset($_POST['min1']) && $_POST['min1']>=0 && $_POST['min1']<=59) ? $_POST['min1'] : ((isset($_GET['min1']) && $_GET['min1']>=0 && $_GET['min1']<=59) ? $_GET['min1'] : 0));
    
    $date2['year'] = ($_POST['year2']>=2006 && $_POST['year2']<=2037) ? $_POST['year2'] : (($_GET['year2']>=2006 && $_GET['year2']<=2037) ? $_GET['year2'] : date('Y'));
    $date2['month'] = ($_POST['month2']>=1 && $_POST['month2']<=12) ? $_POST['month2'] : (($_GET['month2']>=1 && $_GET['month2']<=12) ? $_GET['month2'] : date('n'));
    $date2['day'] = $type>2 ? cal_days_in_month(CAL_GREGORIAN, $date2['month'], $date2['year']) : (($_POST['day2']>=1 && $_POST['day2']<=31) ? $_POST['day2'] : (($_GET['day2']>=1 && $_GET['day2']<=31) ? $_GET['day2'] : date('j')));
    $date2['hour'] = $type>1 ? 23 : ((isset($_POST['hour2']) && $_POST['hour2']>=0 && $_POST['hour2']<=23) ? $_POST['hour2'] : ((isset($_GET['hour2']) && $_GET['hour2']>=0 && $_GET['hour2']<=23) ? $_GET['hour2'] : 23));
    $date2['min'] = $type ? 59 : ((isset($_POST['min2']) && $_POST['min2']>=0 && $_POST['min2']<=59) ? $_POST['min2'] : ((isset($_GET['min2']) && $_GET['min2']>=0 && $_GET['min2']<=59) ? $_GET['min2'] : 59));
    
    $date1['day'] = cal_days_in_month(CAL_GREGORIAN, $date1['month'], $date1['year'])<$date1['day'] ? cal_days_in_month(CAL_GREGORIAN, $date1['month'], $date1['year']) : $date1['day'];
    $date2['day'] = cal_days_in_month(CAL_GREGORIAN, $date2['month'], $date2['year'])<$date2['day'] ? cal_days_in_month(CAL_GREGORIAN, $date2['month'], $date2['year']) : $date2['day'];
    
    $time_from = mktime($date1['hour'], $date1['min'], 1, $date1['month'], $date1['day'], $date1['year']);
    $time_to = mktime($date2['hour'], $date2['min'], 59, $date2['month'], $date2['day'], $date2['year']);
    
    $types = array(0,1,2,3);
    switch ($type) {
    	case 0:
    		$sql_cols = "minute(from_unixtime(data.log_time)) as \"i\", hour(from_unixtime(data.log_time)) as \"G\", day(from_unixtime(data.log_time)) as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "i", "G", "j", "n", "Y"';
    		break;
    	case 1:
    		$sql_cols = "'0' as \"i\", hour(from_unixtime(data.log_time)) as \"G\", day(from_unixtime(data.log_time)) as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "G", "j", "n", "Y"';
    		break;
    	case 2:
    		$sql_cols = "'0' as \"i\", '0' as \"G\", day(from_unixtime(data.log_time)) as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "j", "n", "Y"';
    		break;
    	case 3:
    		$sql_cols = "'0' as \"i\", '0' as \"G\", '0' as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "n", "Y"';
    		break;
    	default:
    		$sql_cols = "'0' as \"i\", '0' as \"G\", '0' as \"j\", '0' as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "Y"';
    		$type = 2;
    }
    
    ...

    Писал "биллинг" попутно изучая пхп) скрипт вывода статистики

    Запостил: PycmaM, 11 Августа 2009

    Комментарии (2) RSS

    • Иногда мне кажется что даже перл красивый язык....
      Ответить
      • Почему кажется? Perl вообще красивый
        Ответить

    Добавить комментарий