mirror of https://github.com/xevidos/codiad.git
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:
parent
fa0889268a
commit
5af37cbce3
38
common.php
38
common.php
|
@ -167,7 +167,7 @@ class Common {
|
|||
public static function is_admin() {
|
||||
|
||||
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"] );
|
||||
$return = $sql->query( $query, $bind_variables, -1, 'fetchColumn' );
|
||||
$admin = ( $return > 0 );
|
||||
|
@ -390,11 +390,11 @@ class Common {
|
|||
|
||||
$pass = false;
|
||||
|
||||
if( isset( $_SESSION["token"] ) && isset( $_SESSION["user"] ) ) {
|
||||
if( isset( $_SESSION["token"] ) && isset( $_SESSION["user_id"] ) ) {
|
||||
|
||||
global $sql;
|
||||
$query = "SELECT COUNT( * ) FROM users WHERE username=? AND token=?;";
|
||||
$bind_variables = array( $_SESSION["user"], sha1( $_SESSION["token"] ) );
|
||||
$query = "SELECT COUNT( * ) FROM users WHERE id=? AND token=?;";
|
||||
$bind_variables = array( $_SESSION["user_id"], sha1( $_SESSION["token"] ) );
|
||||
$return = $sql->query( $query, $bind_variables, formatJSEND( "error", "Error checking access." ), "fetchColumn" );
|
||||
|
||||
if( $return > 0 ) {
|
||||
|
@ -458,33 +458,43 @@ class Common {
|
|||
// Format JSEND Response
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
public static function formatJSEND( $status, $data = false ) {
|
||||
public static function formatJSEND( $status, $data = false, $debug = false ) {
|
||||
|
||||
/// Debug /////////////////////////////////////////////////
|
||||
$debug = "";
|
||||
$jsend = array(
|
||||
"status" => null,
|
||||
"data" => null,
|
||||
"debug" => null,
|
||||
"message" => null,
|
||||
);
|
||||
|
||||
if( count( Common::$debugMessageStack ) > 0 ) {
|
||||
|
||||
$debug .= ',"debug":';
|
||||
$debug .= json_encode( Common::$debugMessageStack );
|
||||
$jsend["debug"] = json_encode( Common::$debugMessageStack );
|
||||
}
|
||||
|
||||
if( $debug ) {
|
||||
|
||||
$jsend["debug"] = $debug;
|
||||
}
|
||||
|
||||
if( $status == "success" ) {
|
||||
|
||||
// Success ///////////////////////////////////////////////
|
||||
$jsend["status"] = "success";
|
||||
|
||||
if( $data ) {
|
||||
|
||||
$jsend = '{"status":"success","data":' . json_encode( $data ) . $debug . '}';
|
||||
} else {
|
||||
|
||||
$jsend = '{"status":"success","data":null' . $debug . '}';
|
||||
$jsend["data"] = $data;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Error /////////////////////////////////////////////////
|
||||
$jsend = '{"status":"' . $status . '","message":"' . $data . '"' . $debug . '}';
|
||||
$jsend["status"] = "error";
|
||||
$jsend["message"] = $data;
|
||||
}
|
||||
// Return ////////////////////////////////////////////////
|
||||
return $jsend;
|
||||
return json_encode( $jsend );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -34,7 +34,7 @@ class Active extends Common {
|
|||
|
||||
global $sql;
|
||||
$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" );
|
||||
}
|
||||
|
||||
|
@ -115,13 +115,21 @@ class Active extends Common {
|
|||
public function Add() {
|
||||
|
||||
global $sql;
|
||||
$query = "INSERT INTO active( user, path, focused ) VALUES ( ?, ?, ? );";
|
||||
$bind_variables = array( $_SESSION["user_id"], $this->path, false );
|
||||
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
||||
$query = "UPDATE active SET focused=false WHERE user=? AND path=?;";
|
||||
$bind_variables = array( $_SESSION["user_id"], $this->path );
|
||||
$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" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,17 @@ checkSession();
|
|||
<?php
|
||||
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':
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1321,54 +1321,14 @@
|
|||
|
||||
bindKeys: function( i ) {
|
||||
|
||||
//Add key bindings to editor so we overwrite any already Setup
|
||||
//by the ace editor.
|
||||
var _this = this;
|
||||
|
||||
// Find
|
||||
i.commands.addCommand( {
|
||||
name: 'Find',
|
||||
bindKey: {
|
||||
win: 'Ctrl-F',
|
||||
mac: 'Command-F'
|
||||
},
|
||||
exec: function( e ) {
|
||||
_this.openSearch( 'find' );
|
||||
}
|
||||
codiad.keybindings.bindings.forEach( function( m, j, a ) {
|
||||
|
||||
i.commands.addCommand( m );
|
||||
});
|
||||
|
||||
// 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' );
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -39,6 +39,52 @@
|
|||
|
||||
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() {
|
||||
|
||||
// Active List Next [CTRL+DOWN] //////////////////////////////
|
||||
|
@ -74,6 +120,12 @@
|
|||
codiad.editor.openSearch( 'find' );
|
||||
});
|
||||
|
||||
// Find [CTRL+L] /////////////////////////////////////////////
|
||||
$.ctrl( '76', function() {
|
||||
|
||||
codiad.editor.open_goto();
|
||||
});
|
||||
|
||||
// Open in browser [CTRL+O] //////////////////////////////////
|
||||
$.ctrl( '79', function() {
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class Permissions {
|
|||
continue;
|
||||
}
|
||||
|
||||
if( $data["owner"] == 'nobody' ) {
|
||||
if( $data["owner"] == -1 ) {
|
||||
|
||||
$access = self::LEVELS["owner"];
|
||||
} elseif( $data["owner"] == $_SESSION["user_id"] ) {
|
||||
|
|
|
@ -214,7 +214,7 @@ class Project extends Common {
|
|||
WHERE path = ?
|
||||
AND (
|
||||
owner=?
|
||||
OR owner='nobody'
|
||||
OR owner=-1
|
||||
OR id IN ( SELECT project FROM access WHERE user = ? )
|
||||
) ORDER BY name;";
|
||||
$bind_variables = array( $project, $_SESSION["user_id"], $_SESSION["user_id"] );
|
||||
|
@ -258,7 +258,7 @@ class Project extends Common {
|
|||
$query = "
|
||||
SELECT * FROM projects
|
||||
WHERE owner=?
|
||||
OR owner='nobody'
|
||||
OR owner=-1
|
||||
OR id IN ( SELECT project FROM access WHERE user = ? );";
|
||||
$bind_variables = array( $_SESSION["user_id"], $_SESSION["user_id"] );
|
||||
$return = $sql->query( $query, $bind_variables, array() );
|
||||
|
@ -292,14 +292,14 @@ class Project extends Common {
|
|||
public function rename_project( $old_name, $new_name, $path ) {
|
||||
|
||||
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"] );
|
||||
$return = $sql->query( $query, $bind_variables, array() );
|
||||
$pass = false;
|
||||
|
||||
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"] );
|
||||
$return = $sql->query( $query, $bind_variables, 0, "rowCount");
|
||||
|
||||
|
@ -372,7 +372,7 @@ class Project extends Common {
|
|||
WHERE path = ?
|
||||
AND (
|
||||
owner=?
|
||||
OR owner='nobody'
|
||||
OR owner=-1
|
||||
OR id IN ( SELECT project FROM access WHERE user = ? )
|
||||
) ORDER BY name LIMIT 1;";
|
||||
$bind_variables = array( $this->path, $_SESSION["user_id"], $_SESSION["user_id"] );
|
||||
|
|
|
@ -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>
|
||||
<?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>
|
||||
|
|
|
@ -172,8 +172,8 @@ class Settings {
|
|||
|
||||
global $sql;
|
||||
|
||||
$query = "SELECT name, value FROM user_options WHERE username=?;";
|
||||
$bind_variables = array( $this->username );
|
||||
$query = "SELECT name, value FROM user_options WHERE user=?;";
|
||||
$bind_variables = array( $_SESSION["user_id"] );
|
||||
$return = $sql->query( $query, $bind_variables, array() );
|
||||
$options = array();
|
||||
|
||||
|
@ -259,21 +259,21 @@ class Settings {
|
|||
}
|
||||
} else {
|
||||
|
||||
$query = "INSERT INTO user_options ( name, user, value ) VALUES ( ?, ?, ? );";
|
||||
$query = "UPDATE user_options SET value=? WHERE name=? AND user=?;";
|
||||
$bind_variables = array(
|
||||
$value,
|
||||
$option,
|
||||
$_SESSION["user_id"],
|
||||
$value,
|
||||
);
|
||||
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
||||
|
||||
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(
|
||||
$value,
|
||||
$option,
|
||||
$_SESSION["user_id"],
|
||||
$value,
|
||||
);
|
||||
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
$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 {
|
||||
|
||||
$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"
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ if ( $_POST['action'] == 'create_default_tables' ) {
|
|||
exit( formatJSEND( "success", "Created tables." ) );
|
||||
} else {
|
||||
|
||||
exit( formatJSEND( "error", "Could not create tables." ) );
|
||||
exit( formatJSEND( "error", array( "message" => "Could not create tables.", "result" => $result ) ) );
|
||||
}
|
||||
} else {
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ class updater {
|
|||
|
||||
$sql = new sql();
|
||||
$connection = $sql->connect();
|
||||
$result = $sql->recreate_default_tables();
|
||||
$result = $sql->create_default_tables();
|
||||
$upgrade_function = str_replace( ".", "_", $this->update::VERSION );
|
||||
|
||||
if( is_callable( array( $this, $upgrade_function ) ) ) {
|
||||
|
|
|
@ -159,7 +159,7 @@ class User {
|
|||
|
||||
global $sql;
|
||||
$pass = false;
|
||||
$this->EncryptPassword();
|
||||
$password = $this->encrypt_password( $password );
|
||||
$query = "SELECT * FROM users WHERE username=? AND password=?;";
|
||||
$bind_variables = array( $username, $password );
|
||||
$return = $sql->query( $query, $bind_variables, array() );
|
||||
|
@ -198,7 +198,7 @@ class User {
|
|||
$_SESSION["login_session"] = true;
|
||||
|
||||
$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' );
|
||||
$projects = $sql->query( "SELECT path FROM projects WHERE id = ?", array( $user["project"] ), array() );
|
||||
|
||||
|
@ -294,6 +294,8 @@ class User {
|
|||
|
||||
public function Create( $username, $password ) {
|
||||
|
||||
$username = self::CleanUsername( $username );
|
||||
$password = $this->encrypt_password( $password );
|
||||
$this->add_user( $username, $password );
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ if($_GET['action']=='authenticate') {
|
|||
}
|
||||
|
||||
$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
|
||||
require_once '../../languages/code.php';
|
||||
|
@ -98,7 +98,7 @@ if($_GET['action']=='authenticate') {
|
|||
|
||||
$_SESSION['lang'] = $lang;
|
||||
$_SESSION['theme'] = $theme;
|
||||
exit( formatJSEND( "success", array( "username" => $this->username ) ) );
|
||||
exit( formatJSEND( "success", array( "username" => $username ) ) );
|
||||
} else {
|
||||
|
||||
exit( formatJSEND( "error", "Incorrect Username or Password" ) );
|
||||
|
@ -137,9 +137,7 @@ if( $_GET['action'] == 'create' ) {
|
|||
exit( formatJSEND( "error", "Invalid characters in username" ) );
|
||||
}
|
||||
|
||||
$username = User::CleanUsername( $_POST['username'] );
|
||||
$password = $User->encrypt_password( $_POST['password'] );
|
||||
$User->Create( $username, $password );
|
||||
$User->Create( $_POST['username'], $_POST['password'] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue