Continued work on implementation of new table structures and new function principles, Started new goto line system without using javascript built in confirms or alerts,

This commit is contained in:
xevidos 2019-10-18 15:58:01 -04:00
parent fa0889268a
commit 5af37cbce3
14 changed files with 208 additions and 87 deletions

View file

@ -167,7 +167,7 @@ class Common {
public static function is_admin() { public static function is_admin() {
global $sql; global $sql;
$query = "SELECT COUNT( * ) FROM users WHERE id=? AND access=?;"; $query = "SELECT COUNT( * ) FROM users WHERE id=? AND ( access=? OR access='admin' );";
$bind_variables = array( $_SESSION["user_id"], Permissions::SYSTEM_LEVELS["admin"] ); $bind_variables = array( $_SESSION["user_id"], Permissions::SYSTEM_LEVELS["admin"] );
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' ); $return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' );
$admin = ( $return > 0 ); $admin = ( $return > 0 );
@ -390,11 +390,11 @@ class Common {
$pass = false; $pass = false;
if( isset( $_SESSION["token"] ) && isset( $_SESSION["user"] ) ) { if( isset( $_SESSION["token"] ) && isset( $_SESSION["user_id"] ) ) {
global $sql; global $sql;
$query = "SELECT COUNT( * ) FROM users WHERE username=? AND token=?;"; $query = "SELECT COUNT( * ) FROM users WHERE id=? AND token=?;";
$bind_variables = array( $_SESSION["user"], sha1( $_SESSION["token"] ) ); $bind_variables = array( $_SESSION["user_id"], sha1( $_SESSION["token"] ) );
$return = $sql->query( $query, $bind_variables, formatJSEND( "error", "Error checking access." ), "fetchColumn" ); $return = $sql->query( $query, $bind_variables, formatJSEND( "error", "Error checking access." ), "fetchColumn" );
if( $return > 0 ) { if( $return > 0 ) {
@ -458,33 +458,43 @@ class Common {
// Format JSEND Response // Format JSEND Response
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
public static function formatJSEND( $status, $data = false ) { public static function formatJSEND( $status, $data = false, $debug = false ) {
/// Debug ///////////////////////////////////////////////// /// Debug /////////////////////////////////////////////////
$debug = ""; $jsend = array(
"status" => null,
"data" => null,
"debug" => null,
"message" => null,
);
if( count( Common::$debugMessageStack ) > 0 ) { if( count( Common::$debugMessageStack ) > 0 ) {
$debug .= ',"debug":'; $jsend["debug"] = json_encode( Common::$debugMessageStack );
$debug .= json_encode( Common::$debugMessageStack ); }
if( $debug ) {
$jsend["debug"] = $debug;
} }
if( $status == "success" ) { if( $status == "success" ) {
// Success /////////////////////////////////////////////// // Success ///////////////////////////////////////////////
$jsend["status"] = "success";
if( $data ) { if( $data ) {
$jsend = '{"status":"success","data":' . json_encode( $data ) . $debug . '}'; $jsend["data"] = $data;
} else {
$jsend = '{"status":"success","data":null' . $debug . '}';
} }
} else { } else {
// Error ///////////////////////////////////////////////// // Error /////////////////////////////////////////////////
$jsend = '{"status":"' . $status . '","message":"' . $data . '"' . $debug . '}'; $jsend["status"] = "error";
$jsend["message"] = $data;
} }
// Return //////////////////////////////////////////////// // Return ////////////////////////////////////////////////
return $jsend; return json_encode( $jsend );
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -34,7 +34,7 @@ class Active extends Common {
global $sql; global $sql;
$query = "DELETE FROM active WHERE path=? AND user=?;"; $query = "DELETE FROM active WHERE path=? AND user=?;";
$bind_variables = array( $path, $_SESSION["user"] ); $bind_variables = array( $path, $_SESSION["user_id"] );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" ); $return = $sql->query( $query, $bind_variables, 0, "rowCount" );
} }
@ -115,13 +115,21 @@ class Active extends Common {
public function Add() { public function Add() {
global $sql; global $sql;
$query = "INSERT INTO active( user, path, focused ) VALUES ( ?, ?, ? );"; $query = "UPDATE active SET focused=false WHERE user=? AND path=?;";
$bind_variables = array( $_SESSION["user_id"], $this->path, false ); $bind_variables = array( $_SESSION["user_id"], $this->path );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" ); $result = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $return > 0 ) { if( $result == 0 ) {
echo formatJSEND( "success" ); global $sql;
$query = "INSERT INTO active( user, path, focused ) VALUES ( ?, ?, ? );";
$bind_variables = array( $_SESSION["user_id"], $this->path, false );
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $result > 0 ) {
echo formatJSEND( "success" );
}
} }
} }

View file

@ -19,6 +19,17 @@ checkSession();
<?php <?php
switch( $_GET['action'] ) { switch( $_GET['action'] ) {
case 'line':
?>
<label><?php i18n("Goto Line:"); ?></label>
<input name="goto_line" autofocus="autofocus" autocomplete="off">
<button class="btn-left" onclick="codiad.editor.goto_line();return false;"><?php i18n("Goto"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Cancel"); ?></button>
<?php
break;
break;
case 'search': case 'search':
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -1321,54 +1321,14 @@
bindKeys: function( i ) { bindKeys: function( i ) {
//Add key bindings to editor so we overwrite any already Setup
//by the ace editor.
var _this = this; var _this = this;
// Find codiad.keybindings.bindings.forEach( function( m, j, a ) {
i.commands.addCommand( {
name: 'Find', i.commands.addCommand( m );
bindKey: {
win: 'Ctrl-F',
mac: 'Command-F'
},
exec: function( e ) {
_this.openSearch( 'find' );
}
}); });
// Find + Replace
i.commands.addCommand( {
name: 'Replace',
bindKey: {
win: 'Ctrl-R',
mac: 'Command-R'
},
exec: function( e ) {
_this.openSearch( 'replace' );
}
});
i.commands.addCommand( {
name: 'Move Up',
bindKey: {
win: 'Ctrl-up',
mac: 'Command-up'
},
exec: function( e ) {
codiad.active.move( 'up' );
}
});
i.commands.addCommand( {
name: 'Move Down',
bindKey: {
win: 'Ctrl-down',
mac: 'Command-up'
},
exec: function( e ) {
codiad.active.move( 'down' );
}
});
}, },
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -39,6 +39,52 @@
codiad.keybindings = { codiad.keybindings = {
bindings: [
{
name: 'Find',
bindKey: {
win: 'Ctrl-F',
mac: 'Command-F'
},
exec: function( e ) {
codiad.editor.openSearch( 'find' );
}
},
{
name: 'Move Down',
bindKey: {
win: 'Ctrl-down',
mac: 'Command-up'
},
exec: function( e ) {
codiad.active.move( 'down' );
}
},
{
name: 'Move Up',
bindKey: {
win: 'Ctrl-up',
mac: 'Command-up'
},
exec: function( e ) {
codiad.active.move( 'up' );
}
},
{
name: 'Replace',
bindKey: {
win: 'Ctrl-R',
mac: 'Command-R'
},
exec: function( e ) {
codiad.editor.openSearch( 'replace' );
}
}
],
init: function() { init: function() {
// Active List Next [CTRL+DOWN] ////////////////////////////// // Active List Next [CTRL+DOWN] //////////////////////////////
@ -74,6 +120,12 @@
codiad.editor.openSearch( 'find' ); codiad.editor.openSearch( 'find' );
}); });
// Find [CTRL+L] /////////////////////////////////////////////
$.ctrl( '76', function() {
codiad.editor.open_goto();
});
// Open in browser [CTRL+O] ////////////////////////////////// // Open in browser [CTRL+O] //////////////////////////////////
$.ctrl( '79', function() { $.ctrl( '79', function() {

View file

@ -85,7 +85,7 @@ class Permissions {
continue; continue;
} }
if( $data["owner"] == 'nobody' ) { if( $data["owner"] == -1 ) {
$access = self::LEVELS["owner"]; $access = self::LEVELS["owner"];
} elseif( $data["owner"] == $_SESSION["user_id"] ) { } elseif( $data["owner"] == $_SESSION["user_id"] ) {

View file

@ -214,7 +214,7 @@ class Project extends Common {
WHERE path = ? WHERE path = ?
AND ( AND (
owner=? owner=?
OR owner='nobody' OR owner=-1
OR id IN ( SELECT project FROM access WHERE user = ? ) OR id IN ( SELECT project FROM access WHERE user = ? )
) ORDER BY name;"; ) ORDER BY name;";
$bind_variables = array( $project, $_SESSION["user_id"], $_SESSION["user_id"] ); $bind_variables = array( $project, $_SESSION["user_id"], $_SESSION["user_id"] );
@ -258,7 +258,7 @@ class Project extends Common {
$query = " $query = "
SELECT * FROM projects SELECT * FROM projects
WHERE owner=? WHERE owner=?
OR owner='nobody' OR owner=-1
OR id IN ( SELECT project FROM access WHERE user = ? );"; OR id IN ( SELECT project FROM access WHERE user = ? );";
$bind_variables = array( $_SESSION["user_id"], $_SESSION["user_id"] ); $bind_variables = array( $_SESSION["user_id"], $_SESSION["user_id"] );
$return = $sql->query( $query, $bind_variables, array() ); $return = $sql->query( $query, $bind_variables, array() );
@ -292,14 +292,14 @@ class Project extends Common {
public function rename_project( $old_name, $new_name, $path ) { public function rename_project( $old_name, $new_name, $path ) {
global $sql; global $sql;
$query = "SELECT * FROM projects WHERE name=? AND path=? AND ( owner=? OR owner='nobody' );"; $query = "SELECT * FROM projects WHERE name=? AND path=? AND ( owner=? OR owner=-1 );";
$bind_variables = array( $old_name, $path, $_SESSION["user_id"] ); $bind_variables = array( $old_name, $path, $_SESSION["user_id"] );
$return = $sql->query( $query, $bind_variables, array() ); $return = $sql->query( $query, $bind_variables, array() );
$pass = false; $pass = false;
if( ! empty( $return ) ) { if( ! empty( $return ) ) {
$query = "UPDATE projects SET name=? WHERE name=? AND path=? AND ( owner=? OR owner='nobody' );"; $query = "UPDATE projects SET name=? WHERE name=? AND path=? AND ( owner=? OR owner=-1 );";
$bind_variables = array( $new_name, $old_name, $path, $_SESSION["user_id"] ); $bind_variables = array( $new_name, $old_name, $path, $_SESSION["user_id"] );
$return = $sql->query( $query, $bind_variables, 0, "rowCount"); $return = $sql->query( $query, $bind_variables, 0, "rowCount");
@ -372,7 +372,7 @@ class Project extends Common {
WHERE path = ? WHERE path = ?
AND ( AND (
owner=? owner=?
OR owner='nobody' OR owner=-1
OR id IN ( SELECT project FROM access WHERE user = ? ) OR id IN ( SELECT project FROM access WHERE user = ? )
) ORDER BY name LIMIT 1;"; ) ORDER BY name LIMIT 1;";
$bind_variables = array( $this->path, $_SESSION["user_id"], $_SESSION["user_id"] ); $bind_variables = array( $this->path, $_SESSION["user_id"], $_SESSION["user_id"] );

View file

@ -114,7 +114,7 @@ switch( $_GET['action'] ) {
?> ?>
<td width="70"><a onclick="codiad.message.error(i18n('Active Project Cannot Be Removed'));" class="icon-block bigger-icon"></a></td> <td width="70"><a onclick="codiad.message.error(i18n('Active Project Cannot Be Removed'));" class="icon-block bigger-icon"></a></td>
<?php <?php
} elseif( $owner !== $_SESSION["user"] && $owner !== 'nobody' ) { } elseif( $owner !== $_SESSION["user"] && $owner != -1 ) {
?> ?>
<td width="70"><a onclick="codiad.message.error(i18n('Projects owned by others can not be deleted'));" class="icon-block bigger-icon"></a></td> <td width="70"><a onclick="codiad.message.error(i18n('Projects owned by others can not be deleted'));" class="icon-block bigger-icon"></a></td>

View file

@ -172,8 +172,8 @@ class Settings {
global $sql; global $sql;
$query = "SELECT name, value FROM user_options WHERE username=?;"; $query = "SELECT name, value FROM user_options WHERE user=?;";
$bind_variables = array( $this->username ); $bind_variables = array( $_SESSION["user_id"] );
$return = $sql->query( $query, $bind_variables, array() ); $return = $sql->query( $query, $bind_variables, array() );
$options = array(); $options = array();
@ -259,21 +259,21 @@ class Settings {
} }
} else { } else {
$query = "INSERT INTO user_options ( name, user, value ) VALUES ( ?, ?, ? );"; $query = "UPDATE user_options SET value=? WHERE name=? AND user=?;";
$bind_variables = array( $bind_variables = array(
$value,
$option, $option,
$_SESSION["user_id"], $_SESSION["user_id"],
$value,
); );
$result = $sql->query( $query, $bind_variables, 0, "rowCount" ); $result = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $result == 0 ) { if( $result == 0 ) {
$query = "UPDATE user_options SET value=? WHERE name=? AND user=?;"; $query = "INSERT INTO user_options ( name, user, value ) VALUES ( ?, ?, ? );";
$bind_variables = array( $bind_variables = array(
$value,
$option, $option,
$_SESSION["user_id"], $_SESSION["user_id"],
$value,
); );
$result = $sql->query( $query, $bind_variables, 0, "rowCount" ); $result = $sql->query( $query, $bind_variables, 0, "rowCount" );
} }

View file

@ -205,6 +205,22 @@ class sql {
); );
} }
try {
$this->query( array(
"mysql" => "ALTER TABLE user_options DROP INDEX name255username255;",
"pgsql" => "ALTER TABLE user_options DROP CONSTRAINT name255username255;",
), array(), 0, "rowCount", "exception" );
} catch( Exception $error ) {
//The access field is not there.
//echo var_export( $error->getMessage(), $access_query );
$status_updates["nameusername_user_option_constraint"] = array(
"error_message" => $error->getMessage(),
"dev_message" => "No constriant to remove."
);
}
try { try {
$update_query = ""; $update_query = "";
@ -271,6 +287,56 @@ class sql {
); );
} }
try {
$convert = false;
$update_query = "";
$projects = $this->query( "SELECT id, name, path, owner FROM projects", array(), array(), "fetchAll", "exception" );
$users = $this->query( "SELECT id, username FROM users", array(), array(), "fetchAll", "exception" );
$delete = Permissions::LEVELS["delete"];
foreach( $projects as $row => $project ) {
if( ! is_numeric( $project["owner"] ) ) {
$convert = true;
}
foreach( $users as $row => $user ) {
if( $project["owner"] == $user["username"] ) {
$update_query .= "UPDATE projects SET owner={$user["id"]} WHERE id={$project["id"]};";
break;
}
}
if( $project["owner"] != $user["username"] ) {
$update_query .= "UPDATE projects SET owner=-1 WHERE id={$project["id"]};";
}
}
if( strlen( $update_query ) > 0 && $convert ) {
//change project to users table
$result = $this->query( "ALTER TABLE projects DROP COLUMN owner", array(), array(), "rowCount", "exception" );
$result = $this->query( "ALTER TABLE projects ADD COLUMN owner INT", array(), array(), "rowCount", "exception" );
$result = $this->query( $update_query, array(), array(), "rowCount", "exception" );
} else {
$status_updates["owner_projects_column"] = array( "dev_message" => "User projects owner column needed no conversion." );
}
} catch( Exception $error ) {
//The access field is not there.
//echo var_export( $error->getMessage(), $access_query );
$status_updates["username_user_option_column"] = array(
"error_message" => $error->getMessage(),
"dev_message" => "No username column to convert."
);
}
try { try {
$projects = $this->query( array( $projects = $this->query( array(
@ -285,6 +351,20 @@ class sql {
"dev_message" => "Removal of username255path1500 constraint in the active table failed. This usually means there was never one to begin with" "dev_message" => "Removal of username255path1500 constraint in the active table failed. This usually means there was never one to begin with"
); );
} }
try {
$result = $this->query( "DELETE FROM active;", array(), 0, "rowCount", "exception" );
$result = $this->query( "ALTER TABLE active DROP COLUMN username;", array(), 0, "rowCount", "exception" );
$result = $this->query( "ALTER TABLE active ADD COLUMN user INT", array(), array(), "rowCount", "exception" );
} catch( Exception $error ) {
//echo var_dump( $error->getMessage() );
$status_updates["username_active_coluin"] = array(
"error_message" => $error->getMessage(),
"dev_message" => "Removal of username255path1500 constraint in the active table failed. This usually means there was never one to begin with"
);
}
} }
return $status_updates; return $status_updates;
} }

View file

@ -26,7 +26,7 @@ if ( $_POST['action'] == 'create_default_tables' ) {
exit( formatJSEND( "success", "Created tables." ) ); exit( formatJSEND( "success", "Created tables." ) );
} else { } else {
exit( formatJSEND( "error", "Could not create tables." ) ); exit( formatJSEND( "error", array( "message" => "Could not create tables.", "result" => $result ) ) );
} }
} else { } else {

View file

@ -177,7 +177,7 @@ class updater {
$sql = new sql(); $sql = new sql();
$connection = $sql->connect(); $connection = $sql->connect();
$result = $sql->recreate_default_tables(); $result = $sql->create_default_tables();
$upgrade_function = str_replace( ".", "_", $this->update::VERSION ); $upgrade_function = str_replace( ".", "_", $this->update::VERSION );
if( is_callable( array( $this, $upgrade_function ) ) ) { if( is_callable( array( $this, $upgrade_function ) ) ) {

View file

@ -159,7 +159,7 @@ class User {
global $sql; global $sql;
$pass = false; $pass = false;
$this->EncryptPassword(); $password = $this->encrypt_password( $password );
$query = "SELECT * FROM users WHERE username=? AND password=?;"; $query = "SELECT * FROM users WHERE username=? AND password=?;";
$bind_variables = array( $username, $password ); $bind_variables = array( $username, $password );
$return = $sql->query( $query, $bind_variables, array() ); $return = $sql->query( $query, $bind_variables, array() );
@ -198,7 +198,7 @@ class User {
$_SESSION["login_session"] = true; $_SESSION["login_session"] = true;
$query = "UPDATE users SET token=? WHERE username=?;"; $query = "UPDATE users SET token=? WHERE username=?;";
$bind_variables = array( sha1( $token ), $this->username ); $bind_variables = array( sha1( $token ), $username );
$return = $sql->query( $query, $bind_variables, 0, 'rowCount' ); $return = $sql->query( $query, $bind_variables, 0, 'rowCount' );
$projects = $sql->query( "SELECT path FROM projects WHERE id = ?", array( $user["project"] ), array() ); $projects = $sql->query( "SELECT path FROM projects WHERE id = ?", array( $user["project"] ), array() );
@ -294,6 +294,8 @@ class User {
public function Create( $username, $password ) { public function Create( $username, $password ) {
$username = self::CleanUsername( $username );
$password = $this->encrypt_password( $password );
$this->add_user( $username, $password ); $this->add_user( $username, $password );
} }

View file

@ -37,7 +37,7 @@ if($_GET['action']=='authenticate') {
} }
$username = User::CleanUsername( $_POST['username'] ); $username = User::CleanUsername( $_POST['username'] );
$password = $User->encrypt_password( $_POST['password'] ); $password = $_POST['password'];
// check if the asked languages exist and is registered in languages/code.php // check if the asked languages exist and is registered in languages/code.php
require_once '../../languages/code.php'; require_once '../../languages/code.php';
@ -98,7 +98,7 @@ if($_GET['action']=='authenticate') {
$_SESSION['lang'] = $lang; $_SESSION['lang'] = $lang;
$_SESSION['theme'] = $theme; $_SESSION['theme'] = $theme;
exit( formatJSEND( "success", array( "username" => $this->username ) ) ); exit( formatJSEND( "success", array( "username" => $username ) ) );
} else { } else {
exit( formatJSEND( "error", "Incorrect Username or Password" ) ); exit( formatJSEND( "error", "Incorrect Username or Password" ) );
@ -137,9 +137,7 @@ if( $_GET['action'] == 'create' ) {
exit( formatJSEND( "error", "Invalid characters in username" ) ); exit( formatJSEND( "error", "Invalid characters in username" ) );
} }
$username = User::CleanUsername( $_POST['username'] ); $User->Create( $_POST['username'], $_POST['password'] );
$password = $User->encrypt_password( $_POST['password'] );
$User->Create( $username, $password );
} }
} }