2018-07-13 18:39:55 +02:00
< ? php
2018-10-09 21:30:00 +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-09 21:30:00 +02:00
require_once ( '../../common.php' );
2018-10-11 16:17:41 +02:00
require_once ( './class.project.php' );
2018-10-09 21:30:00 +02:00
//////////////////////////////////////////////////////////////////
// Verify Session or Key
//////////////////////////////////////////////////////////////////
checkSession ();
2018-10-11 16:17:41 +02:00
$Project = new Project ;
2018-10-09 21:30:00 +02:00
switch ( $_GET [ 'action' ] ) {
//////////////////////////////////////////////////////////////
// List Projects Mini Sidebar
//////////////////////////////////////////////////////////////
case 'sidelist' :
// Get projects data
2018-10-11 16:17:41 +02:00
$projects = $Project -> get_projects ();
2018-10-09 21:30:00 +02:00
?>
< ul >
< ? php
2018-10-11 16:17:41 +02:00
//natcasesort( $projects );
2018-10-09 21:30:00 +02:00
foreach ( $projects as $project => $data ) {
2018-10-09 22:04:48 +02:00
if ( $_GET [ 'trigger' ] == 'true' ) {
2018-10-09 21:30:00 +02:00
?>
2018-10-09 22:04:48 +02:00
< li onclick = " codiad.project.open('<?php echo( $data['path'] );?>'); " >< div class = " icon-archive icon " ></ div >< ? php echo ( $data [ 'name' ] ); ?> </li>
< ? php
} else {
2018-10-09 21:30:00 +02:00
2018-10-09 22:04:48 +02:00
?>
< li ondblclick = " codiad.project.open('<?php echo( $data['path'] );?>'); " >< div class = " icon-archive icon " ></ div >< ? php echo ( $data [ 'name' ] ); ?> </li>
2018-10-09 21:30:00 +02:00
< ? php
}
}
?>
</ ul >
< ? php
break ;
//////////////////////////////////////////////////////////////
// List Projects
//////////////////////////////////////////////////////////////
case 'list' :
2018-10-11 16:17:41 +02:00
//Get projects data
2019-07-08 19:44:17 +02:00
if ( isset ( $_GET [ " all " ] ) ) {
$projects = $Project -> get_all_projects ();
} else {
$projects = $Project -> get_projects ();
}
2018-10-11 16:17:41 +02:00
?>
< label >< ? php i18n ( " Project List " ); ?> </label>
< div id = " project-list " >
< table width = " 100% " >
< tr >
< th width = " 70 " >< ? php i18n ( " Open " ); ?> </th>
< th width = " 150 " >< ? php i18n ( " Project Name " ); ?> </th>
< th width = " 250 " >< ? php i18n ( " Path " ); ?> </th>
2018-11-10 06:41:28 +01:00
< th width = " 70 " >< ? php i18n ( " Access " ); ?> </th>
< th width = " 70 " >< ? php i18n ( " Delete " ); ?> </th>
2018-10-11 16:17:41 +02:00
</ tr >
</ table >
< div class = " project-wrapper " >
< table width = " 100% " style = " word-wrap: break-word;word-break: break-all; " >
< ? php
2019-07-08 19:44:17 +02:00
if ( is_array ( $projects ) ) {
2018-10-11 16:17:41 +02:00
2019-07-08 19:44:17 +02:00
foreach ( $projects as $project => $data ) {
2018-10-11 16:17:41 +02:00
2019-07-08 19:44:17 +02:00
$show = true ;
if ( $show ) {
2018-11-10 06:41:28 +01:00
?>
2019-07-08 19:44:17 +02:00
< tr >
< td width = " 70 " >< a onclick = " codiad.project.open('<?php echo( $data['path'] );?>'); " class = " icon-folder bigger-icon " ></ a ></ td >
< td width = " 150 " >< ? php echo ( $data [ 'name' ]); ?> </td>
< td width = " 250 " >< ? php echo ( $data [ 'path' ]); ?> </td>
2019-06-26 22:45:44 +02:00
< ? php
2019-07-08 19:44:17 +02:00
$owner = $Project -> get_owner ( $data [ 'path' ] );
2019-10-25 18:46:23 +02:00
if ( $owner == - 1 ) {
2019-07-08 19:44:17 +02:00
?>
< td width = " 70 " >< a onclick = " codiad.message.error(i18n('Public projects can not be managed')); " class = " icon-block bigger-icon " ></ a ></ td >
< ? php
2019-10-16 16:20:09 +02:00
} elseif ( $owner !== $_SESSION [ " user_id " ] ) {
2019-07-08 19:44:17 +02:00
?>
< td width = " 70 " >< a onclick = " codiad.message.error(i18n('Projects owned by others can not be managed')); " class = " icon-block bigger-icon " ></ a ></ td >
< ? php
} else {
?>
< td width = " 70 " >< a onclick = " codiad.project.manage_access( '<?php echo( $data['path'] );?>' ); " class = " icon-lock bigger-icon " ></ a ></ td >
< ? php
}
2019-06-26 22:45:44 +02:00
?>
2018-11-10 06:41:28 +01:00
< ? php
2019-07-08 19:44:17 +02:00
if ( $_SESSION [ 'project' ] == $data [ 'path' ] ) {
?>
< td width = " 70 " >< a onclick = " codiad.message.error(i18n('Active Project Cannot Be Removed')); " class = " icon-block bigger-icon " ></ a ></ td >
< ? php
2019-10-25 18:46:23 +02:00
} elseif ( $owner !== $_SESSION [ " user_id " ] && $owner != - 1 ) {
2019-07-08 19:44:17 +02:00
?>
< td width = " 70 " >< a onclick = " codiad.message.error(i18n('Projects owned by others can not be deleted')); " class = " icon-block bigger-icon " ></ a ></ td >
< ? php
} else {
?>
< td width = " 70 " >< a onclick = " codiad.project.delete('<?php echo( $data['name'] );?>','<?php echo( $data['path'] );?>'); " class = " icon-cancel-circled bigger-icon " ></ a ></ td >
< ? php
}
2018-11-10 06:41:28 +01:00
?>
2019-07-08 19:44:17 +02:00
</ tr >
< ? php
}
2018-10-11 16:17:41 +02:00
}
2019-07-08 19:44:17 +02:00
} else {
$error = json_decode ( $projects , true );
echo $error [ " message " ];
2018-10-11 16:17:41 +02:00
}
?>
</ table >
</ div >
</ div >
2018-11-10 06:41:28 +01:00
< button class = " btn-left " onclick = " codiad.project.create(); " >< ? php i18n ( " New Project " ); ?> </button>
< button class = " btn-right " onclick = " codiad.modal.unload();return false; " >< ? php i18n ( " Close " ); ?> </button>
2018-10-11 16:17:41 +02:00
< ? php
2018-10-09 21:30:00 +02:00
break ;
//////////////////////////////////////////////////////////////////////
// Create New Project
//////////////////////////////////////////////////////////////////////
case 'create' :
2018-11-10 06:41:28 +01:00
?>
< form >
< label >< ? php i18n ( " Project Name " ); ?> </label>
< input name = " project_name " autofocus = " autofocus " autocomplete = " off " >
< label >< ? php i18n ( " Folder Name or Absolute Path " ); ?> </label>
< input name = " project_path " autofocus = " off " autocomplete = " off " >
< label >< ? php i18n ( " Public Project " ); ?> </label>
< select name = " public_project " >
< option value = " false " > False </ option >
< option value = " true " > True </ option >
</ select >
< p >< small >< i > Note : Everyone will have full access to public projects .</ i ></ small ></ p >
<!-- Clone From GitHub -->
< div style = " width: 500px; " >
< table class = " hide " id = " git-clone " >
< tr >
< td >
< label >< ? php i18n ( " Git Repository " ); ?> </label>
< input name = " git_repo " >
</ td >
< td width = " 5% " >& nbsp ; </ td >
< td width = " 25% " >
< label >< ? php i18n ( " Branch " ); ?> </label>
< input name = " git_branch " value = " master " >
</ td >
</ tr >
< tr >
< td colspan = " 3 " class = " note " >< ? php i18n ( " Note: This will only work if your Git repo DOES NOT require interactive authentication and your server has git installed. " ); ?> </td>
</ tr >
</ table >
</ div >
<!-- / Clone From GitHub -->
< ? php
$action = 'codiad.project.list();' ;
if ( $_GET [ 'close' ] == 'true' ) {
$action = 'codiad.modal.unload();' ;
}
?>
< button class = " btn-left " >< ? php i18n ( " Create Project " ); ?> </button>
< button onclick = " $ ('#git-clone').slideDown(300); $ (this).hide(); return false; " class = " btn-mid " >< ? php i18n ( " ...From Git Repo " ); ?> </button>
< button class = " btn-right " onclick = " <?php echo $action ;?>return false; " >< ? php i18n ( " Cancel " ); ?> </button>
</ form >
< ? php
break ;
2018-10-09 21:30:00 +02:00
2018-11-10 06:41:28 +01:00
//////////////////////////////////////////////////////////////
// Manage Project Access
//////////////////////////////////////////////////////////////
case 'manage_access' :
/**
* Check and see if the path of the project is set . Also check and
* see if the project the user is attempting to view permissions for
* is one that they own .
*/
if ( ! isset ( $_GET [ " path " ] ) || ! $Project -> check_owner ( $_GET [ " path " ], true ) ) {
?>
< pre > Error , you either do not own this project or it is a public project .</ pre >
< ? php
return ;
}
// Get projects data
$path = $_GET [ 'path' ];
$project = $Project -> get_project ( $path );
2019-07-02 22:46:32 +02:00
$access = $Project -> get_access ( $project [ " id " ] );
2018-11-19 19:30:49 +01:00
$users = get_users ( " return " , true );
2018-11-10 06:41:28 +01:00
?>
2019-07-02 22:46:32 +02:00
< form onSubmit = " event.preventDefault(); " >
< input type = " hidden " name = " project_path " value = " <?php echo $path ;?> " >
< input type = " hidden " name = " project_id " value = " <?php echo $project["id"] ;?> " >
2018-11-10 06:41:28 +01:00
< label >< span class = " icon-pencil " ></ span >< ? php i18n ( " Add Users " ); ?> </label>
< input id = " search_users " type = " text " onkeyup = " codiad.project.search_users(); " />
2018-11-19 19:30:49 +01:00
< select id = " user_list " name = " user_list " >
2018-11-10 06:41:28 +01:00
< ? php
foreach ( $users as $user ) {
?>
2019-10-25 18:46:23 +02:00
< option value = " <?php echo htmlentities( $user["id"] );?> " >< ? php echo htmlentities ( $user [ " username " ] ); ?> </option>
2018-11-10 06:41:28 +01:00
< ? php
}
?>
</ select >
< button class = " btn-left " onclick = " codiad.project.add_user(); " > Add User </ button >
< ? php
2019-07-02 22:46:32 +02:00
if ( $access == null || empty ( $access ) ) {
2018-11-10 06:41:28 +01:00
?>
< p > No users have been given access .</ p >
< ? php
} else {
?>
< table id = " access_list " >
< ? php
2019-07-01 15:24:34 +02:00
2019-07-02 22:46:32 +02:00
$user = null ;
foreach ( $access as $row => $user_permissions ) {
2019-07-01 15:24:34 +02:00
2019-07-02 22:46:32 +02:00
foreach ( $users as $row => $current_user ) {
2019-07-01 15:24:34 +02:00
2019-07-02 22:46:32 +02:00
if ( $current_user [ " id " ] == $user_permissions [ " user " ] ) {
$user = $current_user ;
break ;
}
2019-07-01 15:24:34 +02:00
}
2018-11-10 06:41:28 +01:00
?>
< tr >
< td >
2019-07-02 22:46:32 +02:00
< p >< ? php echo htmlentities ( $user [ " username " ] ); ?> </p>
2018-11-10 06:41:28 +01:00
</ td >
< td >
2019-07-01 15:24:34 +02:00
< select onchange = " codiad.project.change_access( event ); " >
< ? php
foreach ( Permissions :: LEVELS as $level => $id ) {
2019-07-02 22:46:32 +02:00
if ( $id == $user_permissions [ " level " ] ) {
2019-07-01 15:24:34 +02:00
$selected = " selected='selected' " ;
} else {
$selected = " " ;
}
?> <option value="<?php echo $level;?>" <?php echo $selected;?>><?php echo ucfirst( $level );?></option><?php
}
?>
</ select >
2019-10-25 18:46:23 +02:00
< button class = " btn-left " onclick = " codiad.project.remove_user( '<?php echo htmlentities( $user["id"] );?>' ); " > Remove Access </ button >
2018-11-10 06:41:28 +01:00
</ td >
</ tr >
< ? php
}
?>
</ table >
< ? php
}
?>
2018-11-19 19:30:49 +01:00
< button class = " btn-right " onclick = " codiad.modal.unload();return false; " >< ? php i18n ( " Done " ); ?> </button>
2018-11-10 06:41:28 +01:00
< form >
< ? php
2018-10-09 21:30:00 +02:00
break ;
//////////////////////////////////////////////////////////////////
// Rename
//////////////////////////////////////////////////////////////////
case 'rename' :
2018-11-10 06:41:28 +01:00
?>
< form >
< input type = " hidden " name = " project_path " value = " <?php echo( $_GET['path'] );?> " >
< label >< span class = " icon-pencil " ></ span >< ? php i18n ( " Rename Project " ); ?> </label>
< input type = " text " name = " project_name " autofocus = " autofocus " autocomplete = " off " value = " <?php echo( $_GET['name'] );?> " >
< button class = " btn-left " >< ? php i18n ( " Rename " ); ?> </button> <button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n( "Cancel" );?></button>
< form >
< ? php
2018-10-09 21:30:00 +02:00
break ;
//////////////////////////////////////////////////////////////////////
// Delete Project
//////////////////////////////////////////////////////////////////////
case 'delete' :
2018-11-10 06:41:28 +01:00
?>
< form >
< input type = " hidden " name = " project_path " value = " <?php echo( $_GET['path'] );?> " >
< label >< ? php i18n ( " Confirm Project Deletion " ); ?> </label>
< pre >< ? php i18n ( " Name: " ); ?> <?php echo( $_GET['name'] );?>, <?php i18n( "Path:" )?> <?php echo( $_GET['path'] );?></pre>
< table >
< tr >
< td width = " 5 " >
< input type = " checkbox " name = " delete " id = " delete " value = " true " ></ td >
< td >< ? php i18n ( " Delete Project Files " ); ?> </td>
</ tr >
< tr >
< td width = " 5 " >< input type = " checkbox " name = " follow " id = " follow " value = " true " ></ td >
< td >< ? php i18n ( " Follow Symbolic Links " ); ?> </td>
</ tr >
</ table >
< button class = " btn-left " >< ? php i18n ( " Confirm " ); ?> </button><button class="btn-right" onclick="codiad.project.list();return false;"><?php i18n( "Cancel" );?></button>
< ? php
2018-10-09 21:30:00 +02:00
break ;
}
2018-07-13 18:39:55 +02:00
?>