2018-07-13 18:39:55 +02:00
|
|
|
<?php
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
|
|
|
* as-is and without warranty under the MIT License. See
|
|
|
|
* [root]/license.txt for more. This information must remain intact.
|
|
|
|
*/
|
2018-07-13 18:39:55 +02:00
|
|
|
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
require_once('../../common.php');
|
|
|
|
require_once('./class.project.php');
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Verify Session or Key
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
checkSession();
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
$Project = new Project();
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Get Current Project
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
$no_return = false;
|
2018-07-13 18:39:55 +02:00
|
|
|
if (isset($_GET['no_return'])) {
|
2018-10-11 16:17:41 +02:00
|
|
|
$no_return = true;
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($_GET['action']=='get_current') {
|
2018-10-11 16:17:41 +02:00
|
|
|
|
|
|
|
if ( ! isset($_SESSION['project'])) {
|
|
|
|
// Load default/first project
|
|
|
|
if ($no_return) {
|
|
|
|
$Project->no_return = true;
|
|
|
|
}
|
|
|
|
$Project->GetFirst();
|
|
|
|
} else {
|
|
|
|
// Load current
|
|
|
|
$Project->path = $_SESSION['project'];
|
|
|
|
$project_name = $Project->GetName();
|
|
|
|
if (!$no_return) {
|
|
|
|
echo formatJSEND("success", array("name"=>$project_name,"path"=>$_SESSION['project']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Open Project
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
|
|
|
if ($_GET['action']=='open') {
|
2018-10-11 16:17:41 +02:00
|
|
|
if (!checkPath($_GET['path'])) {
|
|
|
|
die(formatJSEND("error", "No Access to path " . $_GET['path']));
|
|
|
|
}
|
|
|
|
$Project->path = $_GET['path'];
|
|
|
|
$Project->Open();
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Create Project
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
|
|
|
if ($_GET['action']=='create') {
|
2018-10-11 16:17:41 +02:00
|
|
|
if (checkAccess()) {
|
|
|
|
$Project->name = $_GET['project_name'];
|
|
|
|
if ($_GET['project_path'] != '') {
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
} else {
|
|
|
|
$Project->path = $_GET['project_name'];
|
|
|
|
}
|
|
|
|
// Git Clone?
|
|
|
|
if (!empty($_GET['git_repo'])) {
|
|
|
|
$Project->gitrepo = $_GET['git_repo'];
|
|
|
|
$Project->gitbranch = $_GET['git_branch'];
|
|
|
|
}
|
|
|
|
$Project->Create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Rename Project
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
|
|
|
if ($_GET['action']=='rename') {
|
2018-10-11 16:17:41 +02:00
|
|
|
if (!checkPath($_GET['project_path'])) {
|
|
|
|
die(formatJSEND("error", "No Access"));
|
|
|
|
}
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
$Project->Rename();
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Delete Project
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
|
|
|
if ($_GET['action']=='delete') {
|
2018-10-11 16:17:41 +02:00
|
|
|
if (checkAccess()) {
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
$Project->Delete();
|
|
|
|
}
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Return Current
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
|
|
|
if ($_GET['action']=='current') {
|
2018-10-11 16:17:41 +02:00
|
|
|
if (isset($_SESSION['project'])) {
|
|
|
|
echo formatJSEND("success", $_SESSION['project']);
|
|
|
|
} else {
|
|
|
|
echo formatJSEND("error", "No Project Returned");
|
|
|
|
}
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|