• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Only allow News sub category to select from on front end
PostPosted: Tue Feb 15, 2011 9:30 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Jun 08, 2007 7:29 pm
Posts: 899
Location: 's-Hertogenbosch, Netherlands
Hi,

I was struggling with the front end submission of an article. I have set up multiple categories in the News (version 2.11 with Core 1.9.2). Some of the categories have sub categories. One of the parent categories is called Review and has subcategories. The 'problem' I was facing was that I wanted to use front end entry of articles, but only allow the visitor/user to select from the sub categories of parent category Review.
As a programmer I thought of changing the code of action.fesubmit.php in the news module. However that is not upgrade friendly. I used in stead a combination of the smarty and a UDT.

In the front end template of news, you will find the following for the category selection:
Code:
   <div class="pageoverflow">
      <p class="pagetext">{$categorytext}:</p>
      <p class="pageinput">{$inputcategory}</p>
   </div>

I needed to intercept the $inputcategory variable and amend that. For that I used the following UDT:
Code:
// The list of categories build in this UDT will be used in the front end submit of reviews, to only allow
// selection of module names. This leaves room to have news about the site or news coming from
// external sources to be booked in a different category
// UDT RebuildInputCategory by Duketown 2011
$inputcategory = $params['inputcategory'];
$parentno = $params['parentno'];

// Intercept the inputcategory given by the News module.
// It also contains the return id and security id. By substringing it, we don't have to worry about that
// You might have to alter the total length of 57
$inputctg = substr($inputcategory, 0, 57);

// Build the category list
$db = cmsms()->GetDb();
$query = "SELECT * FROM ".cms_db_prefix()."module_news_categories
   WHERE parent_id = ?";
$dbresult = $db->Execute($query, array($parentno));

// Read all the categories and form options from each of them
while ($dbresult && $row = $dbresult->FetchRow()) {
    $inputctg .= '<option value="' . $row['news_category_id'] . '">';
    $inputctg .= $row['news_category_name'];
    $inputctg .= '</option>';
}
$inputctg .= '</select>';
return $inputctg;

As you see two parameters are to be passed to this UDT RebuildInputCategory. The first being the original content of $inputcategory (that is prepared by the News module. The second is the id of the parent. You can find the value that you need by editing the parent category. Look in the address bar (the URL) of your browser. The last part will contain '&m1_catid=2' (the 2 might of course be different from your parent id).
Notice that the last line of the UDT contains the variable with the option set and that it is given back to the calling part.

Now that the UDT is prepared, go back to the form template. We have to change the {$inputcategory} into the following:
Code:
{RebuildInputCategory inputcategory=$inputcategory parentno="2"}

See, I pass the two parameters to the UDT:
The first being the variable passed from the News module and the second being the parent number as found during editing the parent category.
The parentno parameter will sure have something else in your situation.

Happy UDT-ing,
Duketown
;D Donations welcome whenever we meet


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Arvixe - A CMSMS Partner