Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
314 lines (290 sloc) 16.7 KB
<?php
/**
* @version 1.5.1 $Id: install.mspseniors.php
* @package Joomla 1.5.x
* @subpackage MSP-seniors
* @copyright (C) 2009 Miami Solution Providers Inc (http://www.causewaycomputer.com)
* @license GNU/GPL
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
$action = $_REQUEST['action'];
switch($action) {
case 'add':
case 'edit':
add_edit();
break;
case 'save':
save();
break;
case 'publish':
publish();
break;
case 'unpublish':
unpublish();
break;
case 'delete':
delete();
break;
default:
display();
break;
}
function display() {
include_once(JPATH_BASE.DS."components".DS."com_mspseniors".DS."includes".DS."admin.mspheader.php");
###############
global $mainframe;
$limit1 = 0;
$limit2 = 0;
$pa = 0;
if($_REQUEST['limit'] > 0) {
$limit2 = $_REQUEST['limit'];
}
else {
$limit2 = $mainframe->getCfg('list_limit');
}
if($_REQUEST['page'] > 0) {
$pa = $_REQUEST['page'];
}
else {
$pa = 1;
}
$limit1 = $limit2 * ($pa-1);
$database =& JFactory::getDBO();
$database->setQuery("select count(*) as tot from `#__".MSP_TABLE_PREFIX."` where 1");
$cnt = $database->loadObject();
$total_page = ceil($cnt->tot/$limit2);
$database->setQuery("select * from `#__".MSP_TABLE_PREFIX."` where 1 order by `date` desc, `id` desc limit ".$limit1.",".$limit2."");
$items = $database->loadObjectList();
?>
<div>
<div>&nbsp;</div>
<table width="100%" cellpadding="0" cellspacing="0"><tr><td><h1>Manage Seniors</h1></td><td align="right"><a href="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&action=add&page=<?php echo $_REQUEST['page']; ?>&limit=<?php echo $_REQUEST['limit']; ?>" title="Add New Senior"><img src="images/new_f2.png" border="0" alt="Edit" /></a></td></tr></table>
</div>
<div>&nbsp;</div>
<div id="editcell">
<table class="adminlist">
<thead>
<tr>
<th width="5">#</th>
<th class="title">Name</th>
<th class="title">Email</th>
<th class="title">Address</th>
<th class="title">Phone</th>
<th class="title">Flower</th>
<th class="title">Comment</th>
<th nowrap="nowrap">Published</th>
<th width="5" nowrap="nowrap">ID</th>
<th class="title">Edit</th>
<th class="title">Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="19">
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<del class="container"><div class="pagination">
<div class="limit">Display #:
<select name="limit" id="limit" class="inputbox" size="1" onchange="MM_jumpMenu('parent',this,0)">
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=5" <?php if ($limit2 == '5') : ?>selected="selected"<?php endif; ?>>5</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=10" <?php if ($limit2 == '10') : ?>selected="selected"<?php endif; ?>>10</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=15" <?php if ($limit2 == '15') : ?>selected="selected"<?php endif; ?>>15</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=20" <?php if ($limit2 == '20') : ?>selected="selected"<?php endif; ?>>20</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=25" <?php if ($limit2 == '25') : ?>selected="selected"<?php endif; ?>>25</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=30" <?php if ($limit2 == '30') : ?>selected="selected"<?php endif; ?>>30</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=50" <?php if ($limit2 == '50') : ?>selected="selected"<?php endif; ?>>50</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=100" <?php if ($limit2 == '100') : ?>selected="selected"<?php endif; ?>>100</option>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=1&limit=999999" <?php if ($limit2 == '999999') : ?>selected="selected"<?php endif; ?>>all</option>
</select> | Page:
<select name="page" id="page" class="inputbox" size="1" onchange="MM_jumpMenu('parent',this,0)">
<?php for($i=1;$i<=$total_page;$i++) { ?>
<option value="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=<?php echo $i; ?>&limit=<?php echo $limit2; ?>" <?php if ($i == $pa) : ?>selected="selected"<?php endif; ?>><?php echo $i; ?></option>
<?php } ?>
</select>
</div>
</div></del> </td>
</tr>
</tfoot>
<tbody>
<?php
$cnt = 1;
foreach ($items as $item) {
?>
<tr class="row<?php echo ($cnt%2); ?>">
<td valign="top"><?php echo $cnt; ?></td>
<td valign="top"><?php echo $item->fname.' '.$item->lname; ?><?php if($item->status=='2') { ?><img src="images/new_f2.png" border="0" alt="New Senior" height="16" width="16" /><?php } ?></td>
<td align="center" valign="top"><?php echo $item->email; ?></td>
<td align="center" valign="top"><?php echo $item->address1; ?></td>
<td align="center" valign="top"><?php echo $item->phone; ?></td>
<td align="center" valign="top"><?php echo $item->flower; ?></td>
<td valign="top"><?php echo $item->comment; ?></td>
<td align="center" valign="top">
<?php if($item->status == 1) { ?>
<a href="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&action=unpublish&id=<?php echo $item->id; ?>&page=<?php echo $_REQUEST['page']; ?>&limit=<?php echo $_REQUEST['limit']; ?>" title="Unpublish Item"><img src="images/tick.png" border="0" alt="Published" /></a>
<?php } else { ?>
<a href="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&action=publish&id=<?php echo $item->id; ?>&page=<?php echo $_REQUEST['page']; ?>&limit=<?php echo $_REQUEST['limit']; ?>" title="Publish Item"><img src="images/publish_x.png" border="0" alt="Unpublished" /></a>
<?php } ?> </td>
<td align="center" valign="top"><?php echo $item->id; ?></td>
<td align="center" valign="top"><a href="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&action=edit&id=<?php echo $item->id; ?>&page=<?php echo $_REQUEST['page']; ?>&limit=<?php echo $_REQUEST['limit']; ?>" title="Edit Item"><img src="images/edit_f2.png" border="0" alt="Edit" /></a></td>
<td align="center" valign="top"><a href="index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&action=delete&id=<?php echo $item->id; ?>&page=<?php echo $_REQUEST['page']; ?>&limit=<?php echo $_REQUEST['limit']; ?>" title="Delete Item" onclick="javascript:if(confirm('Delete Senior #<?php echo $item->id; ?>. Are you sure?')){return true;}else{return false;}"><img src="images/delete_f2.png" border="0" alt="Delete" /></a></td>
</tr>
<?php
$cnt++;
}
if($cnt == 1) {
?>
<tr><td colspan="19">No Seniors Found.</td></tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
include_once(JPATH_BASE.DS."components".DS."com_mspseniors".DS."includes".DS."admin.mspfooter.php");
###############
}
function publish() {
$database =& JFactory::getDBO();
$database->setQuery("update `#__".MSP_TABLE_PREFIX."` set `status`='1' where `id`='".$_REQUEST['id']."'");
$database->query();
header("location:index.php?option=".$_REQUEST['option']."&task=".$_REQUEST['task']."&page=".$_REQUEST['page']."&limit=".$_REQUEST['limit']."&result=true");
exit();
}
function unpublish() {
$database =& JFactory::getDBO();
$database->setQuery("update `#__".MSP_TABLE_PREFIX."` set `status`='0' where `id`='".$_REQUEST['id']."'");
$database->query();
header("location:index.php?option=".$_REQUEST['option']."&task=".$_REQUEST['task']."&page=".$_REQUEST['page']."&limit=".$_REQUEST['limit']."&result=true");
exit();
}
function delete() {
$database =& JFactory::getDBO();
$database->setQuery("delete from `#__".MSP_TABLE_PREFIX."` where `id`='".$_REQUEST['id']."'");
$database->query();
header("location:index.php?option=".$_REQUEST['option']."&task=".$_REQUEST['task']."&page=".$_REQUEST['page']."&limit=".$_REQUEST['limit']."&result=true");
exit();
}
function add_edit() {
include_once(JPATH_BASE.DS."components".DS."com_mspseniors".DS."includes".DS."admin.mspheader.php");
###############
if($_REQUEST['id'] > 0) {
$database =& JFactory::getDBO();
### Old query
###$database->setQuery("select * from `#__".MSP_TABLE_PREFIX."` where `id`='".$_REQUEST['id']."'");
### updated
$database->setQuery("select jos_mspseniors.fname, jos_mspseniors.lname, jos_mspseniors.email, jos_mspseniors.flower, jos_mspseniors.about, jos_mspseniors.address1, jos_mspseniors.address2, jos_mspseniors.city, jos_mspseniors.zip, jos_mspseniors.date, jos_mspseniors.comment, jos_mspseniors.phone, jos_mspseniors.location, jos_mspschools.schoolname from `#__".MSP_TABLE_PREFIX."` , `#__".MSP_TABLE_PREFIX_SCHOOL."` where jos_mspschools.id = jos_mspseniors.school_id;");
$row = $database->loadObject();
}
###############
?>
<div>
<div><h1><?php echo ucfirst(strtolower($_REQUEST['action'])); ?> Seniors</h1></div>
<div>&nbsp;</div>
</div>
<fieldset class="adminform">
<legend>Details</legend>
<script type="text/javascript">
function submitFormRS() {
var f = document.adminFormRS;
if(trim(f.fname.value) == '') {
alert("Please enter first name.");
f.fname.focus();
return false;
}
if(trim(f.lname.value) == '') {
alert("Please enter last name.");
f.lname.focus();
return false;
}
if(trim(f.email.value) == '') {
alert("Please enter email address.");
f.email.focus();
return false;
}
if((/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z.]{2,5}$/).exec(f.email.value)==null) {
alert("Please enter valid email");
f.email.focus();
return false;
}
f.submit();
}
function cancelFormRS() {
location.href='index.php?option=<?php echo $_REQUEST['option']; ?>&task=<?php echo $_REQUEST['task']; ?>&page=<?php echo $_REQUEST['page']; ?>&limit=<?php echo $_REQUEST['limit']; ?>';
}
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
</script>
<form action="index.php" method="post" name="adminFormRS" id="adminFormRS" onsubmit="return submitFormRS();">
<input type="hidden" name="option" id="option" value="<?php echo $_REQUEST['option']; ?>" />
<input type="hidden" name="task" id="task" value="<?php echo $_REQUEST['task']; ?>" />
<input type="hidden" name="action" id="action" value="save" />
<input type="hidden" name="id" id="id" value="<?php echo $row->id; ?>" />
<input type="hidden" name="page" id="page" value="<?php echo $_REQUEST['page']; ?>" />
<input type="hidden" name="limit" id="limit" value="<?php echo $_REQUEST['limit']; ?>" />
<table class="admintable" style="width:50%;">
<tr><td colspan="3" style="text-align:right;" class="key"><span style="color:red;">*</span> fields are mandatory.</td></tr>
<tr><td class="key">Senior First Name:<span style="color:red;">*</span></td><td colspan="2"><input name="fname" id="fname" type="text" maxlength="50" style="width:100%;" value="<?php echo $row->fname; ?>" /></td></tr>
<tr><td class="key">Senior Last Name:<span style="color:red;">*</span></td><td colspan="2"><input name="lname" id="lname" type="text" maxlength="50" style="width:100%;" value="<?php echo $row->lname; ?>" /></td></tr>
<tr><td class="key">Email Address:<span style="color:red;">*</span></td><td colspan="2"><input name="email" id="email" type="text" maxlength="100" style="width:100%;" value="<?php echo $row->email; ?>" /></td></tr>
<tr><td class="key">School:<span style="color:red;">*</span></td><td colspan="2"><input name="school" id="school" type="text" maxlength="100" style="width:100%;" value="<?php echo $row->email; ?>" /></td></tr>
<tr><td class="key">Password Key:<span style="color:red;">*</span></td><td colspan="2"><input name="password" id="password" type="text" maxlength="100" style="width:100%;" value="<?php echo $row->flower; ?>" /></td></tr>
<tr><td class="key">About Submitter:</td><td colspan="2"><input name="about" id="about" type="text" style="width:100%;" value="<?php echo $row->about; ?>" /></td></tr>
<tr><td class="key">Picture Location:</td><td colspan="2"><input name="location" id="location" type="text" maxlength="255" style="width:100%;" value="<?php echo $row->location; ?>" /></td></tr>
<tr><td class="key">Address1:</td><td colspan="2"><input name="address1" id="address1" type="text" maxlength="255" style="width:100%;" value="<?php echo $row->address1; ?>" /></td></tr>
<tr><td class="key">Address2:</td><td colspan="2"><input name="address2" id="address2" type="text" maxlength="255" style="width:100%;" value="<?php echo $row->address2; ?>" /></td></tr>
<tr><td class="key">City:</td><td colspan="2"><input name="city" id="city" type="text" maxlength="255" style="width:100%;" value="<?php echo $row->city; ?>" /></td></tr>
<tr><td class="key">Zip</td><td colspan="2"><input name="zip" id="zip" type="text" maxlength="255" style="width:100%;" value="<?php echo $row->zip; ?>" /></td></tr>
<tr><td class="key">Phone Number:</td><td colspan="2"><input name="location" id="location" type="text" maxlength="255" style="width:100%;" value="<?php echo $row->phone; ?>" /></td></tr>
<tr><td class="key">Date of Posting:<br />( yyyy-mm-dd )</td><td><input name="posting_date" id="posting_date" type="text" maxlength="255" style="width:100%;" value="<?php echo ($row->date ? $row->date : date('Y-m-d')); ?>" /></td></tr>
<tr><td colspan="3" class="key" style="text-align:left;">Comments:</td></tr>
<tr><td colspan="3"><textarea name="comments" id="comments" style="width:100%; height:150px;"><?php echo $row->comment; ?></textarea></td></tr>
<tr><td colspan="3" style="text-align:center;"><input type="button" value="Submit New Senior" class="button" style="width:auto;" onClick="return submitFormRS();" /> <input type="button" value="Cancel" class="button" style="width:auto;" onClick="return cancelFormRS();" /></td></tr>
</table>
</form>
</fieldset>
<?php
###############
include_once(JPATH_BASE.DS."components".DS."com_mspseniors".DS."includes".DS."admin.mspfooter.php");
###############
}
function save() {
foreach($_POST as $key=>$value) {
$_POST[$key] = addslashes($value);
}
$database =& JFactory::getDBO();
$postingArr = explode("-",$_POST['posting_date']);
$mktime = mktime(12, 0, 0, $postingArr[1], $postingArr[2], $postingArr[0]);
if(date('Y', $mktime) > 1979) {
$date = date('Y-m-d', $mktime);
}
else {
$date = date('Y-m-d');
}
if($_POST['id']>0) {
$database->setQuery("update `#__".MSP_TABLE_PREFIX."` set `fname`='".$_POST['fname']."', `lname`='".$_POST['lname']."', `address1`='".$_POST['address1']."', `address2`='".$_POST['address2']."', `city`='".$_POST['city']."',`state`='".$_POST['state']."', `zip`='".$_POST['zip']."', `phone`='".$_POST['phone']."', `about`='".$_POST['about']."', `location`='".$_POST['location']."', `website`='".$_POST['website']."', `email`='".$_POST['email']."', `comment`='".$_POST['comments']."', `date`='".$date."' where `id`='".$_POST['id']."'");
}
else {
$database->setQuery("insert into `#__".MSP_TABLE_PREFIX."`(`id`, `fname`, `lname`, `address1`, `address2`, `city`, `state`, `zip`, `phone`, `about`, `location`, `website`, `email`, `comment`, `date`, `status`) values('', '".$_POST['fname']."', '".$_POST['lname']."', '".$_POST['address1']."', '".$_POST['address2']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."', '".$_POST['phone']."', '".$_POST['about']."', '".$_POST['location']."', '".$_POST['website']."', '".$_POST['email']."', '".$_POST['comments']."', '".$date."', '1')");
}
$database->query();
header("location:index.php?option=".$_REQUEST['option']."&task=".$_REQUEST['task']."&page=".$_REQUEST['page']."&limit=".$_REQUEST['limit']."&result=true");
exit();
}
?>
Something went wrong with that request. Please try again.