Uploads Module: Category selector

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Gorm
New Member
New Member
Posts: 6
Joined: Tue Jun 06, 2006 12:13 pm

Uploads Module: Category selector

Post by Gorm »

Ok So I got the uploads module installed - is it possible when displaying the file upload form to let the end user decide what category to upload to instead of passing the category in the smarty tag?

Thanks Gorm
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Uploads Module: Category selector

Post by calguy1000 »

Well, there's no code in there for this atm.  but westis has a user defined tag that he uses for something similar, I'll bet he'd be willing to paste it here if you can get ahold of him.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
westis

Re: Uploads Module: Category selector

Post by westis »

Hi Gorm,

I've reworked the user-defined tag a bit, but this is how I think it looked originally (thanks tsw and Calguy). I use it to display a list of upload items (Flash videos) in the selected category. Hope it can be of some help, although you need to rework it a bit for your needs.

Code: Select all

$html="";


$categories = array(
1 => array(
   'catid' => 1,
   'categoryname' => "Name of category 1"
),
2 => array(
   'catid' => 2,
   'categoryname' => "Name of category 2"
),
3 => array(
   'catid' => 3,
   'categoryname' => "Name of category 3"
),
4 => array(
   'catid' => 4,
   'categoryname' => "Name of category 4"
)
);



//post handler
$catid = '';
if($_SERVER['REQUEST_METHOD']=='POST') {
if (preg_match("/[0-9]*/" , $_POST['category_id']))
  $catid = $_POST['category_id'];
  $category=$categories[$catid]['categoryname'];
}

//form
$html .= '<form method="post">'."\n";
$html .= '<select name="category_id">'."\n";
foreach($categories as $one) {
$html .= '<option value="'. $one['catid'] .'" ';
if ($catid == $one['catid'])
$html .= 'selected';
$html .= '>'. $one['categoryname'] .'</option>'."\n";
};
$html .= '</select>'."\n";
$html .= '<input type="submit" value="Select a category" />'."\n";
$html .= '</form>'."\n";
//end form

if($catid) {
echo $html;
//Uploads module tag
global $gCms;
$mid = 'm' . ++$gCms->variables["modulenum"];
$returnid = '';
if (isset($gCms->variables['pageinfo']))
{
  $returnid = $gCms->variables['pageinfo']->content_id;
}
print_r( $parms );
$uploads = $gCms->modules['Uploads']['object'];
$parms = array();
$parms['category'] = $category;
$parms['mode'] = summary;
$parms['sortorder'] = date_desc;
$parms['summary_filetemplate'] = 'videos.tpl';
$parms['detail_filetemplate'] = 'showvideo.tpl';
$html .= $uploads->DoAction( 'default', $mid, $parms, $returnid ); 
//end Uploads module tag
} else {
//help
$html .= '<h4>Select a category</h4>';
echo $html;
}

Gorm
New Member
New Member
Posts: 6
Joined: Tue Jun 06, 2006 12:13 pm

Re: Uploads Module: Category selector

Post by Gorm »

Nice one guys (calguy for the module, and westisfor the code)

I made a new plugin like this: 

Code: Select all

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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

