added a way to create multiple front pages.

not implemented the front page selector yet.
This commit is contained in:
hyung-hwan 2010-02-19 09:27:33 +00:00
parent 889803afea
commit 4c40bfe770
35 changed files with 465 additions and 19 deletions

View File

@ -1,3 +1,8 @@
;------------------------------------------------------------------------------
; default site ID
;------------------------------------------------------------------------------
default_siteid = "default";
;------------------------------------------------------------------------------
; banner to display when no project id is available
;------------------------------------------------------------------------------

View File

@ -1,6 +1,17 @@
USE codepot;
CREATE TABLE site (
id VARCHAR(32) PRIMARY KEY,
name VARCHAR(128) NOT NULL,
text TEXT NOT NULL,
createdon DATETIME,
updatedon DATETIME,
createdby VARCHAR(32),
updatedby VARCHAR(32)
) charset=utf8 engine=InnoDB;
CREATE TABLE project (
id VARCHAR(32) PRIMARY KEY,
name VARCHAR(255) UNIQUE NOT NULL,
@ -62,4 +73,3 @@ CREATE TABLE file (
ON DELETE RESTRICT ON UPDATE CASCADE
) charset=utf8 engine=InnoDB;

View File

@ -5,6 +5,7 @@ www_DATA = \
index.html \
main.php \
project.php \
site.php \
source.php \
user.php \
wiki.php

View File

@ -168,6 +168,7 @@ www_DATA = \
index.html \
main.php \
project.php \
site.php \
source.php \
user.php \
wiki.php

View File

@ -0,0 +1,243 @@
<?php
class Site extends Controller
{
var $VIEW_ERROR = 'error';
var $VIEW_EDIT = 'site_edit';
var $VIEW_DELETE = 'site_delete';
function Site ()
{
parent::Controller ();
$this->load->helper ('url');
$this->load->helper ('form');
$this->load->library ('Converter', 'converter');
$this->load->model (CODEPOT_LOGIN_MODEL, 'login');
$this->load->library ('Language', 'lang');
$this->lang->load ('common', CODEPOT_LANG);
}
function _edit_site ($site, $mode, $login)
{
$this->load->helper ('form');
$this->load->library ('form_validation');
$data['login'] = $login;
// SET VALIDATION RULES
$this->form_validation->set_rules (
'site_id', 'ID', 'required|alpha_dash|max_length[32]');
$this->form_validation->set_rules (
'site_name', 'name', 'required|max_length[128]');
$this->form_validation->set_rules (
'site_text', 'text', 'required');
$this->form_validation->set_error_delimiters(
'<span class="form_field_error">','</span>');
$data['message'] = '';
$data['mode'] = $mode;
if($this->input->post('site'))
{
$tmpid = ($mode == 'update')?
$site->id: $this->input->post('site_id');
// recompose the site information from POST data.
unset ($site);
$site->id = $tmpid;
$site->name = $this->input->post('site_name');
$site->text = $this->input->post('site_text');
// validate the form
if ($this->form_validation->run())
{
// if ok, take action
$result = ($mode == 'update')?
$this->sites->update ($login['id'], $site):
$this->sites->create ($login['id'], $site);
if ($result === FALSE)
{
$data['message'] = 'DATABASE ERROR';
$data['site'] = $site;
$this->load->view ($this->VIEW_EDIT, $data);
}
else
{
//redirect ('user/home/' . $site->id);
redirect ('user/home');
}
}
else
{
// if not, reload the edit view with an error message
$data['message'] = 'Your input is not complete, Bro.';
$data['site'] = $site;
$this->load->view ($this->VIEW_EDIT, $data);
}
}
else
{
if ($mode == 'update')
{
$data['site'] = $site;
$this->load->view ($this->VIEW_EDIT, $data);
}
else
{
$data['site'] = $site;
$this->load->view ($this->VIEW_EDIT, $data);
}
}
}
function create ($siteid = "")
{
$this->load->model ('SiteModel', 'sites');
$login = $this->login->getUser ();
if ($login['id'] == '') redirect ('main/signin');
if (!$login['sysadmin?'])
{
$data['login'] = $login;
$data['message'] = "NO PERMISSION";
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
$site->id = $siteid;
$site->name = '';
$site->text = '';
$this->_edit_site ($site, 'create', $login);
}
}
function update ($siteid)
{
$this->load->model ('SiteModel', 'sites');
$login = $this->login->getUser ();
if ($login['id'] == '') redirect ('main/signin');
$site = $this->sites->get ($siteid);
if ($site === FALSE)
{
$data['login'] = $login;
$data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_ERROR, $data);
}
else if ($site === NULL)
{
$data['login'] = $login;
$data['message'] = "NO SUCH PROJECT - $siteid";
$this->load->view ($this->VIEW_ERROR, $data);
}
else if (!$login['sysadmin?'])
{
$data['login'] = $login;
$data['message'] = "NO PERMISSION - $siteid";
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
$this->_edit_site ($site, 'update', $login);
}
}
function _delete_site ($site, $login)
{
$this->load->helper ('form');
$this->load->library ('form_validation');
$data['login'] = $login;
$data['message'] = '';
$this->form_validation->set_rules ('site_confirm', 'confirm', 'alpha');
$this->form_validation->set_error_delimiters('<span class="form_field_error">','</span>');
if($this->input->post('site'))
{
/* the site form has been posted */
$data['site_confirm'] = $this->input->post('site_confirm');
if ($this->form_validation->run())
{
if ($data['site_confirm'] == 'yes')
{
$result = $this->sites->delete ($login['id'], $site);
if ($result === FALSE)
{
$data['message'] = 'DATABASE ERROR';
$data['site'] = $site;
$this->load->view ($this->VIEW_DELETE, $data);
}
else
{
// the site has been deleted successfully.
// go back to the user home.
redirect ('user/home');
}
}
else
{
// the confirm checkbox is not checked.
// go back to the site home page.
//redirect ('user/home/' . $site->id);
redirect ('user/home');
}
}
else
{
// the form validation failed.
// reload the form with an error message.
$data['message'] = "Your input is not complete, Bro.";
$data['site'] = $site;
$this->load->view ($this->VIEW_DELETE, $data);
}
}
else
{
/* no site posting is found. this is the fresh load */
$data['site_confirm'] = 'no';
$data['site'] = $site;
$this->load->view ($this->VIEW_DELETE, $data);
}
}
function delete ($siteid)
{
$this->load->model ('SiteModel', 'sites');
$login = $this->login->getUser ();
if ($login['id'] == '') redirect ('main/signin');
$site = $this->sites->get ($siteid);
if ($site === FALSE)
{
$data['login'] = $login;
$data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_ERROR, $data);
}
else if ($site === NULL)
{
$data['login'] = $login;
$data['message'] = "NO SUCH PROJECT - $siteid";
$this->load->view ($this->VIEW_ERROR, $data);
}
else if (!$login['sysadmin?'])
{
$data['login'] = $login;
$data['message'] = "NO PERMISSION - $siteid";
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
$this->_delete_site ($site, $login);
}
}
}
?>

