<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
  <?php foreach ($breadcrumbs as $breadcrumb) { ?>
  <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
  <?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<div class="box">
  <div class="heading">
    <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
    <div class="buttons"><a onclick="$('#form').submit();" class="button"><span><?php echo $button_save; ?></span></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><span><?php echo $button_cancel; ?></span></a></div>
  </div>
  <div class="content">
    <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
      <table id="module" class="list">
        <thead>
          <tr>
            <td class="left"><span class="required">*</span><?php echo $entry_title; ?></td>
            <td class="left"><span class="required">*</span><?php echo $entry_category; ?></td>
			<td class="left"><span class="required">*</span><?php echo $entry_settings; ?></td>
            <td></td>
          </tr>
        </thead>
        <?php $module_row = 0; ?>
        <?php foreach ($modules as $module) { ?>
        <tbody id="module-row<?php echo $module_row; ?>">
          <tr>
          	<td class="left" style="vertical-align:top; min-width:180px;">
                <?php foreach ($languages as $language) { ?>
                <img src="view/image/flags/<?php echo $language['image']; ?>" alt="<?php echo $language['name']; ?>" />
                <input type="text" name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][language_id][<?php echo $language['language_id']; ?>]" value="<?php if (!empty($module['language_id'][$language['language_id']])) { echo $module['language_id'][$language['language_id']];} ?>">
                <br />
                <?php } ?>
                <span class="error"><?php echo $error_title; ?></span>
            </td>
            <td class="left" style="vertical-align:top; width:280px; min-width:280px;">
			  <div class="scrollbox" style="height:300px;">
                <?php $class = 'odd'; ?>
                <?php foreach ($categories as $category) { ?>
                <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                <div class="<?php echo $class; ?>">
                  <?php if (isset($module['category_id']) && (in_array($category['category_id'], $module['category_id']))) { ?>
                  <input type="checkbox" name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][category_id][]" value="<?php echo $category['category_id']; ?>" checked="checked" />
                  <?php echo $category['name']; ?>
                  <?php } else { ?>
                  <input type="checkbox" name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][category_id][]" value="<?php echo $category['category_id']; ?>" />
                  <?php echo $category['name']; ?>
                  <?php } ?>
                </div>
                <?php } ?>
              </div>
			  <span class="error"><?php echo $error_category; ?></span>
              </td>
            <td class="left">
			  <table class="list">
			    <tr>
			      <td class="left"><?php echo $entry_status; ?></td>
			      <td class="left">
				    <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][status]">
	                  <?php if ($module['status']) { ?>
	                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
	                  <option value="0"><?php echo $text_disabled; ?></option>
	                  <?php } else { ?>
	                  <option value="1"><?php echo $text_enabled; ?></option>
	                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
	                  <?php } ?>
	                </select>
			      </td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_position; ?></td>
			      <td class="left">
				    <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][position]">
                	  <?php if ($module['position'] == 'content_top') { ?>
                	  <option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
	                  <?php } else { ?>
	                  <option value="content_top"><?php echo $text_content_top; ?></option>
	                  <?php } ?>
	                  <?php if ($module['position'] == 'content_bottom') { ?>
	                  <option value="content_bottom" selected="selected"><?php echo $text_content_bottom; ?></option>
	                  <?php } else { ?>
	                  <option value="content_bottom"><?php echo $text_content_bottom; ?></option>
	                  <?php } ?>
	                  <?php if ($module['position'] == 'column_left') { ?>
	                  <option value="column_left" selected="selected"><?php echo $text_column_left; ?></option>
	                  <?php } else { ?>
	                  <option value="column_left"><?php echo $text_column_left; ?></option>
	                  <?php } ?>
	                  <?php if ($module['position'] == 'column_right') { ?>
	                  <option value="column_right" selected="selected"><?php echo $text_column_right; ?></option>
	                  <?php } else { ?>
	                  <option value="column_right"><?php echo $text_column_right; ?></option>
	                  <?php } ?>
              		</select>
			      </td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_layout; ?></td>
			      <td class="left">
				    <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][layout_id]">
                	  <?php foreach ($layouts as $layout) { ?>
                	  <?php if ($layout['layout_id'] == $module['layout_id']) { ?>
                	  <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                	  <?php } else { ?>
                	  <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                	  <?php } ?>
                	  <?php } ?>
              		</select>
			      </td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_count; ?></td>
			      <td class="left">
				    <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][count]">
	                  <?php if ($module['count']) { ?>
	                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
	                  <option value="0"><?php echo $text_no; ?></option>
	                  <?php } else { ?>
	                  <option value="1"><?php echo $text_yes; ?></option>
	                  <option value="0" selected="selected"><?php echo $text_no; ?></option>
	                  <?php } ?>
	                </select>
			      </td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_expand; ?></td>
			      <td class="left">
				    <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][expand]">
	                  <?php if ($module['expand']) { ?>
	                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
	                  <option value="0"><?php echo $text_no; ?></option>
	                  <?php } else { ?>
	                  <option value="1"><?php echo $text_yes; ?></option>
	                  <option value="0" selected="selected"><?php echo $text_no; ?></option>
	                  <?php } ?>
	                </select>
			      </td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_style; ?></td>
			      <td class="left">
				    <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][style]">
	                  <option value="list" <?php if (isset($module['style']) && $module['style'] == 'list') { echo 'selected="selected"'; } ?>><?php echo $text_list; ?></option>
                  	  <option value="select" <?php if (isset($module['style']) && $module['style'] == 'select') { echo 'selected="selected"'; } ?>><?php echo $text_select; ?></option>
                  	  <option value="graphic" <?php if (isset($module['style']) && $module['style'] == 'graphic') { echo 'selected="selected"'; } ?>><?php echo $text_graphic; ?></option>
	                </select>
			      </td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_css_class; ?></td>
			      <td class="left"><input type="text" name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][css_class]" value="<?php echo $module['css_class']; ?>" /></td>
			    </tr>
			    <tr>
			      <td class="left"><?php echo $entry_sort_order; ?></td>
			      <td class="left"><input type="text" name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][sort_order]" value="<?php echo $module['sort_order']; ?>" size="3" /></td>
			    </tr>
			  </table>
			</td>
            <td class="left"><a onclick="$('#module-row<?php echo $module_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>
          </tr>
        </tbody>
        <?php $module_row++; ?>
        <?php } ?>
        <tfoot>
          <tr>
            <td colspan="3"></td>
            <td class="left"><a onclick="addModule();" class="button"><span><?php echo $button_add_module; ?></span></a></td>
          </tr>
        </tfoot>
      </table>
    </form>
  </div>
