tables_in.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. class tables_in
  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 create_table($id)
  10. {
  11. $a=0;
  12. try
  13. {
  14. $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
  15. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16. $db->exec("set names utf8");
  17. //echo('database connected ');
  18. }
  19. catch(PDOException $e)
  20. {
  21. echo $e->getMessage();
  22. return;
  23. }
  24. $user = $db->prepare("SELECT * FROM `tasks` WHERE `id`=:id");
  25. $user->execute(array('id'=>$id));
  26. $r=$user->fetchAll();
  27. return($r);
  28. }
  29. public function check_values($mas)
  30. {
  31. if(isset($mas['date_start']) and isset($mas['time_start']) and isset($mas['date_end']) and isset($mas['time_end']))
  32. {
  33. $mas['date_time_start']=$mas['date_start'].' '.$mas['time_start'].':00';
  34. $mas['date_time_end']=$mas['date_end'].' '.$mas['time_end'].':00';
  35. $mas['long']=1;
  36. }
  37. else
  38. return(1);
  39. //echo(preg_match("/^[0-9]{4}(\.|\-|\:|)(0[1-9]|1[012])(\.|\-|\:|)(0[1-9]|1[0-9]|2[0-9]|3[01]) ([01][0-9]|2[0-3])\:([0-5][0-9])\:([0-5][0-9])$/", $mas['date_time_start']));
  40. if(isset($mas['theme']) and isset($mas['type']) and isset($mas['place']) and isset($mas['comment']))
  41. {
  42. if($mas['theme']!='' and $mas['type']!='' and $mas['place']!='' and $mas['date_time_start']!='' and $mas['date_time_end']!='' and $mas['long']!='')
  43. {
  44. if (preg_match("/^[0-9]{4}(\.|\-|\:|)(0[1-9]|1[012])(\.|\-|\:|)(0[1-9]|1[0-9]|2[0-9]|3[01]) ([01][0-9]|2[0-3])\:([0-5][0-9])\:([0-5][0-9])$/", $mas['date_time_start'])
  45. and preg_match("/^[0-9]{4}(\.|\-|\:|)(0[1-9]|1[012])(\.|\-|\:|)(0[1-9]|1[0-9]|2[0-9]|3[01]) ([01][0-9]|2[0-3])\:([0-5][0-9])\:([0-5][0-9])$/", $mas['date_time_end']))
  46. {
  47. try
  48. {
  49. $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
  50. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  51. $db->exec("set names utf8");
  52. //echo('database connected ');
  53. }
  54. catch(PDOException $e)
  55. {
  56. echo $e->getMessage();
  57. return;
  58. }
  59. $ch = $db->prepare("SELECT `id` FROM `tasks` WHERE `date_time_start`<=:dt and `date_time_end`>=:dt");
  60. $ch->execute(array('dt'=>$mas['date_time_start']));
  61. $ch1=$ch->fetchAll();
  62. if(isset($ch1) and count($ch1)==0)
  63. {
  64. return(0);
  65. }
  66. else
  67. return(4);
  68. }
  69. else
  70. return(3);
  71. }
  72. else
  73. return(2);
  74. }
  75. else
  76. return(1);
  77. }
  78. public function add_task($mas)
  79. {
  80. try
  81. {
  82. $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
  83. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  84. $db->exec("set names utf8");
  85. //echo('database connected ');
  86. }
  87. catch(PDOException $e)
  88. {
  89. echo $e->getMessage();
  90. return;
  91. }
  92. $mas['date_time_start']=$mas['date_start'].' '.$mas['time_start'].':00';
  93. $mas['date_time_end']=$mas['date_end'].' '.$mas['time_end'].':00';
  94. //var_dump($_POST);
  95. $add = $db->prepare("INSERT INTO `tasks` (`theme`, `type`, `place`,`date_time_start`,`date_time_end`,`comment`,`status`) VALUES(:theme, :type, :place, :dts, :dte, :comment, 'undone')");
  96. $add->execute(array('theme'=>$mas['theme'],
  97. 'type'=>$mas['type'],
  98. 'place'=>$mas['place'],
  99. 'dts'=>$mas['date_time_start'],
  100. 'dte'=>$mas['date_time_end'],
  101. 'comment'=>$mas['comment']
  102. ));
  103. // $add = $db->prepare("INSERT INTO `tasks` (`theme`) VALUES(:theme);");
  104. //$add->execute(array('theme'=>$mas['theme']));
  105. }
  106. public function save_edits($mas, $id)
  107. {
  108. try
  109. {
  110. $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
  111. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  112. $db->exec("set names utf8");
  113. //echo('database connected ');
  114. }
  115. catch(PDOException $e)
  116. {
  117. echo $e->getMessage();
  118. return;
  119. }
  120. if(isset($mas['delete']) and $mas['delete']==='yes')
  121. {
  122. $save=$db->prepare("DELETE FROM `tasks` WHERE `id`=:id");
  123. $save->execute(array('id'=>$id));
  124. return;
  125. }
  126. $mas['date_time_start']=$mas['date_start'].' '.$mas['time_start'].':00';
  127. $mas['date_time_end']=$mas['date_end'].' '.$mas['time_end'].':00';
  128. $mas['long']=1;
  129. echo($mas['status']);
  130. $save=$db->prepare("UPDATE `tasks` SET `theme`=:theme, `type`=:type, `place`=:place, `date_time_start`=:dts,`date_time_end`=:dte,`comment`=:comment, `status`=:status WHERE `id`=:id");
  131. $save->execute(array('theme'=>$mas['theme'],
  132. 'type'=>$mas['type'],
  133. 'place'=>$mas['place'],
  134. 'dts'=>$mas['date_time_start'],
  135. 'dte'=>$mas['date_time_end'],
  136. 'comment'=>$mas['comment'],
  137. 'status'=>$mas['status'],
  138. 'id'=>$id
  139. ));
  140. }
  141. /*
  142. CREATE TABLE `tasks` (
  143. `id` int(10) AUTO_INCREMENT NOT NULL,
  144. `theme` varchar(255) NOT NULL,
  145. `type` varchar(255) NOT NULL,
  146. `place` varchar(255) DEFAULT NULL,
  147. `date_time_start` datetime DEFAULT NULL,
  148. `date_time_end` datetime DEFAULT NULL,
  149. `comment` varchar(255) DEFAULT NULL,
  150. `status` varchar(255) DEFAULT NULL,
  151. PRIMARY KEY (`id`)
  152. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  153. */
  154. }
  155. ?>