View File

@ -31,21 +31,35 @@ class User extends Controller
redirect ('main/signin');
$this->load->model ('ProjectModel', 'projects');
$this->load->model ('SiteModel', 'sites');
$latest_projects = $this->projects->getLatestProjects ($login['id'], CODEPOT_MAX_LATEST_PROJECTS);
if ($latest_projects === FALSE)
$site = $this->sites->get (CODEPOT_DEFAULT_SITEID);
if ($site === FALSE)
{
$data['login'] = $login;
$data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_ERROR, $data);
}
else
else
{
$data['login'] = $login;
$data['latest_projects'] = $latest_projects;
$data['user_name'] = '';
$data['user_pass'] = '';
$this->load->view ($this->VIEW_HOME, $data);
$latest_projects = $this->projects->getLatestProjects ($login['id'], CODEPOT_MAX_LATEST_PROJECTS);
if ($latest_projects === FALSE)
{
$data['login'] = $login;
$data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
if ($site === NULL) $site = $this->sites->getDefault ();
$data['login'] = $login;
$data['latest_projects'] = $latest_projects;
$data['site'] = $site;
//$data['user_name'] = '';
//$data['user_pass'] = '';
$this->load->view ($this->VIEW_HOME, $data);
}
}
}

View File

@ -9,7 +9,7 @@ $lang['Delete'] = 'Hapus';
$lang['Description'] = 'Penjelasan';
$lang['Details'] = 'Detail';
$lang['Difference'] = 'Beda';
ng['Directory'] = 'Direktori';
$lang['Directory'] = 'Direktori';
$lang['Download'] = 'Download';
$lang['Edit'] = 'Rubah';
$lang['Head revision'] = 'Kepala Revisi';

