91
phillipd
Where is the 'next' or 'continue' in smarty?
  • 2004/11/4 8:29

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Looking on the smarty FAQ page under item 23:

23. Where is the 'next' or 'continue' in Smarty's loops, to skip to the next iteration?

There is no answer for this question. Anyone have a clue how to skip to next iteration if desired?

Thanks

Doug P



92
phillipd
Re:Dual or tri column output
  • 2004/11/4 6:30

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


That actually doesn't work. It puts the gadgets like this:


gadget1
-------gadget2
gadget3
-------gadget4
gadget5
-------gadget6

I'm fooling around with it to see if I can work it out...

Thanks

Doug P



93
phillipd
Re:Dual or tri column output
  • 2004/11/4 2:18

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Thanks for the tip! I have a rudimentary understanding of Smarty and templates but I need more experience...

Doug P



94
phillipd
Smarty templates in an "admin" script are working!
  • 2004/11/4 2:00

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I finally got Smarty and templates working in an admin script. Here is some sample code, it's sure alot easier to write with smarty!

<?php
include '../../../mainfile.php';
include '../../../include/cp_header.php';

$op = "form";

if ( isset($HTTP_POST_VARS['op']) && $HTTP_POST_VARS['op'] == "submit" ) {
$op = "submit";
}

if ( $op == "form" ) {
xoops_cp_header();
require_once SMARTY_DIR.'Smarty.class.php';
$xoopsTpl = new Smarty;
$xoopsOption['template_main'] = 'ecngis_admin.html';
include XOOPS_ROOT_PATH."/header.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";

//
// Just a sample checkbox
//
$tray_locale = new XoopsFormElementTray("");
$locale = new XoopsFormCheckBox("","Locale","0");
$locale->addOption("0","Locale");
$tray_locale->AddElement($locale);
$form = new XoopsThemeForm("", "layerform", "setlayers.php");
$form->addElement($tray_locale);
$form->assign($xoopsTpl);
$xoopsTpl->assign('lang_layers', _MM_LAYERS);

$xoopsTpl->display('db:'.$xoopsOption['template_main']);
xoops_cp_footer();
}

if ( $op == "submit" ) {

Normal coding stuff...

}
?>



95
phillipd
Dual or tri column output
  • 2004/11/3 23:23

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I've got a bunch of checkboxes I would like to layout in a two or three column form. I am trying a:

<{foreach item=element from=$layerform.elements}>
<tr>
<td class="<{cycle values="even,odd"}>"><{$element.body}></td>
</tr>

<{/foreach}>

type of affair, but would like to layout in more than a single column. How is this done??? How can I do something like:

<{foreach item=element from=$layerform.elements}>
<tr>
<td class="<{cycle values="even,odd"}>"><{$element.body}></td>
<{next}>
<td class="<{cycle values="even,odd"}>"><{$element.body}></td>
</tr>
<{/foreach}>

So I can get "every other" element to layout in a second or third column? (I know there is no "next" )

Thanks

Doug P



96
phillipd
Re: How do you remove the "Preferences" menu in admin.
  • 2004/10/31 22:05

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Ahh, I see. I had a:

$modversion['hasComments'] = 1;

In xoops_version.php

I removed that and the preferences option went away.

Thanks for the lead...

Still waiting for a piece of sample admin code with smarty tags...

I went ahead and wrote the admin module in php/html. I'll post it here for others to see and learn from. Try not to laugh... It is a GIS app that forms a URL to a ESRI/Oracle map service. The result is the requested map comes up in a browser with the requested bounding box and attributes. Kind of like mapquest with more data behind the map. This is just the admin code (index.php) to set reasonable defaults. The rest of the app is at the bottom. I hope it's acceptable to post code here. Sample code is what I learn from so I hope someone can learn from mine. XOOPS is cool!

/////////////////////////////////////////////////////////
//
// admin/index.php
//
/////////////////////////////////////////////////////////
<?php
include '../../../include/cp_header.php';
if ( file_exists("../language/".$xoopsConfig['language']."/main.php") ) {
include "../language/".$xoopsConfig['language']."/main.php";
} else {
include "../language/english/main.php";
}
$op = "listdefaults";

if (isset($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $k => $v) {
$$k = $v;
}
}

if (isset($HTTP_POST_VARS)) {
foreach ($HTTP_POST_VARS as $k => $v) {
$$k = $v;
}
}

