CheckPermission('Use RestaurantMenu')) { return $this->DisplayErrorPage($id, $params, $returnid,$this->Lang('accessdenied')); } $this->DisplayAdminNav($id, $params, $returnid); $db =& $gCms->GetDb(); # get location list $sql = "SELECT id, city, state,zip, phone, fax, location_name FROM cms_module_restaurant_menu_locations"; $dbresult = $db->Execute( $sql ); $locations = array(); while($dbresult && $row = $dbresult->FetchRow()){ $each = new stdClass(); $each->id = $row['id']; $each->name = $row['location_name']; $each->city = $row['city']; $each->state = $row['state']; $each->zip = $row['zip']; $each->phone = $row['phone']; $each->fax = $row['fax']; $locations[] = $each; } $this->smarty->assign('locations',$locations); # get Categories $sql = "SELECT id, cat_text, target FROM cms_module_restaurant_menu_categories"; $dbresult = $db->Execute( $sql ); //if($db->ErrorMsg()){echo $db->ErrorMsg();} //TODO: handle empty result or error $entryarray = array(); $cats = array(); echo $this->StartTabHeaders(); if (FALSE == empty($params['active_tab'])) { $tab = $params['active_tab']; } else { $tab = ''; } while($dbresult && $row = $dbresult->FetchRow()){ $menu[$row['id']]['id'] = $row['id']; $menu[$row['id']]['text'] = $row['cat_text']; $menu[$row['id']]['target'] = $row['target']; $menu[$row['id']]['items'] = array(); echo $this->SetTabHeader($row['target'], $row['cat_text'], ($row['target'] == $tab)); } echo $this->EndTabHeaders(); # get items per category $sql= "SELECT item_fk, location_fk FROM cms_module_restaurant_menu_assoc_item_to_location WHERE status=1"; $dbresult = $db->Execute( $sql ); $assoc = array(); while($row = $dbresult->FetchRow()){ $assoc[$row['item_fk']][] = $row['location_fk']; } $sql= "SELECT items.id, item_name, description, price, cat_fk FROM cms_module_restaurant_menu_item AS items, cms_module_restaurant_menu_categories AS cats WHERE items.cat_fk = cats.id"; $dbresult = $db->Execute( $sql ); //TODO: handle empty result or error while($row = $dbresult->FetchRow()){ $editlink = $this->CreateLink($id, 'edititem', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', 'Edit Item Details','','','systemicon'), array('item_id'=>$row['id'], 'target' => $menu[$row['cat_fk']]['target'])); $deletelink = $this->CreateLink($id, 'deleteitem', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', 'Delete Menu Item','','','systemicon'), array('item_id'=>$row['id'], 'target' => $menu[$row['cat_fk']]['target']), "Are you sure you want to delete this item?"); $menu[$row['cat_fk']]['items'][$row['id']] = array('id'=> $row['id'], 'item_name' => $row['item_name'], 'description' => $row['description'], 'price' => $row['price'], 'editlink' => $editlink, 'deletelink' => $deletelink); $menu[$row['cat_fk']]['items'][$row['id']]['checkboxes'] = ''; $menu[$row['cat_fk']]['items'][$row['id']]['locations'] = array(); $menu[$row['cat_fk']]['items'][$row['id']]['hidden'] = $this->CreateInputHidden( $id, 'items[]', $row['id']); if( isset( $assoc[$row['id']] ) ){ $menu[$row['cat_fk']]['items'][$row['id']]['locations'] = $assoc[$row['id']]; } foreach($locations as $loc){ $extra = ''; if(in_array($loc->id, $menu[$row['cat_fk']]['items'][$row['id']]['locations'])){ $extra = 'checked="checked"'; } $menu[$row['cat_fk']]['items'][$row['id']]['checkboxes'][] = $this->CreateInputCheckBox($id, $row['id'].'-loc[]',$loc->id,'', $extra ); } } # Create form elements $this->smarty->assign('save', $this->CreateInputSubmit($id, 'submit', 'Save Changes')); # Create tabs echo $this->StartTabContent(); foreach($menu as $cat){ echo $this->StartTab($cat['target'], $params); $this->smarty->assign('startform', $this->CreateFormStart($id, 'updateassoc', $returnid, 'post', 'multipart/form-data')); $this->smarty->assign('addlink', $this->CreateLink($id, 'additem', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/newfolder.gif', $this->Lang('addcategory'),'','','systemicon'), array(), '', false, false, '') .' '. $this->CreateLink($id, 'additem', $returnid, 'Add an item', array('cat' => $cat['id'], 'target' => $cat['target']), '', false, false, 'class="pageoptions"')); $this->smarty->assign('menu', $cat); $this->smarty->assign('itemcount', count($cat)); $this->smarty->assign('target', $this->CreateInputHidden( $id, 'target', $cat['target']) ); $this->smarty->assign('endform', $this->CreateFormEnd()); echo $this->ProcessTemplate('catItems.tpl'); echo $this->EndTab(); } echo $this->EndTabContent(); # display ?> # catItems.tpl #--------------------- {$startform}

{$addlink}

{$save}
{if $itemcount > 0} {* foreach location, add a th*} {foreach name=location from=$locations item=loc} {/foreach} {if $menu.items|@count > 0} {foreach name=first from=$menu.items item=i } {if $smarty.foreach.first.iteration is odd} {assign var="rowclass" value="row1"} {else} {assign var="rowclass" value="row2"} {/if} {* foreach location, add a td w/ check box *} {foreach name=location from=$i.checkboxes item=loc } {/foreach} {* checked if it is at that location *} {/foreach} {/if}
Item Description {$loc->name|substr:0:3}
{$i.item_name} {$i.description} {*$i.price*} {$loc}{$i.editlink} {$i.deletelink}{$i.hidden}
{/if}

{$addlink}

{$save}

{$target} {$endform}