View File

@ -5,6 +5,7 @@ www_DATA = \
ldaploginmodel.php \
loginmodel.php \
projectmodel.php \
sitemodel.php \
subversionmodel.php \
wikimodel.php

View File

@ -168,6 +168,7 @@ www_DATA = \
ldaploginmodel.php \
loginmodel.php \
projectmodel.php \
sitemodel.php \
subversionmodel.php \
wikimodel.php

View File

@ -0,0 +1,112 @@
<?php
class SiteModel extends Model
{
function SiteModel ()
{
parent::Model ();
$this->load->database ();
}
function getDefault ()
{
$site->id = CODEPOT_DEFAULT_SITEID;
$site->name = CODEPOT_DEFAULT_BANNER;
$site->text = '';
$site->updatedby = '';
$site->createdby = '';
$site->updatedon = 0;
$site->createdon = 0;
return $site;
}
function get ($id)
{
$this->db->trans_start ();
$this->db->where ('id', (string)$id);
$query = $this->db->get ('site');
$result = $query->result ();
if (empty($result))
{
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return NULL;
}
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return $result[0];
}
function create ($userid, $site)
{
$this->db->trans_begin ();
$this->db->set ('id', $site->id);
$this->db->set ('name', $site->name);
$this->db->set ('text', $site->text);
$this->db->set ('createdon', date('Y-m-d H:i:s'));
$this->db->set ('createdby', $userid);
$this->db->set ('updatedon', date('Y-m-d H:i:s'));
$this->db->set ('updatedby', $userid);
$this->db->insert ('site');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback ();
return FALSE;
}
else
{
$this->db->trans_commit ();
return TRUE;
}
}
function update ($userid, $site)
{
$this->db->trans_begin ();
$this->db->where ('id', $site->id);
$this->db->set ('name', $site->name);
$this->db->set ('text', $site->text);
$this->db->set ('updatedon', date('Y-m-d H:i:s'));
$this->db->set ('updatedby', $userid);
$this->db->update ('site');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback ();
return FALSE;
}
else
{
$this->db->trans_commit ();
return TRUE;
}
}
function delete ($userid, $site)
{
$this->db->trans_begin ();
$this->db->where ('id', $site->id);
$this->db->delete ('site');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback ();
return FALSE;
}
else
{
$this->db->trans_commit ();
return TRUE;
}
}
}
?>

View File

@ -13,6 +13,8 @@ www_DATA = \
project_home.php \
project_list.php \
projectbar.php \
site_edit.php \
site_delete.php \
source_blame.php \
source_diff.php \
source_file.php \

View File

@ -176,6 +176,8 @@ www_DATA = \
project_home.php \
project_list.php \
projectbar.php \
site_edit.php \
site_delete.php \
source_blame.php \
source_diff.php \
source_file.php \

View File