if ($op == "listdefaults") {
xoops_cp_header();
///////////////////////////////////////////////////////////////////////////////
///
/// Displays and sets GIS extents for city, zip and lon/lat views
///
///////////////////////////////////////////////////////////////////////////////
$opts = 'SELECT * FROM '.$xoopsDB->prefix('gis_options').'';
$result = $xoopsDB->query($opts);
list($dum,$dum,$mapservice,$cityext,$zipext,$lonlatext) = $xoopsDB->fetchRow($result);
echo "
<h3 style='text-align:center;'>"._MM_CURRENT."</h3>
<h4 style='text-align:left;'>"._MM_EXTENT_HELP."</h4>
<form action='index.php' method='post'>
<table border='0' cellpadding='0' cellspacing='0' width='90%'>
<tr>
<td class='bg2'>
<table width='100%' border='5' cellpadding='4' cellspacing='1'>

<tr nowrap='nowrap'>
<td class='bg3' width='200'>"._MM_CITY_EXT." </td>
<td class='bg1'width='400'><input type='text' value='$cityext' name='cityext' size='15' maxlength='255' /></td>
</tr>
<tr nowrap='nowrap'>
<td class='bg3' width='200'>"._MM_ZIP_EXT." </td>
<td class='bg1'width='400'><input type='text'value='$zipext' name='zipext' size='15' maxlength='255' /></td>
</tr>
<tr nowrap='nowrap'>
<td class='bg3' width='200'>"._MM_LONLAT_EXT." </td>
<td class='bg1'width='400'><input type='text' value='$lonlatext' name='lonlatext' size='15' maxlength='255' /></td>
</tr>
<tr nowrap='nowrap'>
<td class='bg3' width='200'>"._MM_MAP_SERVICE." </td>
<td class='bg1'width='400'><input type='text' value='$mapservice' name='mapservice' size='55' maxlength='255' /></td>
</tr>
<tr>
<td class='bg3'>&nbsp;</td>
<td class='bg1'>
<input type='hidden' name='op' value='setextents' />
<input type='submit' value='"._MM_SETDEFAULTS."' /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>";

xoops_cp_footer();
exit();
}

if ($op == "setextents") {
$myts =& MyTextSanitizer::getInstance();
//
// Grab the numbers from the text gadgets above
//
$cityext = $HTTP_POST_VARS['cityext'];
$zipext = $HTTP_POST_VARS['zipext'];
$lonlatext = $HTTP_POST_VARS['lonlatext'];
//$mapservice = $HTTP_POST_VARS['mapservice'];
$mapservice = $myts->oopsAddSlashes(trim($HTTP_POST_VARS['mapservice']));
//
// Create a update query with the new values
//
$sql = "UPDATE ".$xoopsDB->prefix("gis_options")." set
opt_service='".$mapservice."',
opt_cityextent=".$cityext.",
opt_zipextent=".$zipext.",
opt_lonlatextent=".$lonlatext." WHERE opt_id=1";
//
// Update the gis_options table
//
if (!$xoopsDB->query($sql)) {
xoops_cp_header();
echo "Could not update GIS defaults, tell your System Administrator!";
xoops_cp_footer();
} else {
redirect_header("index.php?op=listdefaults",5,_MM_OPTSUCCESS);
}
}

?>
-----------------------------------------------------

And my mysql.sql file:

CREATE TABLE gis_zip (
zip_id int(15) unsigned NOT NULL auto_increment,
zip_zip varchar(255) NOT NULL default '',
zip_x float NOT NULL default '0.0',
zip_y float NOT NULL default '0.0',
PRIMARY KEY (zip_id)
) TYPE=MyISAM;

CREATE TABLE gis_city (
city_id int(15) unsigned NOT NULL auto_increment,
city_name varchar(255) NOT NULL default '',
city_state varchar(255) NOT NULL default '',
city_x float NOT NULL default '0.0',
city_y float NOT NULL default '0.0',
PRIMARY KEY (city_id)
) TYPE=MyISAM;

CREATE TABLE gis_sites (
site_id int(15) unsigned NOT NULL auto_increment,
site_name varchar(255) NOT NULL default '',
x1 float NOT NULL default '0.0',
y1 float NOT NULL default '0.0',
xx float NOT NULL default '0.0',
y2 float NOT NULL default '0.0',
PRIMARY KEY (site_id)
) TYPE=MyISAM;

#
# Fake data for testing
#
INSERT INTO gis_sites VALUES (1,"Knoxville",-77.43,41.95,-77.33,42.05);
INSERT INTO gis_sites VALUES (2,"Wilcox",-77.43,41.95,-77.33,42.05);
INSERT INTO gis_sites VALUES (3,"Roxbury",-77.43,41.95,-77.33,42.05);
INSERT INTO gis_sites VALUES (4,"West Boxford",-77.43,41.95,-77.33,42.05);