function smarty_cms_function_ucat($params, &$smarty)
{
$html="";


$categories = array(

1 => array(
   'catid' => 1,
   'categoryname' => "your cat1"
),
2 => array(
   'catid' => 2,
   'categoryname' => "your cat2"
)
);



//post handler
$catid = '';
if($_SERVER['REQUEST_METHOD']=='POST') {
if (preg_match("/[0-9]*/" , $_POST['category_id']))
  $catid = $_POST['category_id'];
  $category=$categories[$catid]['categoryname'];
}

//form
$html .= '<form method="post">'."\n";
$html .= '<select name="category_id">'."\n";
foreach($categories as $one) {
$html .= '<option value="'. $one['catid'] .'" ';
if ($catid == $one['catid'])
$html .= 'selected';
$html .= '>'. $one['categoryname'] .'</option>'."\n";
};
$html .= '</select>'."\n";
$html .= '<input type="submit" value="Select a category" />'."\n";
$html .= '</form>'."\n";
//end form
//////////////////////////


//////////////////////////
if($catid) {
echo $html;
//Uploads module tag
global $gCms;
$mid = 'm' . ++$gCms->variables["modulenum"];
$returnid = '';
if (isset($gCms->variables['pageinfo']))
{
  $returnid = $gCms->variables['pageinfo']->content_id;
}
print_r( $parms );
$uploads = $gCms->modules['Uploads']['object'];
$parms = array();
$parms['category'] = $category;
$parms['mode'] = summary;
$parms['sortorder'] = date_desc;
$parms['summary_filetemplate'] = 'videos.tpl';
$parms['detail_filetemplate'] = 'showvideo.tpl';
$html .= '<div class = "hr"></div>';
$html .= $uploads->DoAction( 'default', $mid, $parms, $returnid );
//end Uploads module tag

?>

<div class = "hr"></div>
<form id="m7moduleform-1" name="m7moduleform-1" method="post" action="index.php" enctype="multipart/form-data"><div class="hidden"><input name="mact" value="Uploads,m7,do_upload,0" type="hidden"><input name="m7returnid" value="43" type="hidden"></div>

<table border="0" cellpadding="2" width="100%">
  <tr>
    <td>Author</td>
    <td><input name="m7input_author" value="gorm" size="20" maxlength="255" type="text"></td>
  </tr>
  <tr>
    <td>Summary</td>
    <td><input name="m7input_summary" value="" size="40" maxlength="255" type="text"></td>
  </tr>
  <tr>
    <td>Description</td>

    <td><textarea name="m7input_description" cols="80" rows="15"></textarea></td>
  </tr>
  <tr>
    <td>Upload As</td>
    <td><input name="m7input_destname" value="" size="40" maxlength="255" type="text"></td>
  </tr>
  <tr>

    <td colspan="2"><em>Use the 'Upload As' field to change the name of the file on upload.  Leave blank to preserve the filename as-is.</em></td>
  </tr>
  <tr>
    <td>Thumbnail</td>
    <td><input name="m7input_thumbnail" type="file"></td>
  </tr>
  <tr>

    <td colspan="2"><em>An optional thumbnail file</em></td>
  </tr>
  <tr>
    <td>Allow Overwrite</td>
    <td><input name="m7input_replace" value="1" type="checkbox"></td>
  </tr>
  <tr>

    <td colspan="2"> <em>Replace any file with the same name (does not change id) CAT: <? echo $category;?></em></td>
  </tr>
  <tr>
    <td>Upload<input name="m7MAX_FILE_SIZE" value="1000000" type="hidden">
<input name="m7category" value="<? echo $category;?>" type="hidden"></td>
    <td><input name="m7input_browse" type="file"></td>
  </tr>
  <tr>
    <td><input name="m7do_uploadfile" value="Submit" type="submit"></td>
    <td> </td>
  </tr>
</table>
</form>

<?
} else {
//help
$html .= '<h4>Select a category</h4>';
echo $html;
}
}


?>



I then just stick {ucat} in my page or template.  It's a bit of a hack (I cut and pasted the generated form code from uploads) at the moment it redirects only to one page - I am gonna try and figure out how to pull the categorys/upload form in dynamically. Any advice greatfully recived.
Last edited by Gorm on Fri Jul 21, 2006 11:15 am, edited 1 time in total.
sn3p
Forum Members
Forum Members
Posts: 169
Joined: Mon Oct 15, 2007 2:27 pm

Re: Uploads Module: Category selector

Post by sn3p »

I have a different approach, with a simular result.
The following adjustments allows you to add a Category selector to your Uploads form.

Find the following lines in "function.default_uploadmode.php" (~ line 98):

Code: Select all

$hidden = 
	$this->CreateInputHidden ($id, 'MAX_FILE_SIZE', $this->GetPreference('max_uploadsize','1000000')).
	$this->CreateInputHidden( $id, 'category', $params['category']);
And replace it with:

Code: Select all

// get listable categories
$query = "SELECT upload_category_name AS category FROM ".cms_db_prefix ()."module_uploads_categories WHERE upload_category_listable = 1";
$dbresult = $db->Execute($query);

$categories = array();
while ($row = $dbresult->FetchRow()) {
	$category = $row['category'];
	$categories[$category] = $category;
}

$smarty->assign('cat_select', $this->CreateInputDropdown($id, 'category', $categories, $selectedindex=0, $selectedvalue=$params['category']));

$hidden = $this->CreateInputHidden($id, 'MAX_FILE_SIZE', $this->GetPreference('max_uploadsize','1000000'));
Use {$cat_select} in your Upload Form Template to display the Category selector.
naturelab
Forum Members
Forum Members
Posts: 169
Joined: Thu Oct 15, 2009 11:11 am

Re: Uploads Module: Category selector

Post by naturelab »

Hi sn3p :-

I would really like to implement your solution, but the uploads module has since been updated and I am not sure which part of the file to change. Any ideas ? Any help much appreciated.
naturelab
Forum Members
Forum Members
Posts: 169
Joined: Thu Oct 15, 2009 11:11 am

Re: Uploads Module: Category selector

Post by naturelab »

BTW - I am using Uploads 1.11.3 and CMS Made Simple 1.8.1 "Mankara"
User avatar
MikeTroop74
Forum Members
Forum Members
Posts: 65
Joined: Thu Oct 14, 2010 6:58 pm

Re: Uploads Module: Category selector

Post by MikeTroop74 »

naturelab wrote: Hi sn3p :-

I would really like to implement your solution, but the uploads module has since been updated and I am not sure which part of the file to change. Any ideas ? Any help much appreciated.
Did you ever get your answer to this?
Post Reply

Return to “Modules/Add-Ons”