@ -23,6 +23,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'project' => NULL,
'pageid' => '',
'ctxmenuitems' => array ()

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'file',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'file',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'file',
'ctxmenuitems' => array (
array ("file/create/{$project->id}", $this->lang->line('New'))

View File

@ -35,6 +35,7 @@ $hexname = $this->converter->AsciiToHex ($file->name);
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'file',
'ctxmenuitems' => array (
array ("file/create/{$project->id}", $this->lang->line('New')),

View File

@ -28,6 +28,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'project' => NULL,
'pageid' => '',
'ctxmenuitems' => array ()

View File

@ -20,6 +20,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'project',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'project' => (($mode != 'create')? $project: NULL),
'pageid' => 'project',
'ctxmenuitems' => array ()

View File

@ -35,6 +35,7 @@ function render_wiki()
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'project',
'ctxmenuitems' => array (
array ("project/update/{$project->id}", $this->lang->line('Edit')),

View File

@ -25,6 +25,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'project' => NULL,
'pageid' => '',
'ctxmenuitems' => array (

View File

@ -1,10 +1,14 @@
<div class="projectbar">
<?php
function show_projectbar ($con, $project, $pageid, $ctxmenuitems)
function show_projectbar ($con, $site, $project, $pageid, $ctxmenuitems)
{
print "<div class='title'>";
print isset($project)? $project->id: CODEPOT_DEFAULT_BANNER;
if (isset($project)) print $project->id;
else if (isset($site) && $site->name != '') print htmlspecialchars($site->name);
else print htmlspecialchars(CODEPOT_DEFAULT_BANNER);
print "</div>";
print '<div class="ctxmenu">';
@ -57,7 +61,7 @@ function show_projectbar ($con, $project, $pageid, $ctxmenuitems)
print '</div>';
}
show_projectbar ($this, $project, $pageid, $ctxmenuitems);
show_projectbar ($this, $site, $project, $pageid, $ctxmenuitems);
?>
</div>

View File

@ -27,6 +27,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'source',
'ctxmenuitems' => array ()
)

View File

@ -27,6 +27,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'source',
'ctxmenuitems' => array ()
)

View File

@ -27,6 +27,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'source',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'source',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'source',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'source',
'ctxmenuitems' => array ()
)

View File

@ -4,6 +4,18 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="<?=base_url()?>/css/common.css" />
<link type="text/css" rel="stylesheet" href="<?=base_url()?>/css/project.css" />
<script type="text/javascript" src="<?=base_url()?>/js/creole.js"></script>
<script type="text/javascript">
function render_wiki()
{
creole_render_wiki (
"user_home_mainarea_textpre",
"user_home_mainarea_text",
""
);
}
</script>
<?php
$caption = $this->lang->line('Home');
if ($login['id'] != '') $caption .= "({$login['id']})";
@ -11,7 +23,7 @@
<title><?=htmlspecialchars($caption)?></title>
</head>
<body>
<body onLoad="render_wiki()">
<div class="content" id="user_home_content">
@ -22,12 +34,24 @@
<!---------------------------------------------------------------------------->
<?php
if ($login['sysadmin?'])
{
$ctxmenuitems = array (
array ("site/create", $this->lang->line('Create')),
array ("site/update/{$site->id}", $this->lang->line('Edit')),
array ("site/delete/{$site->id}", $this->lang->line('Delete'))
);
}
else $ctxmenuitems = array ();
$this->load->view (
'projectbar',
array (
'project' => NULL,
'pageid' => '',
'ctxmenuitems' => array ()
'site' => $site,
'pageid' => 'site',
'ctxmenuitems' => $ctxmenuitems
)
);
?>
@ -36,7 +60,7 @@ $this->load->view (
<div class="mainarea" id="user_home_mainarea">
<div class="sidebar">
<div class="sidebar" id="user_home_mainarea_sidebar">
<div class="box">
<div class="boxtitle"><?=$this->lang->line('Latest projects')?></div>
@ -54,7 +78,13 @@ foreach ($latest_projects as $project)
?>
</ul>
</div>
</div>
</div> <!-- user_home_mainarea_sidebar -->
<div id="user_home_mainarea_text">
<pre id="user_home_mainarea_textpre" style="visibility: hidden">
<?php print htmlspecialchars($site->text); ?>
</pre>
</div> <!-- user_home_mainarea_text -->
<!----------------------------------------------------------->

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'wiki',
'ctxmenuitems' => array ()
)

View File

@ -22,6 +22,7 @@ $hexname = $this->converter->AsciiToHex ($wiki->name);
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'wiki',
'ctxmenuitems' => array ()
)

View File

@ -21,6 +21,7 @@
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'wiki',
'ctxmenuitems' => array (
array ("wiki/create/{$project->id}", $this->lang->line('New'))

View File

@ -23,6 +23,7 @@ $hexname = $this->converter->AsciiToHex ($wiki->name);
$this->load->view (
'projectbar',
array (
'site' => NULL,
'pageid' => 'wiki',
'ctxmenuitems' => array (
array ("wiki/create/{$project->id}", $this->lang->line('New')),

View File

@ -13,8 +13,8 @@ function load_ini ($file)
if (/*$cfg === FALSE*/ $cfg == FALSE) die ("ERROR: cannot parse $file");
$xcfgs = array (
array ('default_banner', 'string', '@PACKAGE@'),
array ('default_siteid', 'string', 'default'),
array ('lang', 'string', 'english'),
array ('always_require_signin', 'boolean', FALSE),
array ('enable_websvn', 'boolean', FALSE),