dmitriy.kosogorov@yandex.ru 3 年之前
當前提交
9065ba7220
共有 6 個文件被更改,包括 586 次插入0 次删除
  1. 93 0
      calender.php
  2. 101 0
      edit.php
  3. 0 0
      style.css
  4. 172 0
      tables_in.php
  5. 135 0
      tables_out.php
  6. 85 0
      task.php

+ 93 - 0
calender.php

@@ -0,0 +1,93 @@
+<DOCTYPE html>
+
+<head>
+<meta http-equiv = "content-type" charset = utf-8" > 
+
+<meta name = "description" content = "calender" >
+
+<meta name = "keywords" content = "calender">
+
+<title>php1</title>
+
+<link rel="stylesheet" type="text/css" href="style.css">
+</head>
+<?php
+
+	include_once ('tables_out.php');
+	session_start();
+	$tablo=new tables();
+	//var_dump($_POST);
+	if(isset($_POST['change']))
+  {
+    session_start();
+    $_SESSION['id']=($_POST['change']);
+    header('Location:edit.php');
+  }
+
+?>
+<html style="height:100%;">
+
+<body style="background-color: #AAAAAA; min-height:100%;">
+
+<form action="<?php $_PHP_SELF ?>" method="post">
+<div style="background-color:#FFFFFF; margin-left:10%; margin-right:10%; padding:3%; height:100%;">    
+
+<select name="type_of_tasks" value="<?php if (isset($_POST['type_of_tasks'])) { echo $_POST['type_of_tasks']; } ?>">
+<option value="floating">Текущие задачи</option>
+<option value="NotMade">Просроченные задачи</option>
+<option value="Made">Выполненные задачи</option>
+</select>
+                      
+<select name="time_of_tasks" value="<?php if (isset($_POST['time_if_tasks'])) { echo $_POST['time_of_tasks']; } else echo('Today'); ?>" onchange="changes(this)">
+<option value="AllTime">Всё время</option>
+<option value="LastMonth">Прошлый месяц</option>
+<option value="LastWeek">Прошлая неделя</option>
+<option value="Yesterday">Вчера</option>
+<option value="Today" default>Сегодня</option>
+<option value="Tomorrow">Завтра</option>
+<option value="NextWeek">Следующая неделя</option>
+<option value="NextMonth">Следующий месяц</option>
+<option value="OnDate">По дате</option>
+</select>
+
+<label for="date_of_tasks"> дата</label>
+<input type="date" name ="date_of_tasks" id="date_of_tasks" disabled></td>
+
+                                                           <button onclick="location.reload()">поиск</button>
+<include type="radio" name="change" value="-1">
+
+<table border=1>
+<th>Список заданий</th>
+<tr>
+<td>id</td><td>Тема</td><td>Тип</td><td>Место</td><td>Дата и время начала</td><td>Дата и время конца</td><td>Комментарии</td><td>Статус</td><td>Изменить</td>
+</tr>
+<?php
+$tablo->create_table($_POST);
+?>
+
+</table>
+<a href="task.php">Добавить задание</a>
+<button onclick="update()" style="margin-left:20%">Редактировать</button>
+</div>
+</form>
+
+</body>
+<script>
+function changes(obj)
+{
+target=document.getElementsByName('date_of_tasks')[0];
+if(obj.value=='OnDate')
+target.disabled=false;
+else
+target.disabled=true;
+}
+function update()
+{
+int i=0;
+upla=document.getElementsByName("change")
+for(i=0;i<upla.lenght;i++)
+if(upla[i].checked)
+location.reload()
+}
+</script>
+</html>

+ 101 - 0
edit.php

