| 1 |
<?php
|
| 2 |
/***************************************************************************
|
| 3 |
* mysql.php
|
| 4 |
*
|
| 5 |
* Fri Oct 17 15:53:53 2003
|
| 6 |
* Copyright 2003 lisa seelye - lisa@gentoo.org
|
| 7 |
* Copyright 2003 james harlow - hythloday@gentoo.org
|
| 8 |
* Copyright 2003 Gentoo Technologies, Inc. - http://www.gentoo.org/
|
| 9 |
*
|
| 10 |
* $Header: /home/cvsroot/gentoo-src/glep15/mysql.php,v 1.1 2003/10/30 21:52:52 lisa Exp $
|
| 11 |
***************************************************************************
|
| 12 |
* This program is free software; you can redistribute it and/or modify
|
| 13 |
* it under the terms of the GNU General Public License as published by
|
| 14 |
* the Free Software Foundation; either version 2 of the License, or
|
| 15 |
* (at your option) any later version.
|
| 16 |
*
|
| 17 |
* This program is distributed in the hope that it will be useful,
|
| 18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 |
* GNU Library General Public License for more details.
|
| 21 |
*
|
| 22 |
* You should have received a copy of the GNU General Public License
|
| 23 |
* along with this program; if not, write to the Free Software
|
| 24 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 25 |
**************************************************************************/
|
| 26 |
require_once("config.php");
|
| 27 |
|
| 28 |
/* for get_username() */
|
| 29 |
require_once ("authenticate.php");
|
| 30 |
|
| 31 |
$link = mysql_connect("$mysql_host","$mysql_username","$mysql_password")
|
| 32 |
or die ("Could not connect to databse: " . mysql_error());
|
| 33 |
|
| 34 |
$db = mysql_select_db("$mysql_script_database")
|
| 35 |
or die("Could not select database (did you create it?): " . mysql_error());
|
| 36 |
|
| 37 |
function get_scripts ( $number ) {
|
| 38 |
$query = "SELECT * FROM scripts ";
|
| 39 |
if ( isset ( $number ) ) {
|
| 40 |
$query .= "LIMIT $number";
|
| 41 |
}
|
| 42 |
$result = mysql_query($query) or die("Query failed : ".mysql_error());
|
| 43 |
$scripts = array ();
|
| 44 |
while ($row = mysql_fetch_object($result)) {
|
| 45 |
array_push ( $scripts, $row );
|
| 46 |
}
|
| 47 |
return $scripts;
|
| 48 |
}
|
| 49 |
|
| 50 |
/* Insert the script into the database. This should not generate output. */
|
| 51 |
function submit_script ( $script_name, $script_description, $script_location ) {
|
| 52 |
global $mysql_script_table;
|
| 53 |
|
| 54 |
$script_text = file_get_contents ( $script_location );
|
| 55 |
$submitter = get_username();
|
| 56 |
$category = get_language_from_script( $script_text );
|
| 57 |
$query = "INSERT INTO `$mysql_script_table` (`submitter`, `category`,
|
| 58 |
`dateadded`, `name`, `descript`, `script`) VALUES ( '$submitter',
|
| 59 |
'$category', '".date ( "Y-m-d H:i:s", time())."', '$script_name',
|
| 60 |
'$script_description', '$script_text' )";
|
| 61 |
mysql_query($query);
|
| 62 |
}
|
| 63 |
|
| 64 |
function get_script_by_sid( $sid ) {
|
| 65 |
$query = "SELECT * FROM scripts WHERE sid = '$sid' ";
|
| 66 |
$result = mysql_query($query) or die("Query failed : ".mysql_error());
|
| 67 |
return mysql_fetch_object($result);
|
| 68 |
}
|
| 69 |
|
| 70 |
?>
|