CREATE TABLE gis_options (
opt_id int(15) unsigned NOT NULL auto_increment,
opt_layers varchar(255) NOT NULL default '00000001100000110110010001',
opt_service varchar(255) NOT NULL default 'http://hqapp.oem.doe.gov/website/
us_detail_html',
opt_cityextent float NOT NULL default '0.15',
opt_zipextent float NOT NULL default '0.02',
opt_lonlatextent float NOT NULL default '0.05',
PRIMARY KEY (opt_id)
) TYPE=MyISAM;

INSERT INTO gis_options VALUES (1,"00000001100000110110010001","http://hqapp.oem
.doe.gov/website/us_detail_html",0.15,0.02,0.05);

CREATE TABLE gis_layers (
layer_id int(15) unsigned NOT NULL auto_increment,
layer_name varchar(255) NOT NULL default '',
PRIMARY KEY (layer_id)
) TYPE=MyISAM;
INSERT INTO gis_layers VALUES (1,"Locale");
INSERT INTO gis_layers VALUES (2,"Buildings");
INSERT INTO gis_layers VALUES (3,"");
INSERT INTO gis_layers VALUES (4,"");
INSERT INTO gis_layers VALUES (5,"Physicians");
INSERT INTO gis_layers VALUES (6,"Hospitals");
INSERT INTO gis_layers VALUES (7,"Recreation Areas");
INSERT INTO gis_layers VALUES (8,"Highways");
INSERT INTO gis_layers VALUES (9,"Streets");
INSERT INTO gis_layers VALUES (10,"");
INSERT INTO gis_layers VALUES (11,"Railroads");
INSERT INTO gis_layers VALUES (12,"");
INSERT INTO gis_layers VALUES (13,"DOE Site Buildings");
INSERT INTO gis_layers VALUES (14,"DOE Areas");
INSERT INTO gis_layers VALUES (15,"Zip Code Areas");
INSERT INTO gis_layers VALUES (16,"Counties");
INSERT INTO gis_layers VALUES (17,"Major Water");
INSERT INTO gis_layers VALUES (18,"Water Areas");
INSERT INTO gis_layers VALUES (19,"DOE Sites");
INSERT INTO gis_layers VALUES (20,"");
INSERT INTO gis_layers VALUES (21,"");
INSERT INTO gis_layers VALUES (22,"Airports");
INSERT INTO gis_layers VALUES (23,"Federal Land Areas");
INSERT INTO gis_layers VALUES (24,"Places");
INSERT INTO gis_layers VALUES (25,"Locale");
INSERT INTO gis_layers VALUES (26,"States");

OK here is the rest of the app: (index.php)

/////////////////////////////////////////////////////////
//
// index.php
//
/////////////////////////////////////////////////////////

include "../../mainfile.php";

$op = "form";
if ( isset($HTTP_POST_VARS['op']) && $HTTP_POST_VARS['op'] == "submit" ) {
$op = "submit";
}

if ( $op == "form" ) {
$xoopsOption['template_main'] = 'ecngis_searchform.html';
include XOOPS_ROOT_PATH."/header.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";

$sites_select = new XoopsFormSelect("","sites");
$sites_tray = new XoopsFormElementTray(_MM_SITE, "&nbsp;");
$sites_tray->addElement($sites_select);
$sites_select->addOption("","");
//
// Grab bounding box from DB
//
$sql = 'SELECT site_name FROM '.$xoopsDB->prefix('gis_sites').'';
$result = $xoopsDB->query($sql);

while(list($site) = $xoopsDB->fetchRow($result)) {
$sites_select->addOption($site,$site);
}

$city_text = new XoopsFormText("", "city", 20, 60);
$city_tray = new XoopsFormElementTray(_MM_CITY, "&nbsp;");
$city_tray->addElement($city_text);
$state_text = new XoopsFormText("", "state", 20, 60);
$state_tray = new XoopsFormElementTray(_MM_STATE, "&nbsp;");
$state_tray->addElement($state_text);
//$county_text = new XoopsFormText("", "county", 20, 60);
//$county_tray = new XoopsFormElementTray(_MM_COUNTY, "&nbsp;");
//$county_tray->addElement($county_text);
$zip_text = new XoopsFormText("", "zip", 20, 10);
$zip_tray = new XoopsFormElementTray(_MM_ZIP, "&nbsp;");
$zip_tray->addElement($zip_text);
$lon_text = new XoopsFormText("", "lon", 20, 60);
$lon_tray = new XoopsFormElementTray(_MM_LON, "&nbsp;");
$lon_tray->addElement($lon_text);
$lat_text = new XoopsFormText("", "lat", 20, 60);
$lat_tray = new XoopsFormElementTray(_MM_LAT, "&nbsp;");
$lat_tray->addElement($lat_text);
$op_hidden = new XoopsFormHidden("op", "submit");
$submit_button = new XoopsFormButton("", "", "Search", "submit");

//
// "searchform" is referenced in template
//
$form = new XoopsThemeForm("", "searchform", "index.php");
$form->addElement($sites_tray);
$form->addElement($city_tray);
$form->addElement($state_tray);
$form->addElement($zip_tray);
$form->addElement($lon_tray);
$form->addElement($lat_tray);
$form->addElement($op_hidden);
$form->addElement($submit_button);
$form->assign($xoopsTpl);
$xoopsTpl->assign('lang_search', _MM_SEARCH);
$xoopsTpl->assign('lang_instructions', _MM_INSTRUCTIONS);
//$site_select->setExtra("");
//$site_select->setExtra("onchange='doSite()'");
}

if ( $op == "submit" ) {
$xoopsOption['template_main'] = 'ecngis_searchresults.html';
include XOOPS_ROOT_PATH."/header.php";
$myts =& MyTextSanitizer::getInstance();
$city = $HTTP_POST_VARS['city'];
$state = $HTTP_POST_VARS['state'];
$zip = $HTTP_POST_VARS['zip'];
$lon = $HTTP_POST_VARS['lon'];
$lat = $HTTP_POST_VARS['lat'];
$site = $HTTP_POST_VARS['sites'];

$xoopsTpl->assign('lang_search', _MM_SEARCH);
$xoopsTpl->assign('lang_results', _MM_RESULTS);
$xoopsTpl->assign('lang_city', _MM_CITY);
$xoopsTpl->assign('lang_state', _MM_STATE);
$xoopsTpl->assign('lang_site', _MM_SITE);
$xoopsTpl->assign('lang_zip', _MM_ZIP);
$xoopsTpl->assign('lang_lon', _MM_LON);
$xoopsTpl->assign('lang_lat', _MM_LAT);
$xoopsTpl->assign('lang_link', _MM_LINK);

if ( !empty($HTTP_POST_VARS['sites']) ) {

$opts = 'SELECT opt_service FROM '.$xoopsDB->prefix('gis_options').'';
$optsresult = $xoopsDB->query($opts);
list($service) = $xoopsDB->fetchRow($optsresult);

$site1 = rawurlencode($site);
$row = array();
$row['site'] = $site;
$row['url'] = "$service?ActiveLayer=19&Query=NAME%3D$site1$QueryZoom=Yes";
$xoopsTpl->append('row',$row);
$xoopsTpl->assign('type', "site");
$city = $state = $zip = "";
}

if(strlen($city) > 0 || strlen($state) > 0) {
$xoopsTpl->assign('type', "city");
//
// Generate a query based on what gadgets are filled in
//
if(strlen($city) > 0 && strlen($state) > 0) {
$sql = 'SELECT * FROM '.$xoopsDB->prefix('gis_city').'
WHERE city_name LIKE "%'.$city.'%"
AND city_state LIKE "%'.$state.'%" ORDER BY city_name';
}
if(strlen($city) > 0 && strlen($state) == 0) {
$sql = 'SELECT * FROM '.$xoopsDB->prefix('gis_city').'
WHERE city_name LIKE "%'.$city.'%" ORDER BY city_name';
}
if(strlen($city) == 0 && strlen($state) > 0) {
$sql = 'SELECT * FROM '.$xoopsDB->prefix('gis_city').'
WHERE city_state LIKE "%'.$state.'%" ORDER BY city_name';
}
$result = $xoopsDB->query($sql);
//
// Grab bounding box from DB
//
$opts = 'SELECT opt_layers,opt_service,opt_cityextent FROM '.$xoopsDB->prefix('gis_options').'';
$optsresult = $xoopsDB->query($opts);
list($layers,$service,$extent) = $xoopsDB->fetchRow($optsresult);

//
// Now build url for GIS viewer
//
$row = array();
$count = 0;
while (list($dbid,$dbcity, $dbstate, $dblon, $dblat) = $xoopsDB->fetchRow($result)) {
//echo"$dbcity, $dbstate, $dblon, $dblat <br></br>";
$x1 = $dblon - $extent;
$y1 = $dblat - $extent;
$x2 = $dblon + $extent;
$y2 = $dblat + $extent;
$row['url'] = "$service/viewer.htm?box=$x1:$y1:$x2:$y2?layers=$layers";
$row['city'] = $dbcity;
$row['state'] = $dbstate;
$row['lon'] = $dblon;
$row['lat'] = $dblat;
$xoopsTpl->append('row',$row);
$count++;
}
$xoopsTpl->assign('count',$count);
}
if(strlen($zip) > 0) {
$xoopsTpl->assign('type', "zip");
$sql = 'SELECT * FROM '.$xoopsDB->prefix('gis_zip').'
WHERE zip_zip LIKE "%'.$zip.'%" ORDER BY zip_zip';
//echo "$sql <br>";
$result = $xoopsDB->query($sql);
//
// Grab bounding box from DB
//
$opts = 'SELECT opt_layers,opt_service,opt_zipextent FROM '.$xoopsDB->prefix('gis_options').'';
$optsresult = $xoopsDB->query($opts);
list($layers,$service,$extent) = $xoopsDB->fetchRow($optsresult);
$row = array();

$count = 0;
while (list($dbid,$dbzip, $dblon, $dblat) = $xoopsDB->fetchRow($result)) {
//echo"$dbcity, $dbstate, $dblon, $dblat <br></br>";
$x1 = $dblon - $extent;
$y1 = $dblat - $extent;
$x2 = $dblon + $extent;
$y2 = $dblat + $extent;
$row['url'] = "$service/viewer.htm?box=$x1:$y1:$x2:$y2?layers=$layers";
$row['city'] = "";
$row['state'] = "";
$row['zip'] = $dbzip;
$row['lon'] = $dblon;
$row['lat'] = $dblat;
$xoopsTpl->append('row',$row);
$count++;
}
$xoopsTpl->assign('count',$count);
}

if(strlen($lon) > 0) {
$xoopsTpl->assign('type', "lon");
//
// Grab bounding box from DB
//
$opts = 'SELECT opt_layers,opt_service,opt_lonlatextent FROM '.$xoopsDB->prefix('gis_options').'';
$optsresult = $xoopsDB->query($opts);
list($layers,$service,$extent) = $xoopsDB->fetchRow($optsresult);
$row = array();

$count = 0;
//echo"$dbcity, $dbstate, $dblon, $dblat <br></br>";
$x1 = $lon - $extent;
$y1 = $lat - $extent;
$x2 = $lon + $extent;
$y2 = $lat + $extent;
$row['url'] = "$service/viewer.htm?box=$x1:$y1:$x2:$y2?layers=$layers";
$row['city'] = "";
$row['state'] = "";
$row['zip'] = "";
$row['lon'] = $lon;
$row['lat'] = $lat;
$xoopsTpl->append('row',$row);
$xoopsTpl->assign('count',$count);
}
}

include_once XOOPS_ROOT_PATH."/footer.php";
?>



97
phillipd
How do you remove the "Preferences" menu in admin.
  • 2004/10/31 19:22

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


After creating an "Admin" script for my module I note there is always a "Preferences" menu item when I "mouse over" the module icon. How do I remove this? I only have one menuitem in my menu.php. Where does the other item come from?

Thanks

Doug P



98
phillipd
Re:Why isn't smarty used in admin scripts
  • 2004/10/31 17:23

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Thanks for your answer! Have you got a sample admin module I can see to get started? Starting from agenda-x is jast about like starting from scratch.

Thanks!!

Doug P



99
phillipd
Re:Why isn't smarty used in admin scripts
  • 2004/10/31 5:04

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I'm a beginner at developing XOOPS modules. I've heavily modified the xoopsfaq module to make it do what I needed and have created another GIS module to display maps from a ESRI system from scratch. I was about to write my first admin module for this GIS project when I discovered this lack of smarty usage in admin scripts.

If I could impose on one of you hard working XOOPS masters...

1) Why is it anymore awkward than just writing a module? What am I missing here?

2) What "support" was required that wasn't there previously.

3) Are there any restrictions I should know about?

4) Do you know of any other modules with admin scripts, that use smarty as the prevalent way to generate admin forms, I can use for educating myself?

Gratefully

Doug P



100
phillipd
Why isn't smarty used in admin scripts
  • 2004/10/31 4:14

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I just checked all the modules that come with XOOPS and shockingly discovered that none use smarty in their admin scripts. Why is this? One exception to this is agendax (I know it doesn't come with xoops), and it uses very little in the way of smarty and templates in its admin code.

Puzzled

Doug P




TopTop
« 1 ... 7 8 9 (10) 11 12 13 ... 22 »



Login

Who's Online

109 user(s) are online (60 user(s) are browsing Support Forums)


Members: 0


Guests: 109


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits