families page converted
This commit is contained in:
parent
7040459d82
commit
ab7d49d757
2 changed files with 180 additions and 148 deletions
187
src/families.php
187
src/families.php
|
@ -58,10 +58,10 @@ if ($action == "delete") {
|
|||
exit;
|
||||
}
|
||||
else if ($action == "edit") {
|
||||
$query = "SELECT familyname FROM {$OPT["table_prefix"]}families WHERE familyid = " . $_GET["familyid"];
|
||||
$query = "SELECT familyname FROM {$OPT["table_prefix"]}families WHERE familyid = " . addslashes($_GET["familyid"]);
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
if ($row = mysql_fetch_array($rs,MYSQL_ASSOC)) {
|
||||
$familyname = htmlspecialchars($row["familyname"]);
|
||||
$familyname = $row["familyname"];
|
||||
}
|
||||
mysql_free_result($rs);
|
||||
}
|
||||
|
@ -105,157 +105,48 @@ else {
|
|||
exit;
|
||||
}
|
||||
|
||||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Gift Registry - Manage Families</title>
|
||||
<link href="styles.css" type="text/css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if (isset($message)) {
|
||||
echo "<span class=\"message\">" . $message . "</span>";
|
||||
}
|
||||
|
||||
$query = "SELECT f.familyid, familyname, COUNT(userid) AS members " .
|
||||
"FROM {$OPT["table_prefix"]}families f " .
|
||||
"LEFT OUTER JOIN {$OPT["table_prefix"]}memberships m ON m.familyid = f.familyid " .
|
||||
"GROUP BY f.familyid " .
|
||||
"ORDER BY familyname";
|
||||
$families = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
if ($OPT["show_helptext"]) {
|
||||
?>
|
||||
<p class="helptext">
|
||||
Here you can specify families that will use your gift registry. Members may belong to one or more family circles.<br />
|
||||
After adding a new family, click Edit to add members to it.
|
||||
</p>
|
||||
<?php
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
$families = array();
|
||||
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
|
||||
$families[] = $row;
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<table class="partbox" cellspacing="0" cellpadding="2">
|
||||
<tr class="partboxtitle">
|
||||
<td colspan="3" align="center">Families</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="colheader">Family</th>
|
||||
<th class="colheader"># Members</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
while ($row = mysql_fetch_array($families,MYSQL_ASSOC)) {
|
||||
?>
|
||||
<tr class="<?php echo (!($i++ % 2)) ? "evenrow" : "oddrow" ?>">
|
||||
<td><?php echo htmlspecialchars($row["familyname"]); ?></td>
|
||||
<td align="right"><?php echo htmlspecialchars($row["members"]); ?></td>
|
||||
<td align="right">
|
||||
<a href="families.php?action=edit&familyid=<?php echo $row["familyid"]; ?>">Edit</a>
|
||||
/
|
||||
<a href="families.php?action=delete&familyid=<?php echo $row["familyid"]; ?>">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
mysql_free_result($families);
|
||||
?>
|
||||
</table>
|
||||
</p>
|
||||
<p>
|
||||
<a href="families.php">Add a new family</a> / <a href="index.php">Back to main</a>
|
||||
</p>
|
||||
<form name="family" method="get" action="families.php">
|
||||
<?php
|
||||
if ($action == "edit" || (isset($haserror) && $action == "update")) {
|
||||
?>
|
||||
<input type="hidden" name="familyid" value="<?php echo $_GET["familyid"]; ?>">
|
||||
<input type="hidden" name="action" value="update">
|
||||
<?php
|
||||
}
|
||||
else if ($action == "" || (isset($haserror) && $action == "insert")) {
|
||||
?>
|
||||
<input type="hidden" name="action" value="insert">
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div align="center">
|
||||
<TABLE class="partbox">
|
||||
<tr class="partboxtitle">
|
||||
<td align="center" colspan="2"><?php echo ($action == "edit" ? "Edit Family '" . $familyname . "'" : "Add New Family"); ?></td>
|
||||
</tr>
|
||||
<TR valign="top">
|
||||
<TD>Family</TD>
|
||||
<TD>
|
||||
<input name="familyname" type="text" value="<?php echo $familyname; ?>" maxlength="255" size="50"/>
|
||||
<?php
|
||||
if (isset($familyname_error)) {
|
||||
?><br /><font color="red"><?php echo $familyname_error ?></font><?php
|
||||
}
|
||||
?>
|
||||
</TD>
|
||||
</TR>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<div align="center">
|
||||
<input type="submit" value="<?php if ($action == "" || $action == "insert") echo "Add"; else echo "Update"; ?>"/>
|
||||
<input type="button" value="Cancel" onClick="document.location.href='families.php';">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
mysql_free_result($rs);
|
||||
|
||||
<?php
|
||||
if ($action == "edit")
|
||||
{
|
||||
?>
|
||||
<br />
|
||||
<form name="membership" method="get" action="families.php">
|
||||
<input type="hidden" name="familyid" value="<?php echo $_GET["familyid"]; ?>">
|
||||
<input type="hidden" name="action" value="members">
|
||||
<div align="center">
|
||||
<TABLE class="partbox">
|
||||
<tr class="partboxtitle">
|
||||
<td align="center">Members of '<?php echo $familyname; ?>'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<?php
|
||||
$query = "SELECT u.userid, u.fullname, m.familyid FROM {$OPT["table_prefix"]}users u " .
|
||||
"LEFT OUTER JOIN {$OPT["table_prefix"]}memberships m ON m.userid = u.userid AND m.familyid = " . $_GET["familyid"] . " " .
|
||||
"ORDER BY u.fullname";
|
||||
$nonmembers = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
?>
|
||||
<p class="helptext">Hold CTRL while clicking to select multiple users.</p>
|
||||
<select name="members[]" size="10" multiple>
|
||||
<?php
|
||||
while ($row = mysql_fetch_array($nonmembers,MYSQL_ASSOC)) {
|
||||
echo "<option value=\"" . $row["userid"] . "\"";
|
||||
if ($row["familyid"] != "")
|
||||
echo " SELECTED";
|
||||
echo ">" . $row["fullname"] . "</value>\r\n";
|
||||
}
|
||||
mysql_free_result($nonmembers);
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div align="center">
|
||||
<input type="submit" value="Save"/>
|
||||
<input type="button" value="Cancel" onClick="document.location.href='families.php';">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
if ($action == "edit") {
|
||||
$query = "SELECT u.userid, u.fullname, m.familyid FROM {$OPT["table_prefix"]}users u " .
|
||||
"LEFT OUTER JOIN {$OPT["table_prefix"]}memberships m ON m.userid = u.userid AND m.familyid = " . addslashes($_GET["familyid"]) . " " .
|
||||
"ORDER BY u.fullname";
|
||||
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
|
||||
$nonmembers = array();
|
||||
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
|
||||
$nonmembers[] = $row;
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
mysql_free_result($rs);
|
||||
}
|
||||
|
||||
define('SMARTY_DIR',str_replace("\\","/",getcwd()).'/includes/Smarty-3.1.12/libs/');
|
||||
require_once(SMARTY_DIR . 'Smarty.class.php');
|
||||
$smarty = new Smarty();
|
||||
$smarty->assign('action', $action);
|
||||
$smarty->assign('haserror', $haserror);
|
||||
if (isset($familyname_error)) {
|
||||
$smarty->assign('familyname_error', $familyname_error);
|
||||
}
|
||||
$smarty->assign('families', $families);
|
||||
$smarty->assign('familyid', $_GET["familyid"]);
|
||||
$smarty->assign('familyname', $familyname);
|
||||
if (isset($nonmembers)) {
|
||||
$smarty->assign('nonmembers', $nonmembers);
|
||||
}
|
||||
if (isset($message)) {
|
||||
$smarty->assign('message', $message);
|
||||
}
|
||||
$smarty->assign('isadmin', $_SESSION["admin"]);
|
||||
$smarty->assign('opt', $OPT);
|
||||
$smarty->display('families.tpl');
|
||||
?>
|
||||
|
|
141
src/templates/families.tpl
Normal file
141
src/templates/families.tpl
Normal file
|
@ -0,0 +1,141 @@
|
|||
{*
|
||||
This program 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.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Gift Registry - Manage Families</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
{include file='navbar.tpl' isadmin=$isadmin}
|
||||
|
||||
<div class="container" style="padding-top: 60px;">
|
||||
|
||||
{if isset($message)}
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<div class="alert alert-info">{$message|escape:'htmlall'}</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if $opt.show_helptext}
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<div class="alert alert-info">
|
||||
Here you can specify families that will use your gift registry. Members may belong to one or more family circles.
|
||||
After adding a new family, click Edit to add members to it.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="row">
|
||||
<div class="span12">
|
||||
<div class="well">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Family</th>
|
||||
<th># Members</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$families item=row}
|
||||
<tr>
|
||||
<td>{$row.familyname|escape:'htmlall'}</td>
|
||||
<td>{$row.members}</td>
|
||||
<td>
|
||||
<a href="families.php?action=edit&familyid={$row.familyid}#familyform"><img src="images/write_obj.gif" alt="Edit Family" title="Edit Family" border="0" /></a>
|
||||
/
|
||||
<a href="families.php?action=delete&familyid={$row.familyid}"><img src="images/remove.gif" alt="Delete Family" title="Delete Family" border="0" /></a>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
<h5><a href="families.php">Add a new family</a></h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a name="familyform">
|
||||
<div class="row">
|
||||
<div class="span6">
|
||||
<form name="family" method="get" action="families.php" class="well form-horizontal">
|
||||
{if $action == "edit" || (isset($haserror) && $action == "update")}
|
||||
<input type="hidden" name="familyid" value="{$familyid}">
|
||||
<input type="hidden" name="action" value="update">
|
||||
{elseif $action == "" || (isset($haserror) && $action == "insert")}
|
||||
<input type="hidden" name="action" value="insert">
|
||||
{/if}
|
||||
<fieldset>
|
||||
<legend>{if $action == "edit" || $action == "update"}Edit family '{$familyname|escape:'htmlall'}'{else}Add Family{/if}</legend>
|
||||
<div class="control-group {if isset($familyname_error)}warning{/if}">
|
||||
<label class="control-label" for="familyname">Family name</label>
|
||||
<div class="controls">
|
||||
<input id="familyname" name="familyname" type="text" class="input-xlarge" value="{$familyname|escape:'htmlall'}" maxlength="255">
|
||||
{if isset($familyname_error)}
|
||||
<span class="help-inline">{$familyname_error|escape:'htmlall'}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">{if $action == "" || $action == "insert" || $action == "update"}Add{else}Update{/if}</button>
|
||||
<button type="button" class="btn" onClick="document.location.href='families.php';">Cancel</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{if $action == "edit"}
|
||||
<div class="span6">
|
||||
<form name="membership" method="get" action="families.php" class="well form-horizontal">
|
||||
<input type="hidden" name="familyid" value="{$familyid}">
|
||||
<input type="hidden" name="action" value="members">
|
||||
<fieldset>
|
||||
<legend>Members of '{$familyname|escape:'htmlall'}'</legend>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="members[]">Members</label>
|
||||
<div class="controls">
|
||||
<select name="members[]" size="10" multiple>
|
||||
{foreach from=$nonmembers item=row}
|
||||
<option value="{$row.userid}" {if $row.familyid != ''}SELECTED{/if}>{$row.fullname|escape:'htmlall'}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<p class="help-block">(Hold CTRL while clicking to select multiple users.)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<button type="button" class="btn" onClick="document.location.href='families.php';">Cancel</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
||||
<script src="bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue