acl_check ( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) | $acl->acl_check ( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_dailymessage' ))) {
SendRedirect ( 'index2.php', _NOT_AUTH );
}
}
/***************************************************************
// Query for our configuration data
***************************************************************/
$query = "SELECT * FROM `#__ionfile_conf`";
$database = get_db ();
/***************************************************************
// Run SQL Command
***************************************************************/
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
/***************************************************************
// Insert default data if the
// row doesn't exist.
***************************************************************/
if (count ( $rows ) < 1) {
$query = "INSERT INTO `#__ionfile_conf`
(hdr_text,show_size,show_ver,show_lic,show_icon,show_dl,
show_desc,show_hdr,show_totals,show_hdr_desc,hdr_desc_text,allow_direct)
VALUES ('Downloads',1,0,0,0,1,0,1,0,1,'Description',0);"; //<- May need to be changed in future versions, stores the default .
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
}
/***************************************************************/
// Count the category rows
/***************************************************************/
$query_count = "SELECT * FROM #__ionfile_categories";
$database->setQuery ( $query_count );
$rows_count = $database->loadObjectList ();
$total = count ( $rows_count );
/***************************************************************/
// Get our absolute path
/***************************************************************/
$pageNav = pageNavWrap ( $total );
/***************************************************************/
// Send up an error message if error occured
/***************************************************************/
if ($database->getErrorNum ()) {
print $database->stderr ();
return false;
}
/***************************************************************/
// Retrieve our HTML File
/***************************************************************/
if (defined ( '_JEXEC' )) {
require_once (JApplicationHelper::getPath ( 'admin_html' ));
} else {
require_once ($mainframe->getPath ( 'admin_html' ));
}
/***************************************************************/
// get parameters from the URL or submitted form
/***************************************************************/
$cid = mosGetParam ( $_REQUEST, 'cid', array (0 ) );
$act = mosGetParam ( $_REQUEST, 'act' );
$task = mosGetParam ( $_REQUEST, 'task' );
$id = mosGetParam ( $_REQUEST, 'id' );
if (! is_array ( $cid )) {
$cid = array (0 );
}
/***************************************************************/
// Determine which function the user wants
/***************************************************************/
switch ( $act) {
case "mancats" :
switch ( $task) {
case 'publish' :
publishCategories ( intval ( $id ), $cid, 1 );
break;
case 'new' :
editCategory ( 0 );
break;
case 'unpublish' :
publishCategories ( intval ( $id ), $cid, 0 );
break;
case 'edit' :
editCategory ( intval ( $cid [0] ) );
break;
case 'remove' :
removeCategories ( $cid );
break;
case 'add' :
editCategory ( 0 );
break;
case 'orderup' :
orderCategory ( intval ( $cid [0] ), - 1 );
break;
case 'orderdown' :
orderCategory ( intval ( $cid [0] ), 1 );
break;
case 'saveorder' :
saveOrder ( $cid, $section );
break;
default :
listCats ( $option );
break;
}
break;
case "manfiles" :
switch ( $task) {
case 'newfile' :
editFile ( 0 );
break;
case 'editF' :
editFile ( intval ( $cid [0] ) );
break;
case 'editAF' :
editFile ( intval ( $id ) );
break;
case 'applyF' :
case 'saveF' :
saveFile ( $task );
break;
case 'publishF' :
publishFiles ( intval ( $id ), $cid, 1 );
break;
case 'unpublishF' :
publishFiles ( intval ( $id ), $cid, 0 );
break;
case 'archive' :
archiveFiles ( intval ( $id ), $cid, 1 );
break;
case 'unarchive' :
archiveFiles ( intval ( $id ), $cid, 0 );
break;
case 'cancelF' :
cancelFile ();
break;
case 'removeF' :
removeFiles ( $cid );
break;
case 'orderupF' :
orderFile ( intval ( $cid [0] ), - 1 );
break;
case 'orderdownF' :
orderFile ( intval ( $cid [0] ), 1 );
break;
case 'saveorderF' :
saveOrderF ( $cid, $section );
break;
default :
listFiles ( $option );
break;
}
break;
case "config" :
switch ( $task) {
default :
config ();
break;
}
break;
case "check" : //<--Version Check
doVersionCheck ();
break;
case "help" : //<--Help file
displayHelpFile ();
break;
default :
switch ( $task) {
case 'add' :
editCategory ( 0 );
break;
case 'edit' :
editCategory ( intval ( $cid [0] ) );
break;
case 'editA' :
editCategory ( intval ( $id ) );
break;
case 'newfile' :
editFile ( 0 );
break;
case 'editF' :
editFile ( intval ( $cid [0] ) );
break;
case 'editAF' :
editFile ( intval ( $id ) );
break;
case 'go2menu' :
case 'go2menuitem' :
case 'menulink' :
case 'save' :
case 'apply' :
saveCategory ( $task );
break;
case 'applyF' :
case 'saveF' :
saveFile ( $task );
break;
case 'saveC' :
saveConf ();
break;
case 'cancelC' :
case 'cancel' :
cancelCategory ();
break;
case 'cancelF' :
cancelFile ();
break;
case 'publish' :
publishCategories ( intval ( $id ), $cid, 1 );
break;
case 'unpublish' :
publishCategories ( intval ( $id ), $cid, 0 );
break;
case 'publishF' :
publishFiles ( intval ( $id ), $cid, 1 );
break;
case 'unpublishF' :
publishFiles ( intval ( $id ), $cid, 0 );
break;
case 'archive' :
archiveFiles ( intval ( $id ), $cid, 1 );
break;
case 'unarchive' :
archiveFiles ( intval ( $id ), $cid, 0 );
break;
case 'orderup' :
orderCategory ( intval ( $cid [0] ), - 1 );
break;
case 'orderdown' :
orderCategory ( intval ( $cid [0] ), 1 );
break;
case 'orderupF' :
orderFile ( intval ( $cid [0] ), - 1 );
break;
case 'orderdownF' :
orderFile ( intval ( $cid [0] ), 1 );
break;
case 'saveorder' :
saveOrder ( $cid, $section );
break;
case 'saveorderF' :
saveOrderF ( $cid, $section );
break;
case 'accesspublic' :
accessMenu ( intval ( $cid [0] ), 0 );
break;
case 'accessregistered' :
accessMenu ( intval ( $cid [0] ), 1 );
break;
case 'accessspecial' :
accessMenu ( intval ( $cid [0] ), 2 );
break;
case 'accesspublicF' :
accessMenuF ( intval ( $cid [0] ), 0 );
break;
case 'accessregisteredF' :
accessMenuF ( intval ( $cid [0] ), 1 );
break;
case 'accessspecialF' :
accessMenuF ( intval ( $cid [0] ), 2 );
break;
case 'remove' :
removeCategories ( $cid );
break;
case 'removeF' :
removeFiles ( $cid );
break;
default :
default :
config ();
break;
} // End ($task)
break;
} // End ($act)
/***************************************************************
//This function checks the server for a newer version of itself.
***************************************************************/
function doVersionCheck() {
// Set our Version Information
DEFINE ( "_MY_IONFILE_VERSION", "445" ); //<--New Define
$txt = "";
if (ini_get ( 'allow_url_fopen' )) {
//
$txt_handle = fopen ( "http://www.codecall.net/ionfiles_version.v2.txt", "rt" ); //<--If your testing offline, this will halt the server.
if (feof ( $txt_handle )) {
HTML_ionFIles::showVersion ( 0, $txt );
return;
}
while ( ! feof ( $txt_handle ) ) {
$txt .= fread ( $txt_handle, 8192 );
}
fclose ( $txt_handle );
list($txt,$priority,$description) = split("|",$txt); //Must check on script use, and display a header if its critical. - (TkTech) - (ToDo)
if ((($txt) * 1) > ((_MY_IONFILE_VERSION) * 1)) //New version! Should force it to compare as a friggin int.
{
HTML_ionFiles::showVersion ( 1, $txt );
} else { //Aww nothing new
HTML_ionFIles::showVersion ( 0, $txt );
}
} else {
$txt = "";
HTML_ionFiles::showVersion ( 2, $txt );
}
}
/***************************************************************
//Calls the html for the static help page.
***************************************************************/
function displayHelpFile() {
HTML_ionFIles::showHelp ();
}
/***************************************************************
// This function lists all of the categories that are
// in the database already
***************************************************************/
function listCats($option) {
global $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path;
$database = get_db ();
if (defined ( '_JEXEC' )) {
global $option;
$limit = $mainframe->getUserStateFromRequest ( "$option.limit", 'limit', $mainframe->getCfg ( 'list_limit' ), 0 );
$limitstart = JRequest::getVar ( 'limitstart', 0, '', 'int' );
} else {
$limit = intval ( $mainframe->getUserStateFromRequest ( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
$limitstart = intval ( $mainframe->getUserStateFromRequest ( "viewlimitstart", 'limitstart', 0 ) );
}
// Select all of our categories
$query = "SELECT * FROM #__ionfile_categories" . "\n ORDER BY ordering" . "\n LIMIT $limitstart, $limit";
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
// Count our rows
$query_count = "SELECT * FROM #__ionfile_categories";
$database->setQuery ( $query_count );
$rows_count = $database->loadObjectList ();
$total = count ( $rows_count );
// Create our pageNav
$pageNav = pageNavWrap ( $total );
// Send up an error message if error occured
if ($database->getErrorNum ()) {
print $database->stderr ();
return false;
}
// Call our HTML layout
HTML_ionFiles::listCategories ( $option, $rows, $pageNav );
}
/***************************************************************
// Function to edit category settings
***************************************************************/
function editCategory($uid = 0) {
global $my;
$database = get_db ();
$query = "SELECT * FROM #__ionfile_categories WHERE id = '$uid' LIMIT 1";
$lists = array ( );
// Determine if new or editing
if ($uid) {
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
$row = $rows [0];
} else {
// do stuff for new records
$row->imagepos = 'top';
$row->ordering = 0;
$row->published = 1;
$row->link = 0;
$row->access = "Public";
$row->title = "";
$row->name = "";
$row->linkURL = "";
}
// build the html select list for ordering
$query = "SELECT ordering AS value, title AS text FROM #__ionfile_categories ORDER BY ordering";
if (defined ( '_JEXEC' )) {
$lists ['ordering'] = JHTML::_ ( 'list.specificordering', $row, '', $query, 1 );
// build the html select list for the group access
$lists ['access'] = JHTML::_ ( 'list.accesslevel', $row );
// build the html radio buttons for published
$lists ['published'] = JHTML::_ ( 'select.booleanlist', 'published', '', $row->published );
$lists ['link'] = JHTML::_ ( 'select.booleanlist', 'link', 'class="inputbox"', $row->link );
} else {
$lists ['ordering'] = mosAdminMenus::SpecificOrdering ( $row, $uid, $query );
$lists ['access'] = mosAdminMenus::Access ( $row );
// build the html radio buttons for published
$lists ['published'] = mosHTML::yesnoRadioList ( 'published', 'class="inputbox"', $row->published );
$lists ['link'] = mosHTML::yesnoRadioList ( 'link', 'class="inputbox"', $row->link );
}
// Load the edit HTML
HTML_ionFiles::edit ( $row, $lists );
}
/***************************************************************
// Edit a file settings
***************************************************************/
function editFile($uid = 0) {
global $my;
$database = get_db ();
$query = "SELECT * FROM #__ionfile WHERE id = '$uid' LIMIT 1";
// Determine if new or editing
if ($uid) {
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
$row = $rows [0];
} else {
$row->cat_id = - 1;
$row->published = 1;
$row->download = 0;
$row->ordering = 0;
$row->access = 0;
$row->id = "";
$row->description = "";
$row->title = "";
$row->name = "";
$row->file_version = "";
$row->license = "";
$row->size = "";
$row->date = "";
$row->file_url = "";
$row->info_url = "";
$row->icon_url = "";
$row->screenshot = "";
$row->author = "";
$row->homepage = "";
}
// Retrieve our category list
$query = "SELECT * FROM #__ionfile_categories";
$database->setQuery ( $query );
$categories = $database->loadObjectList ();
// Make sure the user has created at least one category
if (count ( $categories ) < 1) {
echo "\n";
SendRedirect ( 'index2.php?option=com_ionfiles&act=manfiles' );
exit ();
}
// build the html select list for ordering
$query = "SELECT ordering AS value, title AS text" . "\n FROM #__ionfile" . "\n WHERE cat_id = '$row->cat_id'" . "\n ORDER BY ordering";
if (defined ( '_JEXEC' )) {
$lists ['ordering'] = JHTML::_ ( 'list.specificordering', $row, '', $query, 1 );
// build the html select list for the group access
$lists ['access'] = JHTML::_ ( 'list.accesslevel', $row );
// build the html radio buttons for published
$lists ['published'] = JHTML::_ ( 'select.booleanlist', 'published', '', $row->published );
$lists ['download'] = JHTML::_ ( 'select.booleanlist', 'download', 'class="inputbox"', $row->download );
} else {
$lists ['ordering'] = mosAdminMenus::SpecificOrdering ( $row, $uid, $query );
$lists ['access'] = mosAdminMenus::Access ( $row );
// build the html radio buttons for published
$lists ['published'] = mosHTML::yesnoRadioList ( 'published', 'class="inputbox"', $row->published );
$lists ['download'] = mosHTML::yesnoRadioList ( 'download', 'class="inputbox"', $row->download );
}
// Load the edit HTML
HTML_ionFiles::editfiles ( $row, $lists, $categories );
}
/***************************************************************
// Saves category information
***************************************************************/
function saveCategory($task) {
$database = get_db ();
$menu = mosGetParam ( $_POST, 'menu', 'mainmenu' );
$menuid = mosGetParam ( $_POST, 'menuid', 0 );
$redirect = mosGetParam ( $_POST, 'redirect', '' );
$oldtitle = mosGetParam ( $_POST, 'oldtitle', null );
$title = mosGetParam ( $_POST, 'title', null );
$id = mosGetParam ( $_POST, 'id', 0 );
$title = addslashes ( $title );
$published = mosGetParam ( $_POST, 'published', 0 );
$name = mosGetParam ( $_POST, 'name', '' );
$access = mosGetParam ( $_POST, 'access', 1 );
$position = mosGetParam ( $_POST, 'ordering', 0 );
$link = mosGetParam ( $_POST, 'link', null );
$linkURL = mosGetParam ( $_POST, 'linkURL', null );
// Find out the position the category needs to go in
$query = "SELECT * FROM #__ionfile_categories";
$database->setquery ( $query );
$rows = $database->loadObjectList ();
// Determine our access name
switch ( $access) {
case 0 :
$groupname = "Public";
break;
case 1 :
$groupname = "Registered";
break;
default :
$groupname = "Special";
break;
}
// Make sure it doesn't exist
if ($id != 0) {
$query = "UPDATE #__ionfile_categories" . "\n SET title = '$title', name = '$name', published = '$published', ordering = '$position',
access = '$access', groupname = '$groupname', link = '$link', linkURL = '$linkURL'" . "\n WHERE id = '$id'";
} else {
$position = count ( $rows );
// Setup our query
$query = "INSERT INTO #__ionfile_categories (title, name, published, ordering, access, groupname, link, linkURL)
VALUES ('$title','$name','$published', '$position', '$access', '$groupname','$link','$linkURL')";
}
// Run our query
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
switch ( $task) {
case 'go2menu' :
SendRedirect ( 'index2.php?option=com_menus&menutype=' . $menu );
break;
case 'go2menuitem' :
SendRedirect ( 'index2.php?option=com_menus&task=edit&hidemainmenu=1&id=' . $menuid );
break;
case 'menulink' :
menuLink ( $row->id );
break;
case 'apply' :
$msg = 'Changes to Category saved';
SendRedirect ( 'index2.php?option=com_ionfiles&task=editA&hidemainmenu=1&id=' . $id, $msg );
break;
case 'save' :
default :
$msg = 'Category saved';
SendRedirect ( 'index2.php?option=com_ionfiles&act=mancats', $msg );
break;
}
}
/**
* Cancels an edit operation
* @param string The name of the category section
* @param integer A unique category id
*/
function cancelCategory() {
SendRedirect ( 'index2.php?option=com_ionfiles&act=mancats' );
}
/**
* Cancels an edit operation
* @param string The name of the category section
* @param integer A unique category id
*/
function cancelFile() {
SendRedirect ( 'index2.php?option=com_ionfiles&act=manfiles' );
}
/**
* Publishes or Unpublishes one or more categories
* @param string The name of the category section
* @param integer A unique category id (passed from an edit form)
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The name of the current user
*/
function publishCategories($categoryid = null, $cid = null, $publish = 1) {
global $my;
$database = get_db ();
if (! is_array ( $cid )) {
$cid = array ( );
}
if ($categoryid) {
$cid [] = $categoryid;
}
if (count ( $cid ) < 1) {
$action = $publish ? 'publish' : 'unpublish';
echo "\n";
exit ();
}
$cids = implode ( ',', $cid );
$query = "UPDATE #__ionfile_categories" . "\n SET published = " . intval ( $publish ) . "\n WHERE id IN ( $cids )";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
SendRedirect ( 'index2.php?option=com_ionFiles&act=mancats' );
}
/**
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderCategory($uid, $inc) {
$database = get_db ();
// Select the position of the row
$query = "SELECT * FROM #__ionfile_categories" . "\n WHERE id = '$uid'" . "\n LIMIT 1";
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
$row = $rows [0]; // Only one result
// Get the number
$orderNumber = $row->ordering;
// find the new number
$orderNumber = $orderNumber + $inc;
$inverseNumber = $orderNumber + ($inc * - 1);
// Set the old position number to the inverse
$query = "UPDATE #__ionfile_categories" . "\n SET ordering = '$inverseNumber'" . "\n WHERE ordering = '$orderNumber'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
// Set the category to the new position
$query = "UPDATE #__ionfile_categories" . "\n SET ordering = '$orderNumber'" . "\n WHERE id = '$uid'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
SendRedirect ( 'index2.php?option=com_ionFiles&act=mancats' );
}
/***************************************************************
// Saves the user defined order
***************************************************************/
function saveOrder(&$cid) {
$database = get_db ();
$total = count ( $cid );
$order = mosGetParam ( $_POST, 'order', array (0 ) );
$conditions = array ( );
// update ordering values
for($i = 0; $i < $total; $i ++) {
// Select the position of the row
$query = "SELECT * FROM #__ionfile_categories" . "\n WHERE id = '$cid[$i]'" . "\n LIMIT 1";
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
$row = $rows [0]; // Only one result
if ($row->ordering != $order [$i]) {
$row->ordering = $order [$i];
$query = "UPDATE #__ionfile_categories" . "\n SET ordering = '$order[$i]'" . "\n WHERE id = '$row->id'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
} // if
}
}
$msg = 'New ordering saved';
SendRedirect ( 'index2.php?option=com_ionFiles&act=mancats', $msg );
} // saveOrder
/**
* changes the access level of a record
* @param integer The increment to reorder by
*/
function accessMenu($uid, $access) {
$database = get_db ();
// Determine our access name
switch ( $access) {
case 0 :
$groupname = "Public";
break;
case 1 :
$groupname = "Registered";
break;
default :
$groupname = "Special";
break;
}
$query = "UPDATE #__ionfile_categories" . "\n SET access = '$access', groupname = '$groupname'" . "\n WHERE id = '$uid'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
} // if
SendRedirect ( 'index2.php?option=com_ionFiles&act=mancats' );
}
/**
* Deletes one or more categories from the categories table
* @param string The name of the category section
* @param array An array of unique category id numbers
*/
function removeCategories($cid) {
$database = get_db ();
if (count ( $cid ) < 1) {
echo "\n";
exit ();
}
$cids = implode ( ',', $cid );
// Make sure there is no files in the categories!
$query = "SELECT * from #__ionfile" . "\n WHERE cat_id in ( $cids )";
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
if (count ( $rows ) > 0) {
echo "\n";
exit ();
} // if
$query = "DELETE FROM #__ionfile_categories" . "\n WHERE id IN ( $cids )";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
} // if
SendRedirect ( 'index2.php?option=com_ionFiles&act=mancats' );
}
/***************************************************************
// This function lists all of the files that are
// in the database already
***************************************************************/
function listFiles($option) {
global $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path;
$database = get_db ();
if (defined ( '_JEXEC' )) {
global $option;
$limit = $mainframe->getUserStateFromRequest ( "$option.limit", 'limit', $mainframe->getCfg ( 'list_limit' ), 0 );
$limitstart = JRequest::getVar ( 'limitstart', 0, '', 'int' );
} else {
$limit = intval ( $mainframe->getUserStateFromRequest ( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
$limitstart = intval ( $mainframe->getUserStateFromRequest ( "viewlimitstart", 'limitstart', 0 ) );
}
$query = "SELECT * FROM #__ionfile" . "\n ORDER BY cat_id, ordering" . "\n LIMIT $limitstart, $limit";
// Select all of our categories
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
// Get our total count
$query_count = "SELECT * FROM #__ionfile";
$database->setQuery ( $query_count );
$rows_count = $database->loadObjectList ();
$total = count ( $rows_count );
// Create our pageNav
$pageNav = pageNavWrap ( $total );
// Send up an error message if error occured
if ($database->getErrorNum ()) {
print $database->stderr ();
return false;
}
// Call our HTML layout
HTML_ionFiles::listFiles ( $option, $rows, $pageNav );
}
/***************************************************************
// Save our file information after the user presses save
***************************************************************/
function saveFile($task) {
$database = get_db ();
$menu = mosGetParam ( $_POST, 'menu', 'mainmenu' );
$menuid = mosGetParam ( $_POST, 'menuid', 0 );
$oldtitle = mosGetParam ( $_POST, 'oldtitle', null );
$title = mosGetParam ( $_POST, 'title', null );
$id = mosGetParam ( $_POST, 'id', 0 );
$title = addslashes ( $title );
$published = mosGetParam ( $_POST, 'published', 0 );
$name = mosGetParam ( $_POST, 'name', 0 );
$access = mosGetParam ( $_POST, 'access', 1 );
$position = mosGetParam ( $_POST, 'ordering', 0 );
$description = mosGetParam ( $_POST, 'description', null, _MOS_ALLOWHTML );
$description = addslashes ( $description );
$version = mosGetParam ( $_POST, 'version', null );
$license = mosGetParam ( $_POST, 'license', null );
$category = mosGetParam ( $_POST, 'category', 0 );
$size = mosGetParam ( $_POST, 'size', 0 );
$date = mosGetParam ( $_POST, 'date', null );
$file_url = mosGetParam ( $_POST, 'url', null );
$info_url = mosGetParam ( $_POST, 'info_url', null );
$icon_url = mosGetParam ( $_POST, 'icon_url', null );
$screenshot = mosGetParam ( $_POST, 'screenshot', null );
$author = mosGetParam ( $_POST, 'author', null );
$author_url = mosGetParam ( $_POST, 'authorurl', null );
$download = mosGetParam ( $_POST, 'download', 0 );
$creation_date = time ();
// Find out the position the category needs to go in
$query = "SELECT * FROM #__ionfile" . "\n WHERE cat_id = '$category'";
$database->setquery ( $query );
$rows = $database->loadObjectList ();
// Determine our access name
switch ( $access) {
case 0 :
$groupname = "Public";
break;
case 1 :
$groupname = "Registered";
break;
default :
$groupname = "Special";
break;
}
// Make sure it doesn't exist
if ($id != 0) {
$query = "UPDATE #__ionfile" . "\n SET title = '$title', name = '$name', published = '$published', ordering = '$position', access = '$access', groupname = '$groupname', file_url = '$file_url', file_version = '$version', license = '$license', icon_url = '$icon_url', description = '$description', info_url = '$info_url', cat_id = '$category', size = '$size', author = '$author', date = '$date', homepage = '$author_url', screenshot = '$screenshot', download = '$download'" . "\n WHERE id = '$id'";
} else {
$position = count ( $rows );
// Setup our query
$query = "INSERT INTO #__ionfile (title, name, published, ordering, access, groupname, file_url, file_version, license, icon_url, description, info_url, cat_id, size, author, date, homepage, screenshot, download, creation_date )" . "\n VALUES ('$title','$name','$published', '$position', '$access', '$groupname', '$file_url','$version','$license','$icon_url','$description','$info_url','$category','$size','$author','$date','$author_url','$screenshot','$download', '$creation_date')";
}
// Run our query
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
switch ( $task) {
case 'apply' :
$msg = 'Changes to Category saved';
SendRedirect ( 'index2.php?option=com_ionfiles&task=editA&hidemainmenu=1&id=' . $id, $msg );
break;
case 'save' :
default :
$msg = 'File saved';
SendRedirect ( 'index2.php?option=com_ionfiles&act=manfiles', $msg );
break;
}
}
/**
* Publishes or Unpublishes one or more files
* @param string The name of the category section
* @param integer A unique category id (passed from an edit form)
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The name of the current user
*/
function publishFiles($fileid = null, $cid = null, $publish = 1) {
global $my;
$database = get_db ();
if (! is_array ( $cid )) {
$cid = array ( );
}
if ($fileid) {
$cid [] = $fileid;
}
if (count ( $cid ) < 1) {
$action = $publish ? 'publish' : 'unpublish';
echo "\n";
exit ();
}
$cids = implode ( ',', $cid );
$query = "UPDATE #__ionfile" . "\n SET published = " . intval ( $publish ) . "\n WHERE id IN ( $cids )";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
SendRedirect ( 'index2.php?option=com_ionFiles&act=manfiles' );
}
/**
* Archives or Unarchives one or more files
* @param string The name of the category section
* @param integer A unique category id (passed from an edit form)
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The name of the current user
*/
function archiveFiles($fileid = null, $cid = null, $archive = 1) {
global $my;
$database = get_db ();
if (! is_array ( $cid )) {
$cid = array ( );
}
if ($fileid) {
$cid [] = $fileid;
}
if (count ( $cid ) < 1) {
$action = $publish ? 'archive' : 'unarchive';
echo "\n";
exit ();
}
$cids = implode ( ',', $cid );
$query = "UPDATE #__ionfile" . "\n SET archived = " . intval ( $archive ) . "\n WHERE id IN ( $cids )";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
SendRedirect ( 'index2.php?option=com_ionFiles&act=manfiles' );
}
/**
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderFile($uid, $inc) {
$database = get_db ();
// Select the position of the row
$query = "SELECT * FROM #__ionfile" . "\n WHERE id = '$uid'" . "\n LIMIT 1";
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
$row = $rows [0]; // Only one result
// Get the number
$orderNumber = $row->ordering;
// find the new number
$orderNumber = $orderNumber + $inc;
$inverseNumber = $orderNumber + ($inc * - 1);
// Set the old position number to the inverse
$query = "UPDATE #__ionfile" . "\n SET ordering = '$inverseNumber'" . "\n WHERE ordering = '$orderNumber'" . "\n AND cat_id = '$row->cat_id'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
// Set the category to the new position
$query = "UPDATE #__ionfile" . "\n SET ordering = '$orderNumber'" . "\n WHERE id = '$uid'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
SendRedirect ( 'index2.php?option=com_ionFiles&act=manfiles' );
}
/**
* changes the access level of a record
* @param integer The increment to reorder by
*/
function accessMenuF($uid, $access) {
$database = get_db ();
// Determine our access name
switch ( $access) {
case 0 :
$groupname = "Public";
break;
case 1 :
$groupname = "Registered";
break;
default :
$groupname = "Special";
break;
}
$query = "UPDATE #__ionfile" . "\n SET access = '$access', groupname = '$groupname'" . "\n WHERE id = '$uid'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
} // if
SendRedirect ( 'index2.php?option=com_ionFiles&act=manfiles' );
}
/***************************************************************
// Save the order of the files
***************************************************************/
function saveOrderF(&$cid) {
$database = get_db ();
$total = count ( $cid );
$order = mosGetParam ( $_POST, 'order', array (0 ) );
$conditions = array ( );
// update ordering values
for($i = 0; $i < $total; $i ++) {
// Select the position of the row
$query = "SELECT * FROM #__ionfile" . "\n WHERE id = '$cid[$i]'" . "\n LIMIT 1";
$database->setQuery ( $query );
$rows = $database->loadObjectList ();
$row = $rows [0]; // Only one result
if ($row->ordering != $order [$i]) {
$row->ordering = $order [$i];
$query = "UPDATE #__ionfile" . "\n SET ordering = '$order[$i]'" . "\n WHERE id = '$row->id'";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
} // if
}
}
$msg = 'New ordering saved';
SendRedirect ( 'index2.php?option=com_ionFiles&act=manfiles', $msg );
} // saveOrder
/**
* Deletes one or more categories from the categories table
* @param string The name of the category section
* @param array An array of unique category id numbers
*/
function removeFiles($cid) {
$database = get_db ();
if (count ( $cid ) < 1) {
echo "\n";
exit ();
}
$cids = implode ( ',', $cid );
$query = "DELETE FROM #__ionfile" . "\n WHERE id IN ( $cids )";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
} // if
SendRedirect ( 'index2.php?option=com_ionFiles&act=manfiles' );
}
/**
* Loads the configuration html
*/
function config() {
$database = get_db ();
// Retrieve our configuration
$query = "SELECT * FROM #__ionfile_conf" . "\n LIMIT 1";
$database->setQuery ( $query );
// Get our list
$rows = $database->loadObjectList ();
$row = $rows [0]; // Only one row
// build the html select lists
if (defined ( '_JEXEC' )) {
$lists ['showhdr'] = JHTML::_ ( 'select.booleanlist', 'showhdr', 'class="inputbox', $row->show_hdr );
$lists ['showhdr'] = JHTML::_ ( 'select.booleanlist', 'showhdr', 'class="inputbox"', $row->show_hdr );
$lists ['showicon'] = JHTML::_ ( 'select.booleanlist', 'showicon', 'class="inputbox"', $row->show_icon );
$lists ['showsize'] = JHTML::_ ( 'select.booleanlist', 'showsize', 'class="inputbox"', $row->show_size );
$lists ['showver'] = JHTML::_ ( 'select.booleanlist', 'showver', 'class="inputbox"', $row->show_ver );
$lists ['showdl'] = JHTML::_ ( 'select.booleanlist', 'showdl', 'class="inputbox"', $row->show_dl );
$lists ['showdesc'] = JHTML::_ ( 'select.booleanlist', 'showdesc', 'class="inputbox"', $row->show_desc );
$lists ['showlic'] = JHTML::_ ( 'select.booleanlist', 'showlic', 'class="inputbox"', $row->show_lic );
$lists ['showhdr_desc'] = JHTML::_ ( 'select.booleanlist', 'showhdr_desc', 'class="inputbox"', $row->show_hdr_desc );
$lists ['showdate'] = JHTML::_ ( 'select.booleanlist', 'showdate', 'class="inputbox"', $row->show_date );
$lists ['showtotals'] = JHTML::_ ( 'select.booleanlist', 'showtotals', 'class="inputbox"', $row->show_totals );
$lists ['allowdirect'] = JHTML::_ ( 'select.booleanlist', 'allowdirect', 'class="inputbox"', $row->allow_direct );
$lists ['showarchive'] = JHTML::_ ( 'select.booleanlist', 'showarchive', 'class="inputbox"', $row->show_archive );
$lists ['allowcategory'] = JHTML::_ ( 'select.booleanlist', 'allowcategory', 'class="inputbox"', $row->allow_category );
$lists ['showsearch'] = JHTML::_ ( 'select.booleanlist', 'showsearch', 'class="inputbox"', $row->show_search );
$posArray = array (JHTML::_ ( 'select.option', '0', 'Top' ) );
$posArray [] = JHTML::_ ( 'select.option', '1', 'Bottom' );
$posArray [] = JHTML::_ ( 'select.option', '2', 'Both' );
$lists ['searchpos'] = JHTML::_ ( 'select.genericlist', $posArray, 'searchpos', 'class="inputbox" size="1" ', 'value', 'text', $row->search_pos );
$lists ['disablesearch'] = JHTML::_ ( 'select.booleanlist', 'disablesearch', 'class="inputbox"', $row->disable_search );
} else {
$lists ['showhdr'] = mosHTML::yesnoRadioList ( 'showhdr', 'class="inputbox"', $row->show_hdr );
$lists ['showicon'] = mosHTML::yesnoRadioList ( 'showicon', 'class="inputbox"', $row->show_icon );
$lists ['showsize'] = mosHTML::yesnoRadioList ( 'showsize', 'class="inputbox"', $row->show_size );
$lists ['showver'] = mosHTML::yesnoRadioList ( 'showver', 'class="inputbox"', $row->show_ver );
$lists ['showdl'] = mosHTML::yesnoRadioList ( 'showdl', 'class="inputbox"', $row->show_dl );
$lists ['showdesc'] = mosHTML::yesnoRadioList ( 'showdesc', 'class="inputbox"', $row->show_desc );
$lists ['showlic'] = mosHTML::yesnoRadioList ( 'showlic', 'class="inputbox"', $row->show_lic );
$lists ['showhdr_desc'] = mosHTML::yesnoRadioList ( 'showhdr_desc', 'class="inputbox"', $row->show_hdr_desc );
$lists ['showdate'] = mosHTML::yesnoRadioList ( 'showdate', 'class="inputbox"', $row->show_date );
$lists ['showtotals'] = mosHTML::yesnoRadioList ( 'showtotals', 'class="inputbox"', $row->show_totals );
$lists ['allowdirect'] = mosHTML::yesnoRadioList ( 'allowdirect', 'class="inputbox"', $row->allow_direct );
$lists ['showarchive'] = mosHTML::yesnoRadioList ( 'showarchive', 'class="inputbox"', $row->show_archive );
$lists ['allowcategory'] = mosHTML::yesnoRadioList ( 'allowcategory', 'class="inputbox"', $row->allow_category );
$lists ['showsearch'] = mosHTML::yesnoRadioList ( 'showsearch', 'class="inputbox"', $row->show_search );
$posArray = array (mosHTML::makeOption ( '0', 'Top' ) );
$posArray [] = mosHTML::makeOption ( '1', 'Bottom' );
$posArray [] = mosHTML::makeOption ( '2', 'Both' );
$lists ['searchpos'] = mosHTML::selectList ( $posArray, 'searchpos', 'size="1" class="inputbox"', 'value', 'text', 0 );
$lists ['disablesearch'] = mosHTML::yesnoRadioList ( 'disablesearch', 'class="inputbox"', $row->disable_search );
}
// Show our HTML
HTML_ionFiles::configHTML ( $row, $lists );
}
/***********************************
* This function saves the configuration
* the user creates
************************************/
function saveConf() {
$database = get_db ();
$showhdr = mosGetParam ( $_POST, 'showhdr', 1 );
$allowdirect = mosGetParam ( $_POST, 'allowdirect', 0 );
$showicon = mosGetParam ( $_POST, 'showicon', 0 );
$showsize = mosGetParam ( $_POST, 'showsize', 1 );
$showver = mosGetParam ( $_POST, 'showver', 0 );
$showdl = mosGetParam ( $_POST, 'showdl', 0 );
$showdesc = mosGetParam ( $_POST, 'showdesc', 1 );
$hdrtext = mosGetParam ( $_POST, 'hdrtext', '', _MOS_ALLOWHTML );
$showlic = mosGetParam ( $_POST, 'showlic', 0 );
$showhdr_desc = mosGetParam ( $_POST, 'showhdr_desc', 1 );
$hdrdesc_text = mosGetParam ( $_POST, 'hdrdesc_text', '', _MOS_ALLOWHTML );
$showdate = mosGetParam ( $_POST, 'showdate', 0 );
$showtotals = mosGetParam ( $_POST, 'showtotals', 0 );
$showsearch = mosGetParam ( $_POST, 'showsearch', 0 );
$allowcat = mosGetParam ( $_POST, 'allowcategory', 0 );
$showarchive = mosGetParam ( $_POST, 'showarchive', 0 );
$searchpos = mosGetParam ( $_POST, 'searchpos', 1 );
$disablesearch = mosGetParam ( $_POST, 'disablesearch', 0 );
// Erase all configuration
$query = "TRUNCATE TABLE #__ionfile_conf";
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
// Create our Query
$query = "INSERT INTO #__ionfile_conf" . "\n (hdr_text, show_size, show_ver, show_icon,show_dl, show_desc, show_hdr, show_totals, allow_direct, show_lic,
show_hdr_desc, hdr_desc_text, show_date, show_search, allow_category, show_archive, search_pos, disable_search )" . "\n VALUES ('$hdrtext','$showsize','$showver','$showicon'," . "'$showdl', '$showdesc','$showhdr', '$showtotals', '$allowdirect','$showlic','$showhdr_desc','$hdrdesc_text', '$showdate',
'$showsearch', '$allowcat', '$showarchive', '$searchpos', '$disablesearch')";
// Run our query
$database->setQuery ( $query );
if (! $database->query ()) {
echo "\n";
exit ();
}
// Set our message and Redirect
$msg = 'Configuration saved';
SendRedirect ( 'index2.php?option=com_ionfiles&act=config', $msg );
}
/***************************************************************
// Joomla 1.5/1.0 DB switch
***************************************************************/
function get_db() {
if (defined ( '_JEXEC' )) { // 1.5
// This gets the database object using the JFactory class
$database = &JFactory::getDBO ();
} else {
// Use the Joomla 1.0 database
global $database;
}
return $database;
}
/***************************************************************
// Joomla 1.5/1.0 switch for Redirects
***************************************************************/
function SendRedirect($value, $msg) {
if (defined ( '_JEXEC' )) {
global $mainframe;
$mainframe->redirect ( $value, $msg );
} else {
mosRedirect ( $value, $msg );
}
}
/***************************************************************
// Joomla 1.5/1.0 pagenav Wrap
***************************************************************/
function pageNavWrap($total) {
if (defined ( '_JEXEC' )) {
global $mainframe, $option;
$limit = $mainframe->getUserStateFromRequest ( "$option.limit", 'limit', $mainframe->getCfg ( 'list_limit' ), 0 );
$limitstart = JRequest::getVar ( 'limitstart', 0, '', 'int' );
jimport ( 'joomla.html.pagination' );
$pageNav = new JPagination ( $total, $limitstart, $limit );
} else {
global $limitstart, $limit, $mosConfig_absolute_path;
require_once ($mosConfig_absolute_path . '/administrator/includes/pageNavigation.php');
$pageNav = new mosPageNav ( $total, $limitstart, $limit );
}
return $pageNav;
}
?>