@@ -0,0 +1,101 @@
+<DOCTYPE html>
+
+<head>
+<meta http-equiv = "content-type" charset = utf-8" > 
+
+<meta name = "description" content = "task_add" >
+
+<meta name = "keywords" content = "task_add">
+
+<title>php1</title>
+
+<link rel="stylesheet" type="text/css" href="style.css">
+</head>
+<?php
+session_start();
+$a=0;
+include_once('tables_in.php');
+$main=new tables_in();
+$a=$main->create_table($_SESSION['id']);
+$b=$main->check_values($_POST);
+$a[0]['date_time_start']=substr($a[0]['date_time_start'],0,-3);
+$a[0]['date_time_end']=substr($a[0]['date_time_end'],0,-3);
+$_POST['id']=1;
+if($b==0 || $b==4)
+  if(isset($_POST))
+  	$main->save_edits($_POST,$_SESSION['id']);
+ 
+?>
+<html style="height:100%;">
+
+<body style="background-color: #AAAAAA; min-height:100%;">
+<div style="background-color:#FFFFFF; margin-left:10%; margin-right:10%; padding:3%; height:100%;">                                                       
+<a href="calender.php"> Вернуться к списку </a>
+<form action = "<?php $_PHP_SELF ?>" method="post">
+<table style="border: solid-black 1px;">
+<th>Редактировать задачу</th>
+<tr>
+<td><label for="theme"> Тема: </label></td>
+<td><input type="text" name ="theme" id="theme" value="<?php if (isset($_POST['theme']) and $_POST['theme']!='') echo $_POST['theme']; else echo $a[0]['theme']; ?>"></td>
+</tr>
+<tr>
+<td><label for="type"> Тип:</label></td>
+<td><input type="text" name ="type" id="type" value="<?php if (isset($_POST['type']) and $_POST['type']!='') echo $_POST['type']; else echo $a[0]['type']; ?>"></td>
+</tr>
+<tr>
+<td><label for="place"> Место:</label></td>
+<td><input type="text" name ="place" id="place" value="<?php if (isset($_POST['place']) and $_POST['place']!='') echo $_POST['place']; else echo $a[0]['place']; ?>"></td>
+</tr>
+<tr>
+<td><label for="date_start"> Дата начала:</label></td>
+<td><input type="date" name ="date_start" id="date_start" value="<?php if (isset($_POST['date_start']) and $_POST['date_start']!='') echo $_POST['date_start']; else echo substr($a[0]['date_time_start'],0,10); ?>"></td>
+</tr>
+<tr>
+<td><label for="time_start"> Время начала:</label></td>
+<td><input type="time" name ="time_start" id="time_start" value="<?php if (isset($_POST['time_start']) and $_POST['time_start']!='') echo $_POST['time_start']; else echo substr($a[0]['date_time_start'],11,8); ?>"></td>
+</tr>
+<tr>
+<td><label for="date_end"> Дата начала:</label></td>
+<td><input type="date" name ="date_end" id="date_end" value="<?php if (isset($_POST['date_end']) and $_POST['date_end']!='') echo $_POST['date_end']; else echo substr($a[0]['date_time_end'],0,10); ?>"></td>
+</tr>
+<tr>
+<td><label for="time_end"> Время начала:</label></td>
+<td><input type="time" name ="time_end" id="time_end" value="<?php if (isset($_POST['time_end']) and $_POST['time_end']!='') echo $_POST['time_end']; else echo substr($a[0]['date_time_end'],11,8); ?>"></td>
+</tr>
+<tr>
+<td>Направление</td><td><select name="status" value="<?php if (isset($_POST['status']) and $_POST['status']!='') echo $_POST['status']; else echo $a[0]['status']; ?>">
+<option value="done">done</option>
+<option value="undone">undone</option>
+</select>
+</tr>
+<tr>
+<td>Удалить?</td><td><select name="delete" value="<?php if (isset($_POST['delete']) and $_POST['delete']!='') echo $_POST['delete']; else echo $a[0]['delete']; ?>">
+<option value="no">ни в коем случае!</option>
+<option value="yes">обязательно!</option>
+</select>
+</tr>
+<tr>
+<td><label for="comment"> Комментарий:</label></td>
+<td><textarea rows="4" name ="comment" id="comment"><?php if (isset($_POST['comment']) and $_POST['comment']!='') echo $_POST['comment']; else echo $a[0]['comment']; ?></textarea></td>
+</tr>
+<tr>
+<td text-align:center colspan="2"><input type="submit" value="применить изменения" name="send"></td>
+</tr>
+<?php
+if($b==1)
+  echo('Буффер пустой');
+if($b==2)
+  echo('Заполните все поля');
+if($b==3)
+  echo('Неверный формат даты');
+
+?>
+</tr></td>
+                                                                               
+</tr>
+</table>
+</form>
+</div>
+</body>
+
+</html>

+ 0 - 0
style.css


+ 172 - 0
tables_in.php

