Page 1 of 1

Smarty Help

Posted: Wed Apr 25, 2007 12:48 am
by Nullig
I've not worked with smarty before, so I would appreciate some guidance.

I was trying to write a mod to display my video collection, which is in a MySQL db, and thought I should give it more options to appeal to a wider community. In working on the action.defaultadmin.php I used the company directory mod as a guideline, but I'm kinda stuck and I'm hoping that someone could point me in the right direction to code this properly.

As it stands now, the format of the admin page is wrong, with the tabs appearing below their content. I'm trying to get 3 tabs, the main one, where the data is listed, and two template edit tabs (summary and detail).

Also, how do I paginate the results? The database has 2000 entries and I would like to show only 20 at a time on the admin data list.

Here's the code from action.defaultadmin.php

Code: Select all

<?php
if (!isset($gCms)) exit;

if (! $this->CheckAccess())
	{
	return $this->DisplayErrorPage($id, $params, $returnid,$this->Lang('accessdenied'));
	}

echo $this->StartTabContent();
if ($this->CheckPermission('Add Video'))
{	
	
	echo $this->StartTab('videocollection', $params);
	
	$entryarray = array();
	
	$query = "SELECT * FROM ".cms_db_prefix()."module_video_collector ORDER BY movie_title";
	$dbresult = $db->Execute($query);
	
	$rowclass = 'row1';
	
	while ($dbresult && $row = $dbresult->FetchRow())
	{
		$onerow = new stdClass();
		
		$onerow->id = $row['id'];
		$onerow->movie_title = $row['movie_title'];
		$onerow->movie_year = $row['movie_year'];
		$onerow->IMDB_no = $row['IMDB_no'];
		$onerow->album_no = $row['album_no'];
		$onerow->page_no = $row['page_no'];
		$onerow->no_discs = $row['no_discs'];
		$onerow->scr = $row['scr'];
		
		$onerow->editlink = $this->CreateLink($id, 'editmovie', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', $this->Lang('edit'),'','','systemicon'), array('movieid'=>$row['id']));
		
		$onerow->deletelink = $this->CreateLink($id, 'deletemovie', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', $this->Lang('delete'),'','','systemicon'), array('movieid'=>$row['id']), $this->Lang('areyousure'));
		
		$entryarray[] = $onerow;

		($rowclass=="row1"?$rowclass="row2":$rowclass="row1");
	}
	
	$this->smarty->assign_by_ref('items', $entryarray);
	$this->smarty->assign('itemcount', count($entryarray));
	
	$this->smarty->assign('addlink', $this->CreateLink($id, 'addmovie', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/newfolder.gif', $this->Lang('addmovie'),'','','systemicon'), array(), '', false, false, '') .' '. $this->CreateLink($id, 'addmovie', $returnid, $this->Lang('addmovie'), array(), '', false, false, 'class="pageoptions"'));

	$this->smarty->assign('exportcsv', $this->CreateLink($id, 'exportcsv', $returnid, $this->Lang('exportcsv')));
	$this->smarty->assign('importcsv', $this->CreateLink($id, 'importcsv', $returnid, $this->Lang('importcsv')));
	
	$this->smarty->assign('movietext', $this->Lang('movie'));
	
	#Display template
	echo $this->ProcessTemplate('movielist.tpl');
	
	echo $this->EndTab();
	

	echo $this->StartTab('summarytemplate', $params);
	
	echo $this->CreateFormStart($id, 'updatesummarytemplate');
	
	echo '<p>'.$this->CreateTextArea(false, $id, $this->GetTemplate('displaysummary'), 'templatecontent', 'pagebigtextarea').'</p>';
	
	echo $this->CreateInputSubmit($id, 'submitbutton', $this->Lang('submit'));
	echo $this->CreateInputSubmit($id, 'defaultsbutton', $this->Lang('sysdefaults'), '', '', $this->Lang('restoretodefaultsmsg'));
	
	echo $this->CreateFormEnd();
	
	echo $this->EndTab();

	
	echo $this->StartTab('detailtemplate', $params);
	
	echo $this->CreateFormStart($id, 'updatedetailtemplate');
	
	echo '<p>'.$this->CreateTextArea(false, $id, $this->GetTemplate('displaydetail'), 'templatecontent2', 'pagebigtextarea').'</p>';
	
	echo $this->CreateInputSubmit($id, 'rsssubmitbutton', $this->Lang('submit'));
	echo $this->CreateInputSubmit($id, 'defaultsbutton', $this->Lang('sysdefaults'), '', '', $this->Lang('restoretodefaultsmsg'));
	
	echo $this->CreateFormEnd();
	
	echo $this->EndTab();
}

echo $this->EndTabContent();


$this->smarty->assign('tab_headers',$this->StartTabHeaders().
	$this->SetTabHeader('videocollection',$this->Lang('title_videocollection')).
	$this->SetTabHeader('summarytemplate',$this->Lang('title_summarytemplate')).
	$this->SetTabHeader('detailtemplate',$this->Lang('title_detailtemplate')).
	$this->EndTabHeaders().$this->StartTabContent());

$this->smarty->assign('end_tab',$this->EndTab());

$this->smarty->assign('start_videocollection_tab',$this->StartTab('videocollection'));
$this->smarty->assign('start_summarytemplate_tab',$this->StartTab('summarytemplate'));
$this->smarty->assign('start_detailtemplate_tab',$this->StartTab('detailtemplate'));

echo $this->ProcessTemplate('adminpanel.tpl');

?>
Thanks for any help.

Nullig

Re: Smarty Help

Posted: Wed Apr 25, 2007 4:51 am
by cyberman
Have you made a look at SmartyPaginate?

http://www.phpinsider.com/php/code/SmartyPaginate/

Re: Smarty Help

Posted: Wed Apr 25, 2007 3:08 pm
by calguy1000
a) Normally, I create the tab headers first, then the tab contents.
usually, if the tab contents show up before the tabs, it means that something isn't closed correctly.

b) The FLVPlayer module does exactly what you want, you may want to check it out (warning, it requires CGExtensions to be installed first).  It has examples of back end pagination, tabs with permissions, and...  of how to split stuff out to separate files for increased performance.

Re: Smarty Help

Posted: Wed Apr 25, 2007 3:15 pm
by Nullig
Thanks for the link, cyberman,  but I don't see SmartyPaginate.class.php included with CMSMS.

Nullig

Re: Smarty Help

Posted: Wed Apr 25, 2007 3:16 pm
by Nullig
Thanks, calguy. I'll have a look at it.

Nullig

Re: Smarty Help

Posted: Wed Apr 25, 2007 9:28 pm
by cyberman
Nullig wrote: but I don't see SmartyPaginate.class.php included with CMSMS.
SmartyPaginate is a Smarty plugin so you can / should use it like you want. You can use it with or without CMSms - why do you want to reinvent the wheel?

IMHO you are thinking to short if you only wanna use parts they comes with CMSms ...