Skip to content

Commit

Permalink
Now works!
Browse files Browse the repository at this point in the history
  • Loading branch information
pasamio committed Nov 22, 2007
1 parent 91984f8 commit 77303b0
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 102 deletions.
Expand Up @@ -27,7 +27,7 @@
* @subpackage Newsfeeds
*/
class HTML_personalcontent {

function showSelection( &$rows, &$lists, $pageNav, $option ) {
global $my;

Expand All @@ -37,7 +37,7 @@ function showSelection( &$rows, &$lists, $pageNav, $option ) {
<table class="adminheading">
<tr>
<th>
Selected Newsflash Manager
Personal Content Manager
</th>
</tr>
</table>
Expand All @@ -51,25 +51,24 @@ function showSelection( &$rows, &$lists, $pageNav, $option ) {
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />
</th>
<th class="title">
Article Title
User
</th>
<th width="5%">
Published
<th class="title">
Article Title
</th>

</tr>
<?php
$k = 0;
for ($i=0, $n=count( $rows ); $i < $n; $i++) {
$row = &$rows[$i];

$link = 'index2.php?option=com_newsfeeds&task=editA&hidemainmenu=1&id='. $row->id;
$link = 'index2.php?option=com_newsfeeds&task=editA&hidemainmenu=1&uid='. $row->uid;

$img = $row->published ? 'tick.png' : 'publish_x.png';
/* $img = $row->published ? 'tick.png' : 'publish_x.png';
$task = $row->published ? 'unpublish' : 'publish';
$alt = $row->published ? 'Published' : 'Unpublished';

$checked = '<input id="cb'.$i.'" name="cid[]" value="'.$row->id.'" onclick="isChecked(this.checked);" type="checkbox">';
*/
$checked = '<input id="cb'.$i.'" name="cid[]" value="'.$row->uid.'" onclick="isChecked(this.checked);" type="checkbox">';
?>
<tr class="<?php echo 'row'. $k; ?>">
<td align="center">
Expand All @@ -78,14 +77,13 @@ function showSelection( &$rows, &$lists, $pageNav, $option ) {
<td>
<?php echo $checked; ?>
</td>
<td><a href="index2.php?option=com_personalcontent&task=edit&uid=<?php echo $row->uid ?>">
<?php echo $row->username ? $row->username : 'Anonymous' ?>
</a>
</td>
<td>
<?php echo $row->title; ?>
</td>
<td width="10%" align="center">
<a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')">
<img src="images/<?php echo $img;?>" border="0" alt="<?php echo $alt; ?>" />
</a>
</td>
</tr>
<?php
$k = 1 - $k;
Expand All @@ -102,7 +100,7 @@ function showSelection( &$rows, &$lists, $pageNav, $option ) {
<?php
}

function newNewsflash( $option ) {
function newPersonalContent( $option, $row, $users ) {
?>
<script language="JavaScript">
// This code was a quick mock up to test AJAX integration in a Joomla framework (mambots)
Expand All @@ -123,7 +121,7 @@ function preSearch() {
}
//If the form data is *not* blank, query the DB and return the results
if(theQuery !== "") {
xajax_ajaxDoArticleSearch(theQuery);
xajax_ajaxDoArticleSearch(theQuery,'cid');
} else {
// xajax_ajaxDoArticleSearch("%");
}
Expand All @@ -135,7 +133,7 @@ function preSearch() {
<table class="adminheading">
<tr>
<th>
Select new Newsflash
Select new content item
</th>
</tr>
</table>
Expand All @@ -150,17 +148,18 @@ function preSearch() {
Content ID:
</td>
<td>
<input class="inputbox" type="text" size="40" id="contentid" name="contentid" value="">
<input class="inputbox" type="text" size="40" id="cid" name="cid" value="<?php echo $row->cid ?>">
</td>
</tr>
<tr>
<td>
Published:
User ID:
</td>
<td>
<input type="checkbox" class="inputbox" name="published">
<?php echo $users ?>
<!-- <input class="inputbox" type="text" size="40" id="uid" name="uid" value="<?php echo $row->uid ?>"> -->
</td>
</tr>
</tr>
<tr>
</table>

Expand Down
107 changes: 48 additions & 59 deletions personal_content/trunk/com_personalcontent/admin.personalcontent.php
Expand Up @@ -3,6 +3,7 @@
* Personal Content System
*
* This handles the main logic of the application
* Code borrowed from Sam Moffatt's Selected Newsflash System
*
* PHP4/5
*
Expand All @@ -25,35 +26,39 @@
require_once( $mainframe->getPath( 'admin_html' ) );
require_once( $mainframe->getPath( 'class' ) );

$task = mosGetParam( $_REQUEST, 'task', array(0) );
$task = mosGetParam( $_REQUEST, 'task', '' );
$cid = mosGetParam( $_POST, 'cid', array(0) );
$id = mosGetParam( $_GET, 'id', 0 );
$uid = mosGetParam( $_GET, 'uid', 0 );
if (!is_array( $cid )) {
$cid = array(0);
}

switch ($task) {

case 'new':
newNewsflash( $option );
newPersonalContent( $option );
break;

case 'save':
saveNewsflash( $option );
savePersonalContent( $option );
break;

case 'publish':
publishNewsflash( $cid, 1, $option );
publishPersonalContent( $cid, 1, $option );
break;

case 'unpublish':
publishNewsflash( $cid, 0, $option );
publishPersonalContent( $cid, 0, $option );
break;

case 'remove':
removeNewsflash( $cid, $option );
removePersonalContent( $cid, $option );
break;


case 'edit':
edit($uid, $option);
break;

default:
showSelection( $option );
break;
Expand All @@ -72,21 +77,21 @@ function showSelection( $option ) {

// get the total number of records

$query = "SELECT COUNT(*) FROM #__selectednewsflash";
$query = "SELECT COUNT(*) FROM #__personal_content";
$database->setQuery( $query );
$total = $database->loadResult();

require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
$pageNav = new mosPageNav( $total, $limitstart, $limit );

// get the subset (based on limits) of required records
$query = "SELECT b.id, b.contentid, a.title, b.published"
$query = "SELECT b.uid, b.cid, a.title, c.username"
."\n FROM #__content AS a"
."\n INNER JOIN #__selectednewsflash AS b ON b.contentid = a.id"
."\n INNER JOIN #__personal_content AS b ON b.cid = a.id"
."\n LEFT JOIN #__users AS c ON b.uid = c.id"
."\n WHERE state != 0"
."\n ORDER BY a.ordering"
. "\n LIMIT $pageNav->limitstart, $pageNav->limit";


$database->setQuery( $query );

Expand All @@ -97,87 +102,71 @@ function showSelection( $option ) {
}


HTML_selectednewsflash::showSelection( $rows, $lists, $pageNav, $option );
HTML_personalcontent::showSelection( $rows, $lists, $pageNav, $option );
}

/**
* Creates a new record
* Edits a records
* @param string The current GET/POST option
*/
function newNewsflash( $option ) {
global $database, $mainframe, $my, $mosConfig_absolute_path, $mosConfig_offset;

function edit( $uid, $option ) {
global $database, $mainframe;
$row = new pasPersonalContent($database);
$row->load($uid);
xajaxstart();
$users = mosAdminMenus::UserSelect( 'uid', $row->uid );
HTML_personalcontent::newPersonalContent($option,$row, $users);
}

function xajaxstart() {
global $mosConfig_absolute_path;
// Sam Moffatt's AJAX Server Framework (based on XAJAX)
include $mosConfig_absolute_path . '/administrator/components/com_ajaxserver/ajax/includes/xajax.common.php';
ajax_generateServer($server);
$server->printJavaScript();
HTML_selectednewsflash::newNewsflash( $option );
}

/**
* Creates a new record
*/
function newPersonalContent( $option ) {
global $database, $mainframe, $my, $mosConfig_absolute_path, $mosConfig_offset;

xajaxstart();
$row = new pasPersonalContent($database);
$users = mosAdminMenus::UserSelect( 'uid', $row->uid );
HTML_personalcontent::newPersonalContent( $option, $row, $users );

}

/**
* Saves the record from an edit form submit
* @param string The current GET/POST option
*/
function saveNewsflash( $option ) {
function savePersonalContent( $option ) {
global $database, $my;

$row = new pasSelectedNewsflash( $database );
$row = new paspersonalcontent( $database );
if (!$row->bind( $_POST )) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}

if($row->published == 'on') {
$row->published = 1;
} else {
$row->published = 0;
}

// save the changes
if (!$row->store()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}

mosRedirect( 'index2.php?option='. $option );
}

/**
* Publishes or Unpublishes one or more modules
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The current GET/POST option
*/
function publishNewsflash( $cid, $publish, $option ) {
global $database, $my;

if (count( $cid ) < 1) {
$action = $publish ? 'publish' : 'unpublish';
echo "<script> alert('Select a module to $action'); window.history.go(-1);</script>\n";
exit;
}

$cids = implode( ',', $cid );

$query = "UPDATE #__selectednewsflash"
. "\n SET published = ". intval( $publish )
. "\n WHERE id IN ( $cids )"
;
$database->setQuery( $query );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit();
}

mosRedirect( 'index2.php?option='. $option );
}

/**
* Removes records
* @param array An array of id keys to remove
* @param string The current GET/POST option
*/
function removeNewsflash( &$cid, $option ) {
function removePersonalContent( &$cid, $option ) {
global $database;

if (!is_array( $cid ) || count( $cid ) < 1) {
Expand All @@ -186,8 +175,8 @@ function removeNewsflash( &$cid, $option ) {
}
if (count( $cid )) {
$cids = implode( ',', $cid );
$query = "DELETE FROM #__selectednewsflash"
. "\n WHERE id IN ( $cids )"
$query = "DELETE FROM #__personal_content"
. "\n WHERE uid IN ( $cids )"
;

$database->setQuery( $query );
Expand Down
Expand Up @@ -16,7 +16,7 @@
CREATE TABLE `#__personal_content` (
`uid` INT(12) NOT NULL,
`cid` INT(12) NOT NULL,
PRIMARY KEY(`uid`,`cid`)
PRIMARY KEY(`uid`)
) COMMENT = 'Personal Content Manager Table';
</query>
</queries>
Expand Down
@@ -1,6 +1,6 @@
<?php
/**
* Selected Newsflash Class
* Personal Content Class
* @author Samuel Moffatt <pasamio@pasamio.id.au>
* @copyright Copyright (C) 2006 Samuel Moffatt. All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
Expand All @@ -19,7 +19,24 @@ class pasPersonalContent extends mosDBTable {
* @param database A database connector object
*/
function pasPersonalContent( &$db ) {
$this->mosDBTable( '#__personal_content', 'id', $db );
$this->mosDBTable( '#__personal_content', 'uid', $db );
}

function store( $updateNulls=false ) {
$this->_db->setQuery('SELECT cid FROM #__personal_content WHERE uid = '. $this->uid );
$result = intval($this->_db->loadResult());
if($result) {
$ret = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
} else {
$ret = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
}

if (!$ret) {
$this->_error = strtolower(get_class($this))."::store failed <br />" . $this->_db->getErrorMsg();
return false;
} else {
return true;
}
}
}
?>
@@ -1,6 +1,6 @@
<?php
/**
* Selected Newsflash toolbar - HTML
* Personal Content toolbar - HTML
* @author Samuel Moffatt <pasamio@pasamio.id.au>
* @copyright Copyright (C) 2006 Samuel Moffatt. All rights reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
Expand All @@ -12,9 +12,6 @@
class TOOLBAR_personalcontent {
function _DEFAULT() {
mosMenuBar::startTable();
mosMenuBar::publishList();
mosMenuBar::spacer();
mosMenuBar::unpublishList();
mosMenuBar::spacer();
mosMenuBar::deleteList();
mosMenuBar::spacer();
Expand Down

0 comments on commit 77303b0

Please sign in to comment.