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

    +40

    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
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    <?php
        if($_POST["phones_csv_load"]) {
            if(is_uploaded_file($_FILES["phones_csv"]["tmp_name"])) {
                if (($handle = fopen($_FILES["phones_csv"]["tmp_name"], "r")) !== FALSE) {
                    $linecount = (exec('perl -pe \'s/\r\n|\n|\r/\n/g\' ' . escapeshellarg($_FILES["phones_csv"]["tmp_name"]) . ' | wc -l')) - 1;
                    for($i = 0; $i <= $linecount; $i++) {
    		    $data = str_getcsv(iconv("cp1251", "utf8", stream_get_line($handle, 8000, "\n")), "\t");
    		    $datetime = explode(" ", $data[28]);
    		    $datetime["date"] = explode(".", $datetime[0]);
    		    $datetime["time"] = explode(":", $datetime[1]);
    		    $datetime["unix_time"] = mktime($datetime["time"][0], $datetime["time"][1], 0, $datetime["date"][1], $datetime["date"][0], "20".$datetime["date"][2]);
    		    $datetime["unix_time_ar"] = mktime($datetime["time"][0], $datetime["time"][1], 0, 0, 0, 0);
    		    $datetime["unix_day"] = mktime(0, 0, 0, $datetime["date"][1], $datetime["date"][0], "20".$datetime["date"][2]);
    		    sort($fullmassive[$datetime["unix_day"]][$data[20]][] = array($data[17]." ".$data[18], $datetime["unix_time"], $data[20], $datetime["unix_day"], $datetime["unix_time_ar"], "inout" => checkInOut($data[3]), md5($data[20]." ".$data[18].$datetime["unix_time"].$datetime["unix_time"]), date("d.m.Y H:i", $datetime["unix_time"]), date("H:i", $datetime["unix_time_ar"])), SORT_NATURAL);
                    }
    		foreach($fullmassive as $fullmassive_day) {
    		    foreach($fullmassive_day as $fullmassive_employee) {
    			usort($fullmassive_employee, 'invenDescSort');
    			$employee["uid"] = $fullmassive_employee[0][2];
    			$employee["in"] = $fullmassive_employee[0][1];
    			$employee["in_date"] = $fullmassive_employee[0][3];
    			$employee["in_time"] = $fullmassive_employee[0][4];
    			$employee["out"] = end($fullmassive_employee)[1];
    			$employee["out_date"] = mktime(0, 0, 0, date("n", end($fullmassive_employee)[1]), date("j", end($fullmassive_employee)[1]), date("Y", end($fullmassive_employee)[1]));
    			$employee["out_time"] = mktime(date("H", end($fullmassive_employee)[1]), date("i", end($fullmassive_employee)[1]), 0, 0, 0, 0);
    			$employee["name"] = $fullmassive_employee[0][0];
    			if($employee["in"] >= end($fullmassive_employee)[1]) $employee["in"] = mktime(10, 0, 0, date("n", $employee["in"]), date("j", $employee["in"]), date("Y", $employee["in"]));
    			else if(end($fullmassive_employee)[1] <= $employee["in"]) $employee["out"] = mktime(18, 0, 0, date("n", $employee["in"]), date("j", $employee["in"]), date("Y", $employee["in"]));
    			else
    			{
    			    if(mktime(date("H", $employee["in"]), 0, 0, 0, 0, 0) < mktime(12, 0, 0, 0, 0, 0)) {
    				$employee["out"] = mktime(18, 0, 0, date("n", $employee["in"]),	date("j", $employee["in"]), date("Y", $employee["in"]));
    			    }
    			    else {
    				$employee["in"] = mktime(10, 0, 0, date("n", $employee["in"]), date("j", $employee["in"]), date("Y", $employee["in"]));
    			    }
    			}
    			if($employee["in_time"] >= end($fullmassive_employee)[4]) $employee["in_time"] = mktime(10, 0, 0, date("n", $employee["in_time"]), date("j", $employee["in_time"]), date("Y", $employee["in_time"]));
    			else if(end($fullmassive_employee)[4] <= $employee["in_time"]) $employee["out_time"] = mktime(18, 0, 0, date("n", $employee["in_time"]), date("j", $employee["in_time"]), date("Y", $employee["in_time"]));
    			$employee["worktime"] = $employee["out"] - $employee["in"];
    			mysql_query("INSERT INTO `skud_stat` SET `name` = '".$employee["name"]."',
    								 `uid` = '".$employee["uid"]."',
    			    				         `arrival` = '".$employee["in"]."',
    								 `arrival_date` = '".$employee["in_date"]."',
    								 `arrival_time` = '".$employee["in_time"]."',
    								 `leaving` = '".$employee["out"]."',
    								 `leaving_date` = '".$employee["out_date"]."',
    								 `leaving_time` = '".$employee["out_time"]."',
    								 `worktime` = '".($employee["worktime"])."'");
    		    }
    		}
                    fclose($handle);
                }
            }
        }
        ?>

    Корпоративная Статистика (!). Читаю из CSV

    Запостил: varg242, 24 Января 2013

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

    • $linecount = (exec('perl -pe \'s/\r\n|\n|\r/\n/g\' ' . escapeshellarg($_FILES["phones_csv"]["tmp_name"]) . ' | wc -l')) - 1;
      Кроссплатформенность.

      Ну и массивы с датами, конечно.
      Ответить
      • > Кроссплатформенность.
        Для внутрикорпоративной странички сойдет. Никто там не будет перетаскивать ее с линуксового сервера на виндовый. Да и обратно, впрочем, тоже. К тому же perl и wc под виндой прекрасно себя чувствуют...
        Ответить
        • >Никто там не будет перетаскивать ее с линуксового сервера на виндовый.
          Да вы же оптимист!
          Ответить

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