Subversion Repositories dreq

Compare Revisions

Ignore whitespace Rev 2 → Rev 3

/trunk/img/bg.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/img/bg.gif
New file
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/index.php
===================================================================
--- trunk/index.php (revision 0)
+++ trunk/index.php (revision 3)
@@ -0,0 +1,30 @@
+<?php
+require 'lib/init.php'?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Таблица запросов</title>
+ <link rel="stylesheet" type="text/css" href="style.css">
+ </head>
+ <body>
+ <h1>Таблица запросов AltLUG</h1>
+ <?php
+ $id=(int)$_GET['id'];
+ switch($_GET['act']){
+ case 'add':
+ echo $core->ShowAddForm();
+ break;
+ case 'show':
+ echo $core->ShowRequest($id);
+ break;
+ case 'make':
+ echo $core->ShowMakeForm($id);
+ break;
+ default:
+ echo "<div class='add'><a href='index.php?act=add' class='add'>Добавить запрос</a></div>";
+ echo $core->ListRequest();
+ }
+ ?>
+ </body>
+</html>
/trunk/index.php
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/db_sql.sql
===================================================================
--- trunk/db_sql.sql (revision 0)
+++ trunk/db_sql.sql (revision 3)
@@ -0,0 +1,44 @@
+-- phpMyAdmin SQL Dump
+-- version 3.1.2deb1
+-- http://www.phpmyadmin.net
+--
+-- Хост: localhost
+-- Время создания: Июн 28 2009 г., 23:46
+-- Версия сервера: 5.0.75
+-- Версия PHP: 5.2.6-3ubuntu4.1
+
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+
+--
+-- База данных: `dreq`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Структура таблицы `requests`
+--
+
+CREATE TABLE IF NOT EXISTS `requests` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` varchar(60) collate utf8_unicode_ci NOT NULL,
+ `desk` text collate utf8_unicode_ci NOT NULL,
+ `status` tinyint(1) NOT NULL,
+ `date` date NOT NULL,
+ `author` varchar(20) collate utf8_unicode_ci NOT NULL default 'anonymous',
+ `url` varchar(100) collate utf8_unicode_ci NOT NULL,
+ `comment` text collate utf8_unicode_ci NOT NULL,
+ `type` int(11) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
+
+--
+-- Дамп данных таблицы `requests`
+--
+
Index: trunk/process.php
===================================================================
--- trunk/process.php (revision 0)
+++ trunk/process.php (revision 3)
@@ -0,0 +1,30 @@
+<?php
+require './lib/init.php';
+function secure($str){
+ $str=mysql_real_escape_string($str);
+ return strip_tags($str);
+}
+$name=secure($_POST['name']);
+$desk=secure($_POST['desk']);
+$type=secure($_POST['type']);
+$author=secure($_POST['author']);
+$id=(int)$_POST['id'];
+
+if($_POST['type']=='file'){
+ $type='1';
+}else{
+ $type='0';
+}
+
+switch ($_POST['act']){
+ case 'add':
+ $id=$core->AddRequest($name, $desk, $author, $type);
+ break;
+ case 'make':
+ $core->MakeRequest($id, $name, $desk);
+ break;
+ default:
+ die();
+}
+header('Location: index.php?act=show&id='.$id);
+?>
Index: trunk/lib/init.php
===================================================================
--- trunk/lib/init.php (revision 0)
+++ trunk/lib/init.php (revision 3)
@@ -0,0 +1,6 @@
+<?php
+require 'config.php';
+require 'lib.php';
+mysql_set_charset('utf8');
+$core = new request;
+?>
/trunk/lib/init.php
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/lib/config.php
===================================================================
--- trunk/lib/config.php (revision 0)
+++ trunk/lib/config.php (revision 3)
@@ -0,0 +1,6 @@
+<?php
+//подключение к БД: хост, юзер, пароль
+mysql_connect('localhost', 'USER', 'PASSWORD') or die("MySQL connect error!");
+//имя БД:БД
+mysql_select_db('dreq');
+?>
/trunk/lib/config.php
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/lib/lib.php
===================================================================
--- trunk/lib/lib.php (revision 0)
+++ trunk/lib/lib.php (revision 3)
@@ -0,0 +1,123 @@
+<?php
+/**
+ * Description of lib
+ *
+ * @author Sinegovsky Ivan
+ */
+
+class request {
+ function ListRequest(){//возвращает таблицу список запросов
+ switch ($_GET['order']){
+ case 'named':
+ $order="ORDER BY `name` DESC";
+ break;
+ case 'nameu':
+ $order="ORDER BY `name` ASC";
+ break;
+ case 'authord':
+ $order="ORDER BY `author` DESC";
+ break;
+ case 'authoru':
+ $order="ORDER BY `author` ASC";
+ break;
+ case 'statusd':
+ $order="ORDER BY `status` DESC ";
+ break;
+ case 'statusu':
+ $order="ORDER BY `status` ASC ";
+ break;
+ default:
+ $order="ORDER BY `status` ASC ";
+ }
+ $rez="<table width='100%'><tr><td><b><a href='index.php?order=authord'>&#8595;</a>Заказчик<a href='index.php?order=authoru'>&#8593;</a></b></td><td><b><a href='index.php?order=named'>&#8595;</a> Название<a href='index.php?order=nameu'>&#8593;</a></b></td><td><b><a href='index.php?order=statusd'>&#8595;</a> Статус<a href='index.php?order=statusu'>&#8593;</a></b></td><td><b>Действия</b></td></tr>";
+ $query='SELECT * FROM `requests` '.$order;
+ $result=mysql_query($query);
+ while($row=mysql_fetch_array($result)){
+ $id=$row['id'];
+ if($row['type']==0){$type='[статья]';}else{$type='[файл]';}
+ $name="<a href='index.php?act=show&id=".$id."'>".$type." ".$row['name']."</a>";
+ if ($row['status']){
+ $st="<span class='ok'>Готов</span>";
+ $act="<a href='".$row['url']."'>Получить</a>";
+ }else{
+ $st="<span class='need'>Требуется</span>";
+ $act="<a href='index.php?act=make&id=".$id."'>Выполнить</a>";
+ }
+ //if($mode=='admin'){$act.=" <a style='color:red;text-decoration:none;' href='index.php?act=delete&id=".$id."'>[удалить]</a>";}
+ $rez.="<tr><td>".$row['author']."</td><td>".$name."</td>";
+ $rez.="<td>".$st."</td><td>".$act."</td></tr>";
+ }
+ $rez.="</table>";
+ echo $rez;
+ }
+
+ function ShowRequest($id){
+ $query='SELECT * FROM `requests` WHERE id='.$id;
+ $result=mysql_query($query);
+ $data=mysql_fetch_array($result);
+ if(empty($data['id'])){$rez="<div class='add'>Указанный запрос не найден!</div>";}
+ else{
+ $desk=$data['desk'];
+ if(empty($desk)){$desk="&nbsp";}
+ if($data['type']==0){$type="статья";}else{$type="файл";}
+ $rez="<h2>Запрос №".$data['id']."</h2>";
+ $rez.="<table>";
+ $rez.="<tr><td>Название</td><td>".$data['name']."</td></tr>";
+ $rez.="<tr><td>Тип</td><td>".$type."</td></tr>";
+ $rez.="<tr><td>Описание</td><td>".$desk."</td></tr>";
+ $rez.="<tr><td>Дата</td><td>".$data['date']."</td></tr>";
+ $rez.="<tr><td>Автор</td><td>".$data['author']."</td></tr>";
+ if($data['status']!=0){
+ $rez.="<tr><td>Ссылка</td><td><a href='".$data['url']."'>".$data['url']."</a></td></tr>";
+ $rez.="<tr><td>Комментарий</td><td>".$data['comment']."</td></tr>";
+ }
+ else{
+ $rez.="<td colspan='2'><a href='index.php?act=make&id=".$id."'>Выполнить</a></td>";
+ }
+ $rez.="</table>";
+ }
+ $rez.="<div class='add'><a href='index.php'>Назад</a></div>";
+ echo $rez;
+ }
+
+ function ShowAddForm(){
+ $rez="<h2>Добавление запроса</h2>";
+ $rez.="<form action='process.php' method='post'><table>";
+ $rez.="<tr><td>* Название:</td><td><input type='text' size='40' name='name'></td></tr>";
+ $rez.="<tr><td>Имя:</td><td><input type='text' size='40' name='author'></td></tr>";
+ $rez.="<tr><td>* Тип:</td><td><input type='radio' name='type' value='file'>Файл<Br><input type='radio' checked name='type' value='article'>Статья</td></tr>";
+ $rez.="<tr><td>Описание:</td><td><textarea name='desk' cols='40' rows='3'></textarea></td></tr>";
+ $rez.="<tr><td colspan='2'><input type='submit' value='Добавить'><input type='hidden' name='act' value='add'></td></tr></table>";
+ $rez.="<div style='text-align:center;font:normal 8pt sans;'>* Поля обязательные для заполнения</div>";
+ echo $rez;
+ }
+
+ function AddRequest($name,$desk,$author,$type){
+ if(empty($author)){$author='anonymous';}
+ if(empty($name)){die("ОШИБКА: Не заполнено поле 'Название'!");}
+ $sql = 'INSERT INTO `requests` (`id`, `name`, `desk`, `status`, `date`, `author`, `url`, `comment`, `type`) VALUES (NULL, \''.$name.'\', \''.$desk.'\', \'0\', NOW(), \''.$author.'\', \'\', \'\', \''.$type.'\');';
+ $result=mysql_query($sql);
+ return mysql_insert_id();
+ }
+
+ function MakeRequest($id,$url,$comment){
+ if(empty($url)){die("ОШИБКА: Не заполнено поле 'URL'!");}
+ /* $sql = 'SELECT `status` FROM `requests` WHERE id='.(int)$id;
+ $result=mysql_query($sql);
+ $status=mysql_fetch_field($result,'status');
+ if($status==1){die("ОШИБКА: Текущий запрос уже выполнен!");}
+ */$sql="UPDATE `requests` SET `status` = '1',`url` = '".$url."',`comment` = '".$comment."' WHERE `requests`.`id` =".$id." LIMIT 1 ;";
+ $result=mysql_query($sql);
+ }
+
+ function ShowMakeForm($id){
+ $rez="<h2>Выполнение запроса</h2>";
+ $rez.="<form action='process.php' method='post'><table>";
+ $rez.="<tr><td>* URL:</td><td><input type='text' size='40' name='name'></td></tr>";
+ $rez.="<tr><td>Комментарий:</td><td><textarea name='desk' cols='40' rows='3'></textarea></td></tr>";
+ $rez.="<tr><td colspan='2'><input type='submit' value='Выполнить'><input type='hidden' name='act' value='make'><input type='hidden' name='id' value='".$id."'></td></tr></table>";
+ $rez.="<div style='text-align:center;font:normal 8pt sans;'>* Поля обязательные для заполнения</div>";
+ echo $rez;
+ }
+}
+?>
\ No newline at end of file
/trunk/lib/lib.php
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/style.css
===================================================================
--- trunk/style.css (revision 0)
+++ trunk/style.css (revision 3)
@@ -0,0 +1,61 @@
+/*
+ Document : style
+ Created on : 24.06.2009, 12:42:34
+ Author : Sinegovsky Ivan
+ Description: Main stylesheet.
+*/
+
+body {
+ background: url(img/bg.gif);
+}
+
+h1 {
+ text-align: center;
+ margin: 35px 0 0px 0;
+}
+
+h2 {
+ font: 20pt/20pt Georgia;
+ text-align: center;
+ margin: 10px 0 10px 0;
+}
+
+table {
+ border-top: 2px solid #000;
+ border-left: 2px solid #000;
+ border-bottom: 2px solid #000;
+ border-right: 1px solid #000;
+ width: 500px;
+ margin: 0 auto;
+ border-spacing: 0;
+ white-space: nowrap;
+}
+
+td {
+ text-align: center;
+ padding: 8px 5px;
+ border-bottom: 1px solid #dcdcdc;
+ border-right: 1px solid #000;
+}
+
+.ok{
+ color:green;
+}
+
+.need{
+ color:red;
+}
+
+.add{
+ margin: 10px;
+ text-align:center;
+}
+
+a,a:visited{
+ color:blue;
+ text-decoration:none;
+}
+a:hover{
+ color:blue;
+ text-decoration:underline;
+}
/trunk/style.css
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property