tables_out.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. class tables
  3. {
  4. private $way_to_files = '/home/last_php_task13.hostfl.ru/public_html';
  5. private $dbname='last_php_task13';
  6. private $host='127.0.0.1';
  7. private $password='iVubC3J5';
  8. private $user='last_php_task13';
  9. public function aaaa()
  10. {
  11. echo('aaAaaa');
  12. }
  13. public function create_table($mas)
  14. {
  15. $a=0;
  16. try
  17. {
  18. $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
  19. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  20. $db->exec("set names utf8");
  21. //echo('database connected ');
  22. }
  23. catch(PDOException $e)
  24. {
  25. echo $e->getMessage();
  26. return;
  27. }
  28. $number = $db->query("SELECT MAX(`id`) FROM `tasks` WHERE 1");
  29. $r=$number->fetch();
  30. $n=$r['MAX(`id`)'];
  31. $nnnaa=0;
  32. $addit='';
  33. if(isset($mas['type_of_tasks']))
  34. {
  35. if($mas['type_of_tasks']=='Made')
  36. $addit=' AND `status`="done"';
  37. if($mas['type_of_tasks']=='NotMade')
  38. $addit=' AND `status`="undone" AND DATE(`date_time_end`)<NOW()';
  39. }
  40. if(isset($mas['time_of_tasks']))
  41. {
  42. if($mas['time_of_tasks']=='OnDate' and isset($mas['date_of_tasks']))
  43. {
  44. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=:date".$addit);
  45. $nnnaa=1;
  46. }
  47. else
  48. if($mas['time_of_tasks']=='LastWeek')
  49. {
  50. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)>=NOW()-INTERVAL 7 DAY AND DATE(`date_time_start`)<NOW()".$addit);
  51. }
  52. else
  53. if($mas['time_of_tasks']=='LastMonth')
  54. {
  55. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)>=NOW()-INTERVAL 1 MONTH AND DATE(`date_time_start`)<NOW()".$addit);
  56. }
  57. else
  58. if($mas['time_of_tasks']=='Today')
  59. {
  60. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=NOW()".$addit);
  61. }
  62. else
  63. if($mas['time_of_tasks']=='AllTime')
  64. {
  65. $check = $db->prepare("SELECT * FROM `tasks` WHERE `id`=:id".$addit);
  66. }
  67. else
  68. if($mas['time_of_tasks']=='NextMonth')
  69. {
  70. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)<=NOW()+INTERVAL 1 MONTH AND DATE(`date_time_start`)>NOW()".$addit);
  71. }
  72. else
  73. if($mas['time_of_tasks']=='NextWeek')
  74. {
  75. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)<=NOW()+INTERVAL 7 DAY AND DATE(`date_time_start`)>NOW()".$addit);
  76. }
  77. else
  78. if($mas['time_of_tasks']=='Yesterday')
  79. {
  80. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=NOW()-INTERVAL 1 DAY".$addit);
  81. }
  82. else
  83. if($mas['time_of_tasks']=='Tomorrow')
  84. {
  85. $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=NOW()+INTERVAL 1 DAY".$addit);
  86. }
  87. }
  88. else
  89. $check = $db->prepare("SELECT * FROM `tasks` WHERE `id`=:id");
  90. for($id=1; $id<=$n; $id++)
  91. {
  92. if($nnnaa===0)
  93. $check->execute(array('id'=>$id));
  94. else
  95. $check->execute(array('id'=>$id, 'date'=>$mas['time_of_task']));
  96. $mas_of_file = $check->fetch(PDO::FETCH_ASSOC);
  97. if(isset($mas_of_file['id']))
  98. {
  99. $a=$a+1;
  100. if($a%2==1)
  101. echo '<tr background-color=grey>';
  102. else
  103. echo '<tr>';
  104. echo '<td>'.$mas_of_file['id'].'</td>
  105. <td>'.$mas_of_file['theme'].'</td>
  106. <td>'.$mas_of_file['type'].'</td>
  107. <td>'.$mas_of_file['place'].'</td>
  108. <td>'.substr($mas_of_file['date_time_start'],0,-3).'</td>
  109. <td>'.substr($mas_of_file['date_time_end'],0,-3).'</td>
  110. <td>'.$mas_of_file['comment'].'</td>
  111. <td>'.$mas_of_file['status'].'</td>
  112. <td><input type="radio" value="'.$mas_of_file['id'].'" name="change">редактировать</td>
  113. </tr>';
  114. }
  115. }
  116. }
  117. /*
  118. CREATE TABLE `tasks` (
  119. `id` int(10) AUTO_INCREMENT NOT NULL,
  120. `theme` varchar(255) NOT NULL,
  121. `type` varchar(255) NOT NULL,
  122. `place` varchar(255) DEFAULT NULL,
  123. `date_time` datetime DEFAULT NULL,
  124. `long` int(10) DEFAULT NULL,
  125. `comment` varchar(255) DEFAULT NULL,
  126. PRIMARY KEY (`id`)
  127. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  128. */
  129. }
  130. ?>