[phpwebapp-commits] CVS: top10/templates/edit_project edit_project.php,NONE,1.1 edit_project.js,NONE
Brought to you by:
dashohoxha
|
From: Dashamir H. <das...@us...> - 2003-09-30 07:06:06
|
Update of /cvsroot/phpwebapp/top10/templates/edit_project
In directory sc8-pr-cvs1:/tmp/cvs-serv19008/templates/edit_project
Added Files:
edit_project.php edit_project.js edit_project.html
edit_project.db edit_project.css
Log Message:
Adding a new project and modifying the data of an existing project.
--- NEW FILE: edit_project.php ---
<?php
/*
This file is part of Top10. Top10 is a web application for ranking
and evaluating web application projects at SourceForge.
Copyright 2003 Dashamir Hoxha, das...@us...
Top10 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
Top10 is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with Top10; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include_once FORM_PATH."formWebObj.php";
class edit_project extends formWebObj
{
function init()
{
$this->addSVar("mode", "add"); //it can be 'add' or 'edit'
$this->addSVar("proj_id", UNDEFINED);
}
function on_add($event_args)
{
//make sure that the given proj_id is unique
$proj_id = $event_args["proj_id"];
$rs = WebApp::openRS("check_proj_id", compact("proj_id"));
if (!$rs->EOF()) //there is another project with this id
{
$msg = "Another project with unix name '$proj_id' is already "
. "registered.\n"
. "Please change the unix name of the project, or, if you think "
. "that there is \n"
. "something wrong, contact the admin at '".ADMIN_EMAIL."'.";
WebApp::message($msg);
return;
}
//insert the project and change the mode of the webbox
WebApp::execDBCmd("insert_project", $event_args);
//ToDo: insert also the project members
$this->setSVar("proj_id", $proj_id);
$this->setSVar("mode", "edit");
}
function on_save($event_args)
{
$proj_id = $this->getSVar("proj_id");
if ($proj_id != $event_args["proj_id"])
{
$msg = "You cannot change the project unix name";
WebApp::message($msg);
return;
}
//...
}
function on_done($event_args)
{
}
function onRender()
{
$mode = $this->getSVar("mode");
if ($mode=="add")
{
$tpl_vars = array(
"proj_id" => "",
"proj_name" => "",
"group_id" => "",
"register_date" => date("Y-m-d"),
"license" => "GPL",
"prog_lang" => "PHP",
"category" => "",
"members" => "usr1,usr2,usr3",
"proj_descr" => ""
);
WebApp::addVars($tpl_vars);
}
else if ($mode=="edit")
{
$rs = WebApp::openRS("get_project");
WebApp::addVars($rs->Fields());
}
}
}
?>
--- NEW FILE: edit_project.js ---
// -*-C-*- //tell emacs to use C mode
function add_project()
{
save_project('add');
}
function cancel_adding()
{
select_tab('proj_list');
}
function save_project(event_name)
{
if (event_name==null) event_name = "save";
var form = document.edit_project;
//collect all the input in the form
var event_args = getEventArgs(form);
//save the input entered in the form, even if it is not
//inserted in DB (e.g. because of any error)
saveFormData(form);
SendEvent("edit_project", event_name, event_args);
}
function done_editing()
{
var msg = "This project will be added in the list\n"
+ "after it is approved by the admin.\n"
+ "You will not be able to modify it anymore.";
if (!confirm(msg)) return;
if (!no_empty_fields()) save_project('done');
}
function no_empty_fields()
{
var form = document.edit_project;
var elem;
for (i=0; form.elements[i]; i++)
{
elem = form.elements[i];
if (elem.value=='')
{
alert("Please fill the field '"+elem.name+"'.");
eval('form.'+elem.name+'.select()');
return false;
}
}
return true;
}
--- NEW FILE: edit_project.html ---
<WebBox ID="edit_project">
<If condition="'{{mode}}'=='add'">
<h2>Add New Project</h2>
</If>
<If condition="'{{mode}}'=='edit'">
<h2>Project: <a href="http://sourceforge.net/projects/{{proj_id}}"
target="_blank">{{proj_name}} ({{proj_id}})</a></h2>
</If>
<form name="edit_project" onsubmit="return false;">
<table cellspacing="1" cellpadding="2" bgcolor="#dddddd">
<tr>
<td bgcolor="eeeeee">Project Unix Name:</td>
<td bgcolor="#ffffff">
<input type="text" size="30" name="proj_id" value="{{proj_id}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">Project Name:</td>
<td bgcolor="#ffffff">
<input type="text" size="70" name="proj_name" value="{{proj_name}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">SourceForge group id:</td>
<td bgcolor="#ffffff">
<input type="text" size="30" name="group_id" value="{{group_id}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">Register Date:</td>
<td bgcolor="#ffffff">
<input type="text" size="12" name="register_date"
value="{{register_date}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">License:</td>
<td bgcolor="#ffffff">
<input type="text" size="70" name="license" value="{{license}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">Language:</td>
<td bgcolor="#ffffff">
<input type="text" size="30" name="prog_lang" value="{{prog_lang}}">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">Category:</td>
<td bgcolor="#ffffff">
<input type="text" size="70" name="category" value="{{category}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">Members:</td>
<td bgcolor="#ffffff">
<input type="text" size="70" name="members" value="{{members}}"
onfocus="select()">
</td>
</tr>
<tr>
<td bgcolor="eeeeee">Description:</td>
<td bgcolor="#ffffff">
<textarea name="proj_descr" cols="70" rows="4" onfocus="select()">{{proj_descr}}</textarea>
</td>
</tr>
</table>
</form>
<br>
<If condition="'{{mode}}'=='add'">
<a class="button" href="javascript:add_project()">Add</a>
<a class="button" href="javascript:cancel_adding()">Cancel</a>
</If>
<If condition="'{{mode}}'=='edit'">
<a class="button" href="javascript:save_project()">Save</a>
<a class="button" href="javascript:done_editing()">Done</a>
</If>
<hr>
</WebBox>
--- NEW FILE: edit_project.db ---
<!--# -*-SQL-*- #tell emacs to use SQL mode #-->
<Recordset ID="get_project">
<Query>
SELECT * FROM proj_list
WHERE proj_id = '{{edit_project->proj_id}}'
</Query>
</Recordset>
<Recordset ID="check_proj_id">
<Query>
SELECT proj_id FROM proj_list
WHERE proj_id = '{{proj_id}}'
</Query>
</Recordset>
<dbCommand ID="insert_project">
<Query>
INSERT INTO proj_list
SET
proj_id = '{{proj_id}}',
proj_name = '{{proj_name}}',
proj_descr = '{{proj_descr}}',
category = '{{category}}',
license = '{{license}}',
prog_lang = '{{prog_lang}}',
register_date = '{{register_date}}',
group_id = '{{group_id}}',
points = 0,
nr_comments = 0,
status = 'new'
</Query>
</dbCommand>
<!--# --------------------------------- #-->
<!--# members of the project #-->
<Recordset ID="members">
<Query>
SELECT username FROM proj_members
WHERE proj_id = '{{proj_id}}'
</Query>
</Recordset>
--- NEW FILE: edit_project.css ---
input, textarea
{
border: none;
font-family: arial, helvetica, sans-se;
font-size: 12pt;
color: #000044;
}
|