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

    +41

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static function getById( $id )
    {
      $model = new self;
      $data  = $model->load();
      foreach( $data AS $item ){
        if( $item->id == $id ){
          return $item;
        }
      }
      return null;
    }

    Нашел в текущем проекте.

    grdExh, 28 Января 2013

    Комментарии (2)
  2. PHP / Говнокод #12484

    +142

    1. 1
    2. 2
    if ($options->get('registrationSetup', 'requireDob')) {
    	// dob required

    Без ДОБ-а не пущу.

    DropWorld, 28 Января 2013

    Комментарии (1)
  3. PHP / Говнокод #12477

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function accuire($array = array()) {
            return $this->acquire($array);
        }
    
        public function acquire($array = array()) {

    Spell-master

    jfhs, 25 Января 2013

    Комментарии (4)
  4. PHP / Говнокод #12474

    +39

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    <?php
    set_time_limit(86400);
    $begin = new DateTime($_GET["min_date"]);
    $end = new DateTime($_GET["max_date"]);
    
    $begincp = clone $begin;
    $begincp_2 = clone $begin;
    
    $dt_diff = $begin->diff($end);
    $dt_diff = (int) $dt_diff->format("%a");
    
    for($i = 1; $i <= $dt_diff; $i++)
    {
        $begincp_2->modify("+1 day");  
       
        $q = mysql_query("SELECT * FROM `skud_stat` WHERE
                          `arrival` >= '".$begincp->getTimestamp()."' AND
                          `arrival` < '".$begincp_2->getTimestamp()."'
                           ORDER BY `name`");
        
        while($data = mysql_fetch_array($q))
        {
            $workers[$data["name"]][] = $data;
        }
        
        /* Сортировку */
        
        //uksort($workers, "strnatcasecmp");
        //ksort($workers);
        
       
        $coun = 0;
        
        $begincp->modify("+1 day");
    }
    
        /* быстрая сортировка */
        uksort($workers, "strnatcasecmp");
    ?>      
    
    <table class="table table-striped table-hover table-condensed skud-chart">
    	<thead></thead>
    	<tr>
    	  <th style="text-align: left">Имя</th>
    	  <?php
    	  $begin = new DateTime($_GET["min_date"]);
    	  $end = new DateTime($_GET["max_date"]);
    	  
    	  $bgcp = clone $begin;
    	  
    	  $dt_diff = $begin->diff($end);
    	  $dt_diff = (int) $dt_diff->format("%a");
    	  for($i = 1; $i <= $dt_diff; $i++)
    	  {
    	  ?>
    	  <th><?=date("d.m.Y", $bgcp->getTimestamp());?></th>
    	  <?php
    	  $bgcp->modify("+1 day");
    	  }
    	  ?>
    	</tr>
    	<?php
    	foreach($workers as $worker => $arr)
    	{
    	$begin_copy = clone $begin;
    	$begin_copy2 = clone $begin;	
    	?>
    	<tr>
    	  <td class="b"><?=$worker?></td>
    	<?php
    	for($i = 1; $i <= $dt_diff; $i++)
    	{
    	  $begin_copy2->modify("+1 day");
    	  foreach($arr as $day)
    	  {
    	    if($day["arrival"] > $begin_copy->getTimestamp() && $day["leaving"] < $begin_copy2->getTimestamp())
    	    {
    	    /* 28800 - рабочее время (8 часов)
    	       27000 - как погрешность (7 часов 30 минут)
    	    */
    	    ?>
    	    <td><?=date("H:i", $day["arrival"]);?> / <?=date("H:i", $day["leaving"]);?> / <?php if($day["worktime"] < 27000) { ?><b class="notenough"><?php } ?><?=date("H:i", $day["worktime"]);?><?php if($day["worktime"] < 21600) { ?></b><?php } ?></td>
    	    <?php
    	    $success_day = true;
    	    }
    	    else
    	    {
    	    ?>
    	    <!--<td>-</td>-->
    	    <?php
    	    }
    	  }
    	  if(!$success_day)
    	  {
    	  ?>
    	  <td class="naw">-</td>
    	  <?php
    	  }
    	  unset($success_day);
    	  //if($begin_copy->getTimestamp())

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

    varg242, 24 Января 2013

    Комментарии (2)
  5. 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)
  6. PHP / Говнокод #12462

    +48

    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
    $title = get_the_title();
    if ( $title == "Portfolio")  $data['sl_portfolio_style'] = "2 Columns Portfolio";
    if ( $title == "3 Columns Portfolio")  $data['sl_portfolio_style'] = "3 Columns Portfolio";
    if ( $title == "4 Columns Portfolio")  $data['sl_portfolio_style'] = "4 Columns Portfolio";
    if ( $title == "6 Columns Portfolio")  $data['sl_portfolio_style'] = "6 Columns Portfolio";
    if ( $title == "Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=4&paged=' . $paged );
    if ( $title == "4 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=8&paged=' . $paged );
    if ( $title == "6 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );
    if ( $title == "3 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=6&paged=' . $paged );
    if ( $title == "Portfolio Right Sidebar")  $data['sl_portfolio_style'] = "Portfolio with Sidebar";
    if ( $title == "Portfolio Right Sidebar")  $data['portfolio_sidebar_position'] = "Right Sidebar";
    if ( $title == "Portfolio Left Sidebar")  $data['sl_portfolio_style'] = "Portfolio with Sidebar";
    if ( $title == "Portfolio Left Sidebar")  $data['portfolio_sidebar_position'] = "Left Sidebar";
    
    if ( $title == "Portfolio Left Sidebar")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );
    if ( $title == "Portfolio Right Sidebar")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );

    "switch - case" - Не не слышал!
    И это в покупной теме для wordpress на тимфоресте.
    Стоимость темы - 45 уе...

    tsybulskyserg, 22 Января 2013

    Комментарии (8)
  7. PHP / Говнокод #12461

    +67

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class IntegerUtils
    {
        public static function isInteger($value)
        {
            return preg_match('/[0-9]+/', $value);
        }
    }

    Must have класс, который должен быть у каждого в его библиотеке "велоприседов". Поистине краткий, лаконичный, гениальный. Даешь 100% говнокод!

    SunnyMagadan, 22 Января 2013

    Комментарии (19)
  8. PHP / Говнокод #12458

    +57

    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
    for($i=0;$i<count($data_cor);$i++)
      {
        if(($data_cor[$i]['status'] == 1) && (($data_cor[$i]['number_packet'] == "9999998") || ($data_cor[$i]['number_packet'] == $iNumber)))
        { $_MY_LOG_counter_2 ++;
          foreach($data_cor[$i] as $key=>$value)
            $data_cor[$i][$key] = str_replace(";","",str_replace("\n","",str_replace("\r\n","",$value)));
    
          $d .= "\$Заявка\r\n";
          $d .= $data_cor[$i]['guid'].             ";".$data_cor[$i]['number_1c'].     ";".$data_cor[$i]['date_request'].      ";".$data_cor[$i]['number_request'].";"
                .$data_cor[$i]['contractor'].      ";".$data_cor[$i]['contractor_doc'].";".$data_cor[$i]['general_request_id'].";".$data_cor[$i]['date_dispatch'].";"
                .$data_cor[$i]['type_dispatch'].   ";".$data_cor[$i]['g_contactor_id'].";".$data_cor[$i]['address'].           ";"
                .$data_cor[$i]['station_name'].    ";".$data_cor[$i]['station_code'].  ";".$data_cor[$i]['status'].            ";"
                .$data_cor[$i]['transport_id'].    ";".$data_cor[$i]['contact_person'].";".$data_cor[$i]['phone_number'].      ";"
                .$data_cor[$i]['station_guid'].    ";".$data_cor[$i]['guid_cont_4'].   ";".$data_cor[$i]['transport_type'].    ";"
                .$data_cor[$i]['trailer'].         ";".$data_cor[$i]['driver'].        ";".$data_cor[$i]['driver_reserve'].    ";"
    			.$data_cor[$i]['address_delivery'].";".$data_cor[$i]['comment'];
    
    
    			$d .= "\r\n";
              
          if(count($data_cor['products']>0))
          {
            $d .= "#Товары\r\n";
            foreach($data_cor[$i]['products'] as $p)
              $d .= $p['guid'].";".$p['ob'].";".$p['get'].";".$p['doc_guid']."\r\n";
            
            $d .= "#Состояния\r\n";
            foreach($data_cor[$i]['statuses'] as $s)
              $d .= $s['status'].";".$s['date'].";".$s['user'].";".$s['type'].";".$s['guid']."\r\n";
          }
        }
      }

    CSV заказывали?
    Ах да, выгружаться могут разные данные, поэтому рядом лежат еще 4 говнофункции, отличающихся от этой только ключами массива.

    clauclauclau, 22 Января 2013

    Комментарии (3)
  9. PHP / Говнокод #12455

    +50

    1. 1
    if(!empty($filter['features']) && !empty($filter['features'])) ...

    Simpla CMS /api/Products.php

    Andretti, 21 Января 2013

    Комментарии (14)
  10. PHP / Говнокод #12448

    +47

    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
    function executeNewsRightRelated(sfWebRequest $request)
      {
        $siteId = $request->getParameter('site')->id;
        $tNewsList = $this->object->News;
    
        $newsList = array();
        foreach ($tNewsList as $news) {
    
          $ids = array();
          foreach ($news->Sites as $idModel) {
            $ids[] = $idModel->id;
          }
    
          if (in_array($siteId, $ids)) {
            $newsList[] = $news;
          }
        }
    
        $this->newsList = $newsList;
      }

    Skiv, 18 Января 2013

    Комментарии (7)