</div>
<script type="text/javascript"><!--
var module_row = <?php echo $module_row; ?>;

function addModule() {
	html  = '<tbody id="module-row' + module_row + '">';
	html += '  <tr>';
	html += '    <td class="left" style="vertical-align:top; min-width:180px;">';
    <?php foreach ($languages as $language) { ?>
    html += '      <img src="view/image/flags/<?php echo $language['image']; ?>" alt="<?php echo $language['name']; ?>" />';
    html += '      <input type="text" name="<?php echo $classname; ?>_module[' + module_row + '][language_id][<?php echo $language['language_id']; ?>]" value="">';
    html += '      <br />';
    <?php } ?>
    html += '    </td>';
	html += '    <td class="left" style="vertical-align:top;"><select name="<?php echo $classname; ?>_module[' + module_row + '][category_id][]" multiple="multiple" size="20" style="min-width:300px; width:300px;">';
	<?php foreach ($categories as $category) { ?>
	html += '      <option value="<?php echo $category['category_id']; ?>"><?php echo addslashes($category['name']); ?></option>';
	<?php } ?>
	html += '      </select>';
	html += '      <br /><?php echo $help_category; ?>';
	html += '    </td>';

	html += '    <td class="left">';
	html += '      <table>'
	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_status; ?></td>';
	html += '          <td class="left">';
	html += '            <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][status]">';
	html += '              <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
	html += '              <option value="0"><?php echo $text_disabled; ?></option>';
	html += '            </select>';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_position; ?></td>';
	html += '          <td class="left">';
	html += '            <select name="<?php echo $classname; ?>_module[' + module_row + '][position]">';
	html += '      		   <option value="content_top"><?php echo $text_content_top; ?></option>';
	html += '      		   <option value="content_bottom"><?php echo $text_content_bottom; ?></option>';
	html += '      		   <option value="column_left"><?php echo $text_column_left; ?></option>';
	html += '      		   <option value="column_right"><?php echo $text_column_right; ?></option>';
	html += '    		 </select>';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_layout; ?></td>';
	html += '          <td class="left">';
	html += '            <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][layout_id]">';
	<?php foreach ($layouts as $layout) { ?>
	html += '      		   <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>';
	<?php } ?>
	html += '            </select>';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_count; ?></td>';
	html += '          <td class="left">';
	html += '            <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][count]">';
	html += '              <option value="1" selected="selected"><?php echo $text_yes; ?></option>';
	html += '              <option value="0"><?php echo $text_no; ?></option>';
	html += '            </select>';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_expand; ?></td>';
	html += '          <td class="left">';
	html += '            <select name="<?php echo $classname; ?>_module[<?php echo $module_row; ?>][expand]">';
	html += '              <option value="1" selected="selected"><?php echo $text_yes; ?></option>';
	html += '              <option value="0"><?php echo $text_no; ?></option>';
	html += '            </select>';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_style; ?></td>';
	html += '          <td class="left">';
	html += '    		 <select name="<?php echo $classname; ?>_module[' + module_row + '][style]">';
    html += '    	  	   <option value="list" selected="selected"><?php echo $text_list; ?></option>';
    html += '    	  	   <option value="select"><?php echo $text_select; ?></option>';
    html += '    	  	   <option value="graphic"><?php echo $text_graphic; ?></option>';
    html += '    		 </select>';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_css_class; ?></td>';
	html += '          <td class="left"><input type="text" name="<?php echo $classname; ?>_module[' + module_row + '][css_class]" value="" />';
	html += '          </td>';
	html += '        </tr>';

	html += '        <tr>';
	html += '          <td class="left"><?php echo $entry_sort_order; ?></td>';
	html += '          <td class="left"><input type="text" name="<?php echo $classname; ?>_module[' + module_row + '][sort_order]" value="" size="3" />';
	html += '          </td>';
	html += '        </tr>';

	html += '      </table>';
	html += '    </td>';

	html += '    <td class="left"><a onclick="$(\'#module-row' + module_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '  </tr>';
	html += '</tbody>';

	$('#module tfoot').before(html);

	module_row++;
}
//--></script>
<?php echo $footer; ?>