@@ -0,0 +1,172 @@
+<?php
+class tables_in
+{
+  private $way_to_files = '/home/last_php_task13.hostfl.ru/public_html';
+  private $dbname='last_php_task13';
+  private $host='127.0.0.1';
+  private $password='iVubC3J5';
+  private $user='last_php_task13';
+
+public function create_table($id)
+{
+	$a=0;
+        try 
+      {
+          $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
+          $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+          $db->exec("set names utf8");
+      		//echo('database connected ');
+      }
+    catch(PDOException $e) 
+    	{
+      		echo $e->getMessage();
+      		return;
+    	}
+  
+  $user = $db->prepare("SELECT * FROM `tasks` WHERE `id`=:id");
+  $user->execute(array('id'=>$id));
+  $r=$user->fetchAll();
+  	return($r);
+}
+
+
+public function check_values($mas)
+{
+  if(isset($mas['date_start']) and isset($mas['time_start']) and isset($mas['date_end']) and isset($mas['time_end']))
+  { 
+    $mas['date_time_start']=$mas['date_start'].' '.$mas['time_start'].':00';
+  	$mas['date_time_end']=$mas['date_end'].' '.$mas['time_end'].':00';
+  	$mas['long']=1;
+  }
+  else
+    return(1);
+  //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']));
+	if(isset($mas['theme']) and isset($mas['type']) and isset($mas['place']) and isset($mas['comment']))
+	{
+		
+		if($mas['theme']!='' and $mas['type']!='' and $mas['place']!='' and $mas['date_time_start']!='' and $mas['date_time_end']!='' and $mas['long']!='')
+		{
+			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'])
+				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']))
+			{
+				try 
+				  {
+					  $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
+					  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+					  $db->exec("set names utf8");
+						//echo('database connected ');
+				  }
+				catch(PDOException $e) 
+				{
+					echo $e->getMessage();
+					return;
+				}
+
+				$ch = $db->prepare("SELECT `id` FROM `tasks` WHERE `date_time_start`<=:dt and `date_time_end`>=:dt");
+				$ch->execute(array('dt'=>$mas['date_time_start']));
+				$ch1=$ch->fetchAll();
+				if(isset($ch1) and count($ch1)==0)
+				{
+					return(0);
+				}
+				else
+					return(4);
+			}
+			else
+				return(3);
+		}
+		else
+			return(2);
+	}
+	else
+		return(1);
+}
+
+public function add_task($mas)
+{
+	try 
+	{
+		  $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
+		  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+		  $db->exec("set names utf8");
+			//echo('database connected ');
+	}
+	catch(PDOException $e) 
+	{
+		echo $e->getMessage();
+		return;
+	}
+  $mas['date_time_start']=$mas['date_start'].' '.$mas['time_start'].':00';
+  $mas['date_time_end']=$mas['date_end'].' '.$mas['time_end'].':00';
+  //var_dump($_POST);
+  
+	$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')");
+	$add->execute(array('theme'=>$mas['theme'],
+                      'type'=>$mas['type'],
+                      'place'=>$mas['place'],
+                      'dts'=>$mas['date_time_start'],
+                      'dte'=>$mas['date_time_end'],
+                      'comment'=>$mas['comment']
+                     ));				
+                     
+  
+  
+  
+  
+  
+  
+ // $add = $db->prepare("INSERT INTO `tasks` (`theme`) VALUES(:theme);");
+	//$add->execute(array('theme'=>$mas['theme']));
+}
+  
+  
+public function save_edits($mas, $id)
+{
+  try 
+	{
+		  $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
+		  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+		  $db->exec("set names utf8");
+			//echo('database connected ');
+	}
+	catch(PDOException $e) 
+	{
+		echo $e->getMessage();
+		return;
+	}
+  if(isset($mas['delete']) and $mas['delete']==='yes')
+  {
+    $save=$db->prepare("DELETE FROM `tasks` WHERE `id`=:id");
+    $save->execute(array('id'=>$id));
+    return;
+  }
+  $mas['date_time_start']=$mas['date_start'].' '.$mas['time_start'].':00';
+  $mas['date_time_end']=$mas['date_end'].' '.$mas['time_end'].':00';
+  $mas['long']=1;
+  echo($mas['status']);
+  $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");
+  $save->execute(array('theme'=>$mas['theme'], 
+                       'type'=>$mas['type'], 
+                       'place'=>$mas['place'],
+                       'dts'=>$mas['date_time_start'],
+                       'dte'=>$mas['date_time_end'],
+                     	 'comment'=>$mas['comment'],
+                       'status'=>$mas['status'],
+                       'id'=>$id
+                ));
+}
+  /*
+  CREATE TABLE `tasks` (
+  `id` int(10) AUTO_INCREMENT NOT NULL,
+  `theme` varchar(255) NOT NULL,
+  `type` varchar(255) NOT NULL,
+  `place` varchar(255) DEFAULT NULL,
+  `date_time_start` datetime DEFAULT NULL,
+  `date_time_end` datetime DEFAULT NULL,
+  `comment` varchar(255) DEFAULT NULL,
+  `status` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+*/
+}
+?>

