Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("config.php");
- $conn=pg_connect("host=".host." user=".user." password=".pass." dbname=".database);
- function get_title($id=0)
- {
- global $conn;
- $sql="SELECT title as count FROM proxy_selection where id=".$id;
- $result=pg_Exec($conn,$sql);
- return pg_fetch_result($result,0,"title");
- }
- function get_desc($id=0)
- {
- global $conn;
- $sql="SELECT description as count FROM proxy_selection where id=".$id;
- $result=pg_Exec($conn,$sql);
- return pg_fetch_result($result,0,"title");
- }
- if (!conn)
- {
- echo("cant connect :(");
- exit;
- }
- else
- {
- if (isset($_REQUEST['task'])==false) { $_REQUEST['task']='show'; }
- switch($_REQUEST['task'])
- {
- default:
- case 'show':
- $result=pg_Exec($conn,"SELECT * FROM proxy_selection ORDER BY title");
- if (!$result)
- {
- echo("error load records");
- exit;
- } ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <style>
- th,td { padding-left:20px; }
- </style>
- </script>
- </head>
- <body>
- <table cellspacing="0" cellpadding="0">
- <tr style="background-color:#CCC;">
- <td>#</td>
- <td><b>Title</b></td>
- <td><b>SQL</b></td>
- <td><b>Save</b></td>
- <td><b>Description</b></td>
- <td><b>Delete</b></td>
- </tr><?php
- $n=pg_num_rows($result);
- for($i=0;$i<$n;$i++)
- {
- $data=pg_fetch_object($result,$i); ?>
- <tr>
- <form action="proxy_selection.php?task=save" method="post">
- <td><?php echo($i); ?></td>
- <td><input type="text" name="title" value="<?php echo($data->title); ?>" /></td>
- <td><input type="text" name="sql" value="<?php echo($data->sql); ?>" /></td>
- <td><input type="submit" value="Save" /></td>
- <td><a href="proxy_selection.php?task=desc_edit&id=<?php echo($data->id); ?>"></td>
- <td><a href="proxy_selection.php?task=delete&id=<?php echo($data->id); ?>"></td>
- <?php echo($data->description); ?></a></td>
- </form>
- </tr><?php
- } ?>
- </table>
- <h2><a href="proxy_selection.php?task=new">ADD NEW</h2>
- </body></html><?php
- break;
- case 'save':
- $id=$_REQUEST['id'];
- $title=$_REQUEST['title'];
- $sql=$_REQUEST['sql'];
- $sql="UPDARE proxy_selection SET title='".$title."',sql='".$sql."' WHERE id=".$id;
- pg_query($conn,$sql);
- header("Location: proxy_selection.php");
- break;
- case 'add':
- $sql="INSERT INTO proxy_selection(title) VALUES('')";
- pg_query($conn,$sql);
- header("Location: proxy_selection.php");
- break;
- case 'desc_edit':
- $id=$_REQUEST['id']; ?>
- <h1>edit description for <?php echo(get_title($id)); ?></h1>
- <form action="proxy_selection.php" method="post">
- <textarea name="description"><?php echo(get_desc($id)); ?></textarea>
- <input type="hidden" name="task" value="desc_save" />
- <input type="submit" value="Save" />
- </form>
- break;
- case 'desc_save':
- $id=$_REQUEST['id'];
- $description=$_REQUEST['description'];
- $sql="UPDARE proxy_selection SET description='".$description."' WHERE id=".$id;
- pg_query($conn,$sql);
- header("Location: proxy_selection.php");
- break;
- case 'delete':
- $id=$_REQUEST['id'];
- $sql="DELETE FROM proxy_selection where id=".$id;
- pg_query($conn,$sql);
- header("Location: proxy_selection.php");
- break;
- } //end switch
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement