<?php
if (!defined('IN_CONTEXT')) die('access violation error!');

$cols = 4;
?>
<script type="text/javascript" language="javascript">
<!--
function on_del_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("admingilst_stat");
    if (o_result.result == "ERROR") {
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
	    stat.innerHTML = "<?php _e('OK, refreshing...'); ?>";
	    reloadPage();
    } else {
        return on_failure(response);
    }
}

function on_del_failure(response) {
    document.getElementById("admingilst_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function delete_galleryitem(ga_id) {
	if (confirm("Delete the selected gallery item?")) {
	    var stat = document.getElementById("admingilst_stat");
	    stat.style.display = "block";
	    stat.innerHTML = "<?php _e('Deleting selected gallery item...'); ?>";
		_ajax_request("mod_gallery_item", 
			"admin_delete", 
	        {
	            ga_id:ga_id
	        }, 
			on_del_success, 
			on_del_failure);
	}
}

//-->
</script>
<div class="content_title">
	<h3><?php _e('Gallery Item'); ?></h3>
</div>
<div class="space"></div>
<div class="content_toolbar">
	<table cellspacing="0" class="wrap_table">
		<tbody>
			<tr>
				<td><a href="index.php?<?php echo Html::xuriquery('mod_gallery_item', 'admin_add', array('ga_id' => ParamHolder::get('ga_id', 0))); ?>" title=""><?php _e('New Gallery Item'); ?></a></td>
				<td>|</td>
				<td><a href="index.php?<?php echo Html::xuriquery('mod_gallery', 'admin_list'); ?>" title=""><?php _e('Back'); ?></a></td>
				<td><?php include_once(P_TPL.'/common/language_switch.php'); ?></td>
			</tr>
		</tbody>
	</table>
</div>
<div class="space"></div>
<div class="status_bar">
	<span id="admingilst_stat" class="status" style="display:none;"></span>
</div>
<div class="space"></div>
<table cellspacing="1" class="list_table" id="admin_menu_item_list">
	<!-- thead>
		<tr>
            <th><?php _e('Title'); ?></th>
            <th><?php _e('Description'); ?></th>
            <th><?php _e('Publish'); ?></th>
            <th><?php _e('Operation'); ?></th>
        </tr>
    </thead -->
    <tbody>
        <tr>
            <td>
				<?php
				$n_img = sizeof($galleryitems);
				if ($n_img > 0){
				?>
					<table class="media_grid" cellspacing="1">
						<?php
						for ($i = 0; $i < $n_img; $i++) {
				        	if ($i % $cols == 0) {
				        	    echo '<tr>';
				        	}
				    	?>
				            <td width="<?php echo intval(100 / $cols); ?>%">
				            	<img border="0" src="<?php echo $galleryitems[$i]->feature_thumb;?>" class="media_thumb" />
				            	<br />
				            	<?php echo $galleryitems[$i]->title; ?><br />
				            	<?php echo Toolkit::switchText($galleryitems[$i]->published, array('0' => __('Unpublished'), '1' => __('Published'))); ?><br />
				            	<span class="small">
                                    <a href="index.php?<?php echo Html::xuriquery('mod_gallery_item', 'admin_edit', array('gi_id' => $galleryitems[$i]->id,'ga_id'=>$ga_id)); ?>" title="<?php _e('Edit'); ?>"><?php _e('Edit'); ?></a>
                                    &nbsp;
                                    <a href="#" onclick="delete_galleryitem(<?php echo $galleryitems[$i]->id; ?>);return false;" title="<?php _e('Delete'); ?>"><?php _e('Delete'); ?></a>
				            	</span>
				            </td>
				        <?php
				        	if (($i % $cols) == ($cols - 1)) {
				        	    echo '</tr>';
				        	}
						}
				        if ($i % $cols != 0) {
					        for ($j = 0; $j < ($cols - $i); $j++) {
					            echo '<td width="'.intval(100 / $cols).'%">&nbsp;</td>';
					        }
					        echo '</tr>';
				        }
						?>
					</table>
				<?php } ?>
            </td>
        </tr>
    </tbody>
</table>
<div class="space"></div>
<?php
include_once(P_TPL.'/common/pager.php');
?>