+ 135 - 0
tables_out.php

@@ -0,0 +1,135 @@
+<?php
+
+class tables
+{
+  private $way_to_files = '/home/last_php_task13.hostfl.ru/public_html';
+  private $dbname='last_php_task13';
+  private $host='127.0.0.1';
+  private $password='iVubC3J5';
+  private $user='last_php_task13';
+public function aaaa()
+{
+  echo('aaAaaa');
+}
+
+public function create_table($mas)
+	{
+	$a=0;
+   try 
+      {
+          $db = new PDO("mysql:host=$this->host;dbname=$this->dbname", $this->user, $this->password);
+          $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+          $db->exec("set names utf8");
+      		//echo('database connected ');
+      }
+    catch(PDOException $e) 
+    	{
+      		echo $e->getMessage();
+      		return;
+    	}
+  
+  	$number = $db->query("SELECT MAX(`id`) FROM `tasks` WHERE 1");
+  	$r=$number->fetch();
+    	$n=$r['MAX(`id`)'];
+    $nnnaa=0;
+    $addit='';
+  	if(isset($mas['type_of_tasks']))
+    {
+      if($mas['type_of_tasks']=='Made')
+        $addit=' AND `status`="done"';
+            if($mas['type_of_tasks']=='NotMade')
+        $addit=' AND `status`="undone" AND DATE(`date_time_end`)<NOW()';
+    }
+      if(isset($mas['time_of_tasks']))
+        {
+          if($mas['time_of_tasks']=='OnDate' and isset($mas['date_of_tasks']))
+          {
+            $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=:date".$addit);
+            $nnnaa=1;
+
+          }
+        	else
+          if($mas['time_of_tasks']=='LastWeek')
+          {
+              $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);
+          }
+        	else
+          if($mas['time_of_tasks']=='LastMonth')
+          {
+              $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);
+          }
+        else
+          if($mas['time_of_tasks']=='Today')
+        	{
+          	$check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=NOW()".$addit);
+        	}
+        	else
+            if($mas['time_of_tasks']=='AllTime')
+          {
+            $check = $db->prepare("SELECT * FROM `tasks` WHERE `id`=:id".$addit);
+          }
+        else
+          if($mas['time_of_tasks']=='NextMonth')
+          {
+              $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);
+          }
+        else
+          if($mas['time_of_tasks']=='NextWeek')
+          {
+              $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);
+          }
+        else
+          if($mas['time_of_tasks']=='Yesterday')
+          {
+              $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=NOW()-INTERVAL 1 DAY".$addit);
+          }
+        else
+          if($mas['time_of_tasks']=='Tomorrow')
+          {
+              $check=$db->prepare("SELECT * FROM `tasks` WHERE `id`=:id and DATE(`date_time_start`)=NOW()+INTERVAL 1 DAY".$addit);
+          }
+        }
+        else
+          $check = $db->prepare("SELECT * FROM `tasks` WHERE `id`=:id");
+		for($id=1; $id<=$n; $id++)
+		{
+      if($nnnaa===0)
+      		$check->execute(array('id'=>$id));
+      else
+        	$check->execute(array('id'=>$id, 'date'=>$mas['time_of_task']));
+			$mas_of_file = $check->fetch(PDO::FETCH_ASSOC);
+			if(isset($mas_of_file['id']))
+			{
+			  $a=$a+1;
+			  if($a%2==1)
+				  echo '<tr background-color=grey>';
+			  else
+				  echo '<tr>';
+			  echo '<td>'.$mas_of_file['id'].'</td>
+              <td>'.$mas_of_file['theme'].'</td>
+              <td>'.$mas_of_file['type'].'</td>
+              <td>'.$mas_of_file['place'].'</td>
+              <td>'.substr($mas_of_file['date_time_start'],0,-3).'</td>
+              <td>'.substr($mas_of_file['date_time_end'],0,-3).'</td>
+              <td>'.$mas_of_file['comment'].'</td>
+              <td>'.$mas_of_file['status'].'</td>
+              <td><input type="radio" value="'.$mas_of_file['id'].'" name="change">редактировать</td>
+              </tr>';
+			}
+  		
+		}
+	}
+  /*
+  CREATE TABLE `tasks` (
+  `id` int(10) AUTO_INCREMENT NOT NULL,
+  `theme` varchar(255) NOT NULL,
+  `type` varchar(255) NOT NULL,
+  `place` varchar(255) DEFAULT NULL,
+  `date_time` datetime DEFAULT NULL,
+  `long` int(10) DEFAULT NULL,
+  `comment` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+*/
+}
+?>

