All pastes #800739 Raw Edit

Something

public text v1 · immutable
#800739 ·published 2007-11-28 18:35 UTC
rendered paste body
<?php
#-------------------------------------------------------------------------
# Module: RestaurantMenu 
# Version: 0.1, TAH
# Method: menu admin
#-------------------------------------------------------------------------

if (!isset($gCms)) exit;

if (! $this->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}

<div style="float: left;width: 20%;">
    <p class="pageoptions">{$addlink}</p>
</div>

<div style="float: right;width: 18%;">
    {$save}
</div>
{if $itemcount > 0}

<table cellspacing="0" class="pagetable" style="clear: both;">
    <thead>
        <tr>
	    <th>Item</th>
	    <th>Description</th>
            <th></th>
            <th> </th>
            {* foreach location, add a th*}
            {foreach name=location from=$locations item=loc}
            <th class="pageicon" style="border-left: 1px solid #000;">{$loc->name|substr:0:3}</th>
            {/foreach}
	    <th class="pageicon"></th>
            <th class="pageicon"></th>
                
        </tr>
    </thead>
    <tbody>
    {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}
        <tr class="{$rowclass}" onmouseover="this.className='{$rowclass}hover';" onmouseout="this.className='{$rowclass}';">
            <td>{$i.item_name} </td>
            <td>{$i.description} </td>
            <td>{*$i.price*}</td>
            <td></td>
            {* foreach location, add a td w/ check box *}
            {foreach name=location from=$i.checkboxes item=loc }
            <td  style="border-left: 1px solid #e3e3e3;">{$loc}</td>
            {/foreach}
            {* checked if it is at that location *}
            <td>{$i.editlink}</td>
            <td>{$i.deletelink}{$i.hidden}</td>
        </tr>
        
    {/foreach}
    
    {/if}            

   </tbody>
</table>

{/if}

<div style="float: left;width: 20%;">
    <p class="pageoptions">{$addlink}</p>
</div>

<div style="float: right;width: 18%;">
    {$save}
</div>

<br style="clear: both;"/>
{$target}
{$endform}