Cmscout1.00rc2 > Admin / Admin Downloads.php

Questions? Need Help? Want to share? » PHP Forum
Script Name:
Cmscout1.00rc2

Download:
cmscout1.00rc2.zip

Category:
Content Management

Archive Content:

Content:

Admin

Content:

Avatars

Cache

Calendar

Calendar > Lang

Content:

Docs

Content:

Downloads

Content:

Forums

Content:

Images

Includes

Includes > Internals

Includes > Plugins

Includes

Content:

Install

Install > Templates C

Install

Content:

Photos

Pm

Content:

Sidebox

Content:

Templates > Admin

Templates > Admin > Images

Templates > Admin

Templates > CMScout

Templates > CMScout > Images

Templates > CMScout

Templates

Templates C

Content:

Tiny Mce

Tiny Mce > Langs

Tiny Mce > Plugins > Advhr

Tiny Mce > Plugins > Advhr > Images

Tiny Mce > Plugins > Advhr > Jscripts

Tiny Mce > Plugins > Advhr > Langs

Tiny Mce > Plugins > Advhr

Tiny Mce > Plugins > Advimage > Css

Tiny Mce > Plugins > Advimage

Tiny Mce > Plugins > Advimage > Images

Tiny Mce > Plugins > Advimage > Jscripts

Tiny Mce > Plugins > Advimage > Langs

Tiny Mce > Plugins > Advlink > Css

Tiny Mce > Plugins > Advlink

Tiny Mce > Plugins > Advlink > Jscripts

Tiny Mce > Plugins > Advlink > Langs

Tiny Mce > Plugins > Advlink

Tiny Mce > Plugins > Autosave

Tiny Mce > Plugins > Autosave > Langs

Tiny Mce > Plugins > Contextmenu > Css

Tiny Mce > Plugins > Contextmenu

Tiny Mce > Plugins > Contextmenu > Images

Tiny Mce > Plugins > Directionality

Tiny Mce > Plugins > Directionality > Images

Tiny Mce > Plugins > Directionality > Langs

Tiny Mce > Plugins > Emotions

Tiny Mce > Plugins > Emotions > Images

Tiny Mce > Plugins > Emotions > Jscripts

Tiny Mce > Plugins > Emotions > Langs

Tiny Mce > Plugins > Fullscreen

Tiny Mce > Plugins > Fullscreen > Images

Tiny Mce > Plugins > Fullscreen > Langs

Tiny Mce > Plugins > Ibrowser > Config

Tiny Mce > Plugins > Ibrowser > Css

Tiny Mce > Plugins > Ibrowser

Tiny Mce > Plugins > Ibrowser > Images

Tiny Mce > Plugins > Ibrowser

Tiny Mce > Plugins > Ibrowser > Interface

Tiny Mce > Plugins > Ibrowser > Interface > Images > TinyMCE

Tiny Mce > Plugins > Ibrowser > Interface

Tiny Mce > Plugins > Ibrowser > Langs

Tiny Mce > Plugins > Ibrowser > Scripts

Tiny Mce > Plugins > Ibrowser > Scripts > PhpThumb > Cache

Tiny Mce > Plugins > Ibrowser > Scripts > PhpThumb > Cache > Source

Tiny Mce > Plugins > Ibrowser > Scripts > PhpThumb > Demo

Tiny Mce > Plugins > Ibrowser > Scripts > PhpThumb > Docs

Tiny Mce > Plugins > Ibrowser > Scripts > PhpThumb > Fonts

Tiny Mce > Plugins > Ibrowser > Scripts > PhpThumb

Tiny Mce > Plugins > Ibrowser > Scripts

Tiny Mce > Plugins > Ibrowser > Temp

Tiny Mce > Plugins

Tiny Mce > Plugins > Inlinepopups > Css

Tiny Mce > Plugins > Inlinepopups

Tiny Mce > Plugins > Inlinepopups > Images

Tiny Mce > Plugins > Inlinepopups > Jscripts

Tiny Mce > Plugins > Insertdatetime

Tiny Mce > Plugins > Insertdatetime > Images

Tiny Mce > Plugins > Insertdatetime > Langs

Tiny Mce > Plugins > Paste

Tiny Mce > Plugins > Paste > Css

Tiny Mce > Plugins > Paste

Tiny Mce > Plugins > Paste > Images

Tiny Mce > Plugins > Paste > Jscripts