+ 85 - 0
task.php

@@ -0,0 +1,85 @@
+<DOCTYPE html>
+
+<head>
+<meta http-equiv = "content-type" charset = utf-8" > 
+
+<meta name = "description" content = "task_add" >
+
+<meta name = "keywords" content = "task_add">
+
+<title>php1</title>
+
+<link rel="stylesheet" type="text/css" href="style.css">
+</head>
+<?php
+$a=0;
+include_once('tables_in.php');
+$main=new tables_in();
+$a=$main->check_values($_POST);
+if($a==0)
+  $main->add_task($_POST);
+?>
+<html style="height:100%;">
+
+<body style="background-color: #AAAAAA; min-height:100%;">
+<div style="background-color:#FFFFFF; margin-left:10%; margin-right:10%; padding:3%; height:100%;">                                                       
+<a href="calender.php"> Вернуться к списку </a>
+<form action = "<?php $_PHP_SELF ?>" method="post">
+<table style="border: solid-black 1px;">
+<th>Новая задача</th>
+<tr>
+<td><label for="theme"> Тема: </label></td>
+<td><input type="text" name ="theme" id="theme" value="<?php if (isset($_POST['theme'])) { echo $_POST['theme']; } ?>"></td>
+</tr>
+<tr>
+<td><label for="type"> Тип:</label></td>
+<td><input type="text" name ="type" id="type" value="<?php if (isset($_POST['type'])) { echo $_POST['type']; } ?>"></td>
+</tr>
+<tr>
+<td><label for="place"> Место:</label></td>
+<td><input type="text" name ="place" id="place" value="<?php if (isset($_POST['place'])) { echo $_POST['place']; } ?>"></td>
+</tr>
+<tr>
+<td><label for="date_start"> Дата начала:</label></td>
+<td><input type="date" name ="date_start" id="date_start" value="<?php if (isset($_POST['date_start'])) { echo $_POST['date_start']; } ?>"></td>
+</tr>
+<tr>
+<td><label for="time_start"> Время начала:</label></td>
+<td><input type="time" name ="time_start" id="time_start" value="<?php if (isset($_POST['time_start']))  echo $_POST['time_start']; else echo('00:00');  ?>"></td>
+</tr>
+<tr>
+<td><label for="date_end"> Дата начала:</label></td>
+<td><input type="date" name ="date_end" id="date_end" value="<?php if (isset($_POST['date_end'])) { echo $_POST['date_end']; } ?>"></td>
+</tr>
+<tr>
+<td><label for="time_end"> Время начала:</label></td>
+<td><input type="time" name ="time_end" id="time_end" value="<?php if (isset($_POST['time_end'])) { echo $_POST['time_end']; } else echo('00:00'); ?>"></td>
+</tr>
+<tr>
+<tr>
+<td><label for="comment"> Комментарий:</label></td>
+<td><textarea rows="4" name ="comment" id="comment" value="<?php if (isset($_POST['comment'])) { echo $_POST['comment']; } ?>"></textarea></td>
+</tr>
+</tr>
+<tr>
+<td text-align:center colspan="2"><input type="submit" value="Send" name="send"></td>
+<tr><td>
+<?php
+if($a==1)
+  echo('Ошибка ввода');
+if($a==2)
+  echo('Заполните все поля');
+if($a==3)
+  echo('Неверный формат даты');
+if($a==4)
+  echo('Время занято');
+?>
+</tr></td>
+                                                                               
+</tr>
+</table>
+</form>
+</div>
+</body>
+
+</html>