Skip to content

Commit

Permalink
Modified database (manage_template and manage label in _users)
Browse files Browse the repository at this point in the history
Added menu for user groups (early version)
Survey rights are mostly implemented
Code cleaning/minor code fixing

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@2063 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Dennis committed Sep 10, 2006
1 parent 41f59ee commit 02d2aae
Show file tree
Hide file tree
Showing 12 changed files with 2,325 additions and 1,815 deletions.
10 changes: 9 additions & 1 deletion admin/access_denied.php
Expand Up @@ -110,7 +110,11 @@
}



elseif($action == "delusergroup")
{
$accesssummary .= _("<p>You are not allowed to delete this group!</p>");
$accesssummary .= "<a href='$scriptname?action=editusergroups'>"._("Continue")."</a><br />&nbsp;\n";
}


/*elseif(returnglobal('action') == "importsurvey")
Expand All @@ -134,6 +138,10 @@
$accesssummary .= "<br />"._("You are not allowed to perform this operation!")."<br />\n";
if($sid)
$accesssummary .= "<br /><br /><a href='$scriptname?sid=$sid&action=surveysecurity'>"._("Continue")."</a><br />&nbsp;\n";
elseif(isset($_GET['ugid']))
{
$accesssummary .= "<br /><br /><a href='$scriptname?action=editusergroups&ugid={$_GET['ugid']}'>"._("Continue")."</a><br />&nbsp;\n";
}
else
$accesssummary .= "<br /><br /><a href='$scriptname?action=editusers'>"._("Continue")."</a><br />&nbsp;\n";
}
Expand Down
11 changes: 11 additions & 0 deletions admin/admin.php
Expand Up @@ -68,9 +68,20 @@
."\t\t\tdocument.getElementById(name).style.display='';\n"
."\t\t\t}\n"
."\t\t}\n"

."-->\n"
."function bla(str1, str2)\n"
."{\n"
." return(str1+str2);\n"
."}\n"
."</script>\n";



//. "onChange=\"window.open('$scriptname?action=addgroup&amp;ugid='+arrayugid[this.selectedIndex],'_top')\">\n"



// CHECK IF FIRST USE!
if (!$database_exists)
{
Expand Down
619 changes: 315 additions & 304 deletions admin/dbchecker.php

Large diffs are not rendered by default.

185 changes: 97 additions & 88 deletions admin/dumpdb.php
Expand Up @@ -36,103 +36,112 @@

require_once(dirname(__FILE__).'/../config.php');

if ($database_exists) $tables = $connect->MetaTables();

$export="";
$export .="#------------------------------------------"."\n";
$export .="# PHPSurveyor Database Dump of `$databasename`"."\n";
if ($allowexportalldb==0) {
$export .="# Only prefixed tables with: ". $dbprefix ."\n";
}
$export .="# Date of Dump: ". date("d-M-Y") ."\n";
$export .="#------------------------------------------"."\n\n\n";

foreach($tables as $table) {
if($_SESSION['USER_RIGHT_CONFIGURATOR'] == 1)
{
if ($database_exists) $tables = $connect->MetaTables();

$export="";
$export .="#------------------------------------------"."\n";
$export .="# PHPSurveyor Database Dump of `$databasename`"."\n";
if ($allowexportalldb==0) {
if ($dbprefix==substr($table, 0, strlen($dbprefix))) {
$export .="# Only prefixed tables with: ". $dbprefix ."\n";
}
$export .="# Date of Dump: ". date("d-M-Y") ."\n";
$export .="#------------------------------------------"."\n\n\n";

foreach($tables as $table) {
if ($allowexportalldb==0) {
if ($dbprefix==substr($table, 0, strlen($dbprefix))) {
$export .= defdump($table);
$export .= datadump($table);
}
}
else {
$export .= defdump($table);
$export .= datadump($table);
}
}
else {
$export .= defdump($table);
$export .= datadump($table);
}
}

$file_name = "PHPSurveyor_{$databasename}_dump_".date("Y-m-d").".sql";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name");
Header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
echo $export;
exit;

$file_name = "PHPSurveyor_{$databasename}_dump_".date("Y-m-d").".sql";
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=$file_name");
Header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
echo $export;
exit;


function defdump($tablename)
{
global $connect;
$def = "";
$def .="#------------------------------------------"."\n";
$def .="# Table definition for $tablename"."\n";
$def .="#------------------------------------------"."\n";
$def .= "DROP TABLE IF EXISTS $tablename;"."\n"."\n";
$def .= "CREATE TABLE $tablename ("."\n";
$result = db_execute_assoc("SHOW COLUMNS FROM $tablename") or die("Table $tablename not existing in database");
while($row = $result->FetchRow())
function defdump($tablename)
{
$def .= " $row[Field] $row[Type]";
if (!is_null($row["Default"])) $def .= " DEFAULT '$row[Default]'";
if ($row["Null"] != "YES") $def .= " NOT NULL";
if ($row["Extra"] != "") $def .= " $row[Extra]";
$def .= ",\n";
global $connect;
$def = "";
$def .="#------------------------------------------"."\n";
$def .="# Table definition for $tablename"."\n";
$def .="#------------------------------------------"."\n";
$def .= "DROP TABLE IF EXISTS $tablename;"."\n"."\n";
$def .= "CREATE TABLE $tablename ("."\n";
$result = db_execute_assoc("SHOW COLUMNS FROM $tablename") or die("Table $tablename not existing in database");
while($row = $result->FetchRow())
{
$def .= " $row[Field] $row[Type]";
if (!is_null($row["Default"])) $def .= " DEFAULT '$row[Default]'";
if ($row["Null"] != "YES") $def .= " NOT NULL";
if ($row["Extra"] != "") $def .= " $row[Extra]";
$def .= ",\n";
}
$def = ereg_replace(",\n$","", $def);

$result = db_execute_assoc("SHOW KEYS FROM $tablename");
while($row = $result->FetchRow())
{
$kname=$row["Key_name"];
if(($kname != "PRIMARY") && ($row["Non_unique"] == 0)) $kname="UNIQUE|$kname";
if(!isset($index[$kname])) $index[$kname] = array();
$index[$kname][] = $row["Column_name"];
}

while(list($x, $columns) = @each($index))
{
$def .= ",\n";
if($x == "PRIMARY") $def .= " PRIMARY KEY (" . implode($columns, ", ") . ")";
else if (substr($x,0,6) == "UNIQUE") $def .= " UNIQUE ".substr($x,7)." (" . implode($columns, ", ") . ")";
else $def .= " KEY $x (" . implode($columns, ", ") . ")";
}
$def .= "\n);\n\n\n";
//echo "<pre>$def</pre><br />";
return (stripslashes($def));
}
$def = ereg_replace(",\n$","", $def);

$result = db_execute_assoc("SHOW KEYS FROM $tablename");
while($row = $result->FetchRow())
{
$kname=$row["Key_name"];
if(($kname != "PRIMARY") && ($row["Non_unique"] == 0)) $kname="UNIQUE|$kname";
if(!isset($index[$kname])) $index[$kname] = array();
$index[$kname][] = $row["Column_name"];


function datadump ($table) {

global $connect;

$result = "#------------------------------------------"."\n";
$result .="# Table data for $table"."\n";
$result .="#------------------------------------------"."\n";

$query = db_execute_num("select * from $table");
$num_fields = $query->FieldCount();
$numrow = $query->RecordCount();

while($row=$query->FetchRow()){
set_time_limit(5);
$result .= "INSERT INTO ".$table." VALUES(";
for($j=0; $j<$num_fields; $j++) {
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) $result .= "\"$row[$j]\"" ; else $result .= "\"\"";
if ($j<($num_fields-1)) $result .= ",";
}
$result .= ");\n";
} // while
return $result . "\n\n\n";
}

while(list($x, $columns) = @each($index))

}
else
{
$def .= ",\n";
if($x == "PRIMARY") $def .= " PRIMARY KEY (" . implode($columns, ", ") . ")";
else if (substr($x,0,6) == "UNIQUE") $def .= " UNIQUE ".substr($x,7)." (" . implode($columns, ", ") . ")";
else $def .= " KEY $x (" . implode($columns, ", ") . ")";
$action = "dumpdb";
include("access_denied.php");
include("admin.php");
}
$def .= "\n);\n\n\n";
//echo "<pre>$def</pre><br />";
return (stripslashes($def));
}


function datadump ($table) {

global $connect;

$result = "#------------------------------------------"."\n";
$result .="# Table data for $table"."\n";
$result .="#------------------------------------------"."\n";

$query = db_execute_num("select * from $table");
$num_fields = $query->FieldCount();
$numrow = $query->RecordCount();

while($row=$query->FetchRow()){
set_time_limit(5);
$result .= "INSERT INTO ".$table." VALUES(";
for($j=0; $j<$num_fields; $j++) {
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) $result .= "\"$row[$j]\"" ; else $result .= "\"\"";
if ($j<($num_fields-1)) $result .= ",";
}
$result .= ");\n";
} // while
return $result . "\n\n\n";
}
?>

0 comments on commit 02d2aae

Please sign in to comment.