Tiny Mce > Plugins > Paste > Langs

Tiny Mce > Plugins > Paste

Tiny Mce > Plugins > Preview

Tiny Mce > Plugins > Preview > Images

Tiny Mce > Plugins > Preview > Langs

Tiny Mce > Plugins > Print

Tiny Mce > Plugins > Print > Images

Tiny Mce > Plugins > Print > Langs

Tiny Mce > Plugins > Searchreplace

Tiny Mce > Plugins > Searchreplace > Images

Tiny Mce > Plugins > Searchreplace > Jscripts

Tiny Mce > Plugins > Searchreplace > Langs

Tiny Mce > Plugins > Searchreplace

Tiny Mce > Plugins > Table

Tiny Mce > Plugins > Table > Css

Tiny Mce > Plugins > Table

Tiny Mce > Plugins > Table > Images

Tiny Mce > Plugins > Table > Jscripts

Tiny Mce > Plugins > Table > Langs

Tiny Mce > Plugins > Table

Tiny Mce > Themes > Advanced

Tiny Mce > Themes > Advanced > Css

Tiny Mce > Themes > Advanced > Docs > En

Tiny Mce > Themes > Advanced > Docs > En > Images

Tiny Mce > Themes > Advanced > Docs > En

Tiny Mce > Themes > Advanced > Docs > Images

Tiny Mce > Themes > Advanced

Tiny Mce > Themes > Advanced > Images

Tiny Mce > Themes > Advanced > Images > Xp

Tiny Mce > Themes > Advanced > Jscripts

Tiny Mce > Themes > Advanced > Langs

Tiny Mce > Themes > Advanced

Tiny Mce

Tiny Mce > Utils

Content:

Admin Downloads.php:


<?php
/**************************************************************************
    FILENAME        :   admin_downloads.php
    PURPOSE OF FILE :   Manage downloads and download categories
    LAST UPDATED    :   08 June 2005
    COPYRIGHT       :   © 2005 CMScout Group
    WWW             :   www.cmscout.za.org
    LICENSE         :   GPL vs2.0
    
    

    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.,  51 Franklin St,  Fifth Floor,  Boston,  MA  02110-1301  USA
**************************************************************************/
?>
<?php
if( !empty($getmodules) )
{
    
$module['Troop Content Management']['Downloads'] = "downloads";
    
$permision['Downloads'] = 2;
    return;
}

if (
$level != && $level != && $level != 0
{
 
error_message("Sorry,  you can't access this section");
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) 
{
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

$action $_GET['action'];
$id $_GET['id'];
$did $_GET['did'];

if (
$action == 'delete'
{
    
$sqlq $data->delete_query("download_cats",  "id=$id",  "",  "",  false);
    if (
$sqlq
    { 
        
$sqlq $data->delete_query("downloads", "cat=$id",  'Downloads',   "Deleted category");        
        if (
$sqlq)
        {
            echo 
"<script> alert('Download Category deleted'); window.location = '$pagename';</script>\n";
            exit; 
        }
    }

elseif (
$action == "deletedown"
{
    
$sqlq $data->delete_query("downloads",  "id=$did",  "Downloads",  "Download for category $id deleted");
    
$action "view";
    if (
$sqlq)
    {
        echo 
"<script> alert('Download deleted'); window.location = '$pagename&action=view&id=$id';</script>\n";
        exit; 
    }
}
elseif (
$action == 'publish'
{
    
$sqlq $data->update_query("downloads",  "allowed = 1",  "id=$did",  "Downloads",  "Published $did");
    
header("Location: $pagename&action=view&id=$id");
}
elseif (
$action == 'unpublish'
{
    
$sqlq $data->update_query("downloads",  "allowed = 0",  "id=$did",  "Downloads",  "Unpublished $did");
    
header("Location: $pagename&action=view&id=$id");
}


$submit $_POST['Submit'];
if (
$submit == "Submit"
{
    if (
$action == "adddown"
    {
        if (
$_POST['name'] == '')
        {
            
error_message("You need to enter a name for the download");
            exit;
        }
        if (
$_POST['desc'] == '')
        {
            
error_message("You need to enter a description for the download");
            exit;
        }
        
$name safesql($_POST['name'],  "text");
        
$desc safesql($_POST['desc'],  "text");
        
$where "../" $config['downloadpath'] . "/";
            
$message $message 'Uploading ' $_FILES['file']['name'] . ' (' .$_FILES['file']['type'] . ',  ' .ceil($_FILES['file']['size'] / 1024) . ' Kb).<br />';
            if (!
file_exists($where $_FILES['file']['name']))
            {
                
move_uploaded_file($_FILES['file']['tmp_name'], $where $_FILES['file']['name']);
            }
            
            
$file safesql($_FILES['file']['name'],  "text");
            
$sql $data->insert_query("downloads",  "'',  $name,  $desc,  '$id',  $file,  '0',  '".ceil($_FILES['file']['size'] / 1024)."', '{$check['uname']}',  1",  "Downloads",  "Added Download $name");
            
$action="view";
            if (
$sql)
            {
                echo 
"<script> alert('Download added'); window.location = '$pagename&action=view&id=$id';</script>\n";
                exit; 
            }
    } 
    elseif (
$action == "editdown"
    {
        if (
$_POST['name'] == '')
        {
            
error_message("You need to enter a name for the download");
            exit;
        }
        if (
$_POST['desc'] == '')
        {
            
error_message("You need to enter a description for the download");
            exit;
        }
        
$name safesql($_POST['name'],  "text");
        
$desc safesql($_POST['desc'],  "text");
        
$where "../" $config['downloadpath'] . "/";
        if (
$_FILES['file']['name'] != '') {    
            
$message $message 'Uploading ' $_FILES['file']['name'] . ' (' .$_FILES['file']['type'] . ',  ' .ceil($_FILES['file']['size'] / 1024) . ' Kb).<br />';
            if (
file_exists($where $_FILES['file']['name']))
            {
                
$message $message .  $_FILES['file']['name'] . ' already exists.<br> ';
                
$message $message "Using existing file on server instead.<br>";
            }
            else
            {
                echo 
$_FILES['file']['tmp_name'] . '<br>' $_FILES['file']['name'] . '<br>' .  $_FILES['file']['size'];
                
move_uploaded_file($_FILES['file']['tmp_name'], $where $_FILES['file']['name']);
                
$message $message "File successfully uploaded.<br>";
            }
            
$file safesql($_FILES['file']['name'],  "text");
            
$sql $data->update_query("downloads",  "name = $name,  descs = $desc,  file = $file",  "id = '$did'",  "Downloads",  "Changed Download $name");
        } 
        else 
        {
            
$sql $data->update_query("downloads",  "name = $name,  descs = $desc",  "id = '$did'",  "Downloads",  "Changed Download $name");
        }    
        if (
$sql)
        {
            echo 
"<script> alert('Download updated'); window.location = '$pagename&action=view&id=$id';</script>\n";
            exit; 
        }
        
$action="view";
    }
    elseif (
$action == "add")
    {
        if (
$_POST['catname'] == '')
        {
            
error_message("You need to enter a name for the category");
            exit;
        }
        
$catname safesql($_POST['catname'],  "text");
        
        
$downauths['Guest'] = $_POST['dguest'];

        
$sql $data->select_query("authteam");
        
$groups $data->fetch_array($sql);
        do { 
            
$upauths[$groups['teamname']] = $_POST["u".$groups['id']];
        } while (
$groups $data->fetch_array($sql));
        
        
$sql $data->select_query("authteam");
        
$groups $data->fetch_array($sql);
        do { 
            
$downauths[$groups['teamname']] = $_POST["d".$groups['id']];
        } while (
$groups $data->fetch_array($sql));
        
$downauths safesql(serialize($downauths),  "text");
        
$upauths safesql(serialize($upauths),  "text");
        
        
$sql $data->insert_query("download_cats",  "'',  $catname,  $upauths,  $downauths",  "Downloads",  "Added download cat $catname");
        if (
$sql)
        {
            echo 
"<script> alert('Category added'); window.location = '$pagename';</script>\n";
            exit; 
        }
        
$action "";
    }
    elseif (
$action == "edit")
    {
        if (
$_POST['catname'] == '')
        {
            
error_message("You need to enter a name for the category");
            exit;
        }
        
$catname addslashes($_POST['catname']);
        
        
$downauths['Guest'] = $_POST['dguest'];
        
$sql $data->select_query("authteam");
        
$groups $data->fetch_array($sql);
        do { 
            
$upauths[$groups['teamname']] = $_POST["u".$groups['id']];
        } while (
$groups $data->fetch_array($sql));
        
        
$sql $data->select_query("authteam");
        
$groups $data->fetch_array($sql);
        do { 
            
$downauths[$groups['teamname']] = $_POST["d".$groups['id']];
        } while (
$groups $data->fetch_array($sql));
        
        
$downauths serialize($downauths);
        
$upauths serialize($upauths);
        
        
$sql $data->update_query("download_cats",  "name = '$catname',  upauth = '$upauths',  downauth = '$downauths'",  "id = $id",  "Downloads",  "changed download cat $catname");
        if (
$sql)
        {
            echo 
"<script> alert('Category Updated'); window.location = '$pagename';</script>\n";
            exit; 
        }
    }
}

if (
$action == "view"
{
    
$query $data->select_query("download_cats",  "WHERE id = $id");
    
$catinfo $data->fetch_array($query);
    
$down_query $data->select_query("downloads",  "WHERE cat='$id'");
    
$numdown $data->num_rows($down_query);
    
$downloads = array();
    
$downloads[] = $data->fetch_array($down_query);
    while (
$downloads[] = $data->fetch_array($down_query));
    
$tpl->assign("downloads",  $downloads);
    
$tpl->assign("numdown",  $numdown);
    
$tpl->assign("catinfo",  $catinfo);
    
$tpl->assign('id',  $id);
    
$tpl->assign("downpath",  "../" $config["downloadpath"] . "/");

elseif (
$action == "adddown"
{

elseif (
$action == "editdown"
{
    
$que $data->select_query("downloads",  "WHERE id = '$did'");
    
$download $data->fetch_array($que);
    
$tpl->assign('download',  $download);

elseif (
$action == "edit")
{
    
$sql $data->select_query("download_cats",  "WHERE id = $id");
    
$cat $data->fetch_array($sql);

    
$sql $data->select_query("authteam");
    
$numgroups $data->num_rows($sql);
    
$groups = array();
    
$groups[] = $data->fetch_array($sql);
    do { } while (
$groups[] = $data->fetch_array($sql));
    
    
$authtemp unserialize($cat['upauth']);
    
$numauths count($auths);
    
$upauths = array();
    if (
$authtemp != "")
    {
        while(list(
$group,  $auth) = each($authtemp) )
        {
            
$notfound true;
            for(
$i=0;$i<count($groups);$i++)
            {
                if(
$groups[$i]['teamname'] == $group)
                {
                    
$upauths[] = $auth;
                    
$notfound false;
                }
            }
            if (
$notfound)
            {
                
$auths[] = '1';
            }
        }
    }
    
    
$authtemp unserialize($cat['downauth']);
    
$numauths count($auths);
    
$downauths = array();
    if (
$authtemp != "")
    {
        while(list(
$group,  $auth) = each($authtemp) )
        {
            
$notfound true;
            for(
$i=0;$i<count($groups);$i++)
            {
                if(
$groups[$i]['teamname'] == $group)
                {
                    
$downauths[] = $auth;
                    
$notfound false;
                }
            }
            if (
$notfound)
            {
                
$auths[] = '1';
            }
        }
    }
    
$tpl->assign('guest',  $authtemp['Guest']);
    
$tpl->assign('upauths',  $upauths);
    
$tpl->assign('downauths',  $downauths);
    
$tpl->assign('item',  $item);
    
$tpl->assign('group',  $groups);
    
$tpl->assign('numgroups',  $numgroups);
    
$tpl->assign("cat",  $cat);
}
elseif (
$action == "add")
{
    
$sql $data->select_query("authteam");
    
$numgroups $data->num_rows($sql);
    
$groups = array();
    
$groups[] = $data->fetch_array($sql);
    while (
$groups[] = $data->fetch_array($sql));
    
$tpl->assign('group',  $groups);
    
$tpl->assign('numgroups',  $numgroups);
}
else 
{
    
$cats $data->select_query("download_cats",  "ORDER BY name ASC");
    
$row_cats = array();
    
$row_cats[] = $data->fetch_array($cats);
    
$num_cats $data->num_rows($cats);
    while (
$row_cats[] = $data->fetch_array($album)); 
    
$tpl->assign('cats',  $row_cats);
    
$tpl->assign('num_cats',  $num_cats);
}

$tpl->assign('editFormAction',  $editFormAction);
$tpl->assign('id',  $id);
$tpl->assign('action',  $action);
$filetouse 'admin_downloads.tpl';
?>


Other Content Management Scripts:

WebMaster Resources Home

©RingsWorld.com