Location: PHPKode > scripts > Avatar Tools > views/extensions_modules.php
<?php
/**
 * @version		$Id: coolfeed.php 100 2012-04-14 17:42:51Z hide@address.com $
 * @copyright	JoomAvatar.com
 * @author		Nguyen Quang Trung
 * @link		http://joomavatar.com
 * @license		License GNU General Public License version 2 or later http://www.gnu.org/licenses/gpl-2.0.html
 * @package		Avatar Dream Framework Template
 * @facebook 	http://www.facebook.com/pages/JoomAvatar/120705031368683
 * @twitter	    https://twitter.com/#!/JoomAvatar
 * @support 	http://joomavatar.com/forum/
 */

// no direct access
defined('_JEXEC') or die; 
 
	require_once dirname(dirname(__FILE__)).DS.'helpers/modules.php';
	$db = JFactory::getDBO(); 
?>
<script type="text/javascript">
	
	jQuery.noConflict();
	
	(function($) 
	{ 
		$(document).ready( function()
		{	
			var searchModulesRequest;
			
			$('#avatar-tool-modules-search').keyup(function()
			{
				if (searchModulesRequest !== undefined) {
					searchModulesRequest.abort();
				}
				
				searchModulesRequest = $.ajax({
				  	url: "index.php?option=avatar-tool&controller=ajax&task=modulesSearch",
				  	type: "POST",
				  	data: $("#avatar-tool-form-modules").serialize(),
				  	dataType: "json",
				});	
				
				searchModulesRequest.done(function(data) 
				{
					var items = $('#avatar-tool-modules-search-results');
					var html = '';
					
				  	data.each(function (el, index)
				  	{
				  		index++;
				  		
				  		if (el.published == '1') {
				  			publish = 'module-publish';
				  		} else {
				  			publish = 'module-unpublish';
				  		}
				  		
				  		html += '<li class="item ' + publish + ' ' + el.type + '">';
				  		html += '<form id="module-'+ el.id +'">';
				  		html += '<input type="hidden" name="id" value="'+ el.id +'">';
				  		html += '<input type="hidden" name="ordering" value="'+ $.addslashes(el.ordering) +'">';
				  		html += '<input type="hidden" name="position" value="'+ $.addslashes(el.position) +'">';
				  		html += '<h3 class="title avatar-tool-title">' + index + ' - <span>' + el.title + '</span></h3>';
				  		html += '<input class="avatar-tool-input-title" type="text" name="title" value="'+ $.addslashes(el.title)  +'">';
				  		html += '<div class="details">';
				  		
				  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_PUBLISH', true); ?></strong> <span class="publish state'+ el.published +'"></span></span>';
				  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_ACCESS'); ?></strong> <span class="text access">'+ el.access_level +'</span></span>';
				  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_ELEMENT'); ?></strong> <span class="text module">'+ el.module +'</span></span>';
				  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_ORDER'); ?></strong> <span class="text ordering">'+ el.ordering +'</span></span>';
				  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_POSITION'); ?></strong> <span class="text position">'+ el.position +'</span></span>';
				  		html += '<span class="action click"><strong><?php echo JText::_('AVATAR_TOOL_SHOWTITLE'); ?></strong> <span class="text showtitle state'+ el.showtitle +'"></span></span>';
				  		html += '<span class="action click assignment"><strong><?php echo JText::_('AVATAR_TOOL_ASSIGNMENT'); ?></strong></span>';
				  		html += '<span style="clear:both;"></span>';
				  		html += '</div>';
				  		html += '<div>';
				  		html += '<span class="avatar-tool-button">';
		  				html += '<a href="index.php?option=com_modules&task=module.edit&id='+ el.id +'"><?php echo JText::_('AVATAR_TOOL_BUTTON_EDIT',true); ?></a>';
		  				html += '</span>';
				  		html += '</div>';	
				  		html += '</form>';
				  		html += '</li>';
				  	})
				  	
				  	items.html(html);
				  	
				  	var moduleForms = $('#avatar-tool-modules-search-results form');
				  	var titles 	= $('#avatar-tool-modules-search-results .avatar-tool-title');
				  	var inputTitles = $('#avatar-tool-modules-search-results .avatar-tool-input-title');
				  	
				  	titles.each(function(index)
				  	{
				  		var el = $(this);
				  		el.click(function(){
				  			el.css('display', 'none');
				  			$(inputTitles[index]).css('display', 'block');
				  		});
				  	});
				  	
				  	inputTitles.each(function(index)
				  	{
				  		var el = $(this);
				  		el.change(function()
				  		{
				  			if (el.val() != '') 
				  			{
				  				$('span', $(titles[index])).html(el.val());
					  			el.css('display', 'none');
					  			$(titles[index]).css('display', 'block');
					  			
					  			request = $.ajax({
								  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleUpdateTitle",
								  	type: "POST",
								  	data: $('#' + moduleForms[index].get('id')).serialize(),
								  	dataType: "json",
								});	
				  			}
				  		});
				  	});
				  	
				  	var buttonPublishs 	= $('#avatar-tool-modules-search-results .details .publish');
			  		
			  		buttonPublishs.each(function(index)
				  	{
				  		$(this).click(function()
			  			{
			  				var el = $(this);
			  				var state = 0;
			  				
			  				if (el.hasClass('state1')) {
			  					el.removeClass('state1').addClass('state0');
			  					state = 0;
			  				} else if (el.hasClass('state0')) {
			  					el.removeClass('state0').addClass('state1');
			  					state = 1;
			  				};
			  			
			  				request = $.ajax({
							  	url: "index.php?option=avatar-tool&controller=ajax&task=modulePublish",
							  	type: "POST",
							  	data: $('#' + moduleForms[index].get('id')).serialize() + '&published=' + state,
							  	dataType: "json",
							});	
			  			});
				  	});
				  	
				  	var buttonShowTitles = $('#avatar-tool-modules-search-results .details .showtitle');
				  	
				  	buttonShowTitles.each(function(index)
				  	{
				  		$(this).click(function()
			  			{
			  				var el = $(this);
			  				var state = 0;
			  				
			  				if (el.hasClass('state1')) {
			  					el.removeClass('state1').addClass('state0');
			  					state = 0;
			  				} else if (el.hasClass('state0')) {
			  					el.removeClass('state0').addClass('state1');
			  					state = 1;
			  				};
			  			
			  				request = $.ajax({
							  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleShowTitle",
							  	type: "POST",
							  	data: $('#' + moduleForms[index].get('id')).serialize() + '&showtitle=' + state,
							  	dataType: "json",
							});	
			  			});
				  	})
				  	
				  	var buttonAccess = $('#avatar-tool-modules-search-results .details .access');
					
				  	buttonAccess.each(function(index)
				  	{
				  		var access = $(this);
				  		access.click(function()
				  		{
				  			$('#avatar-tool-subview-access').dialog({
				  				title: "<?php echo JText::_('AVATAR_TOOL_VIEW_ACCESS_TITLE', true); ?>",
				  				zIndex: 900,
				  				open: function(event, ui)
				  				{
				  					request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=accessGet",
									  	type: "GET",
									  	dataType: "json",
									});	
									
									request.done(function(data)
									{
										if ($.isArray(data)) 
										{
											var html = '';
											data.each(function(index)
											{
												html += '<p class="avatar-tool-button button-tag">' + $(index)[0].title;
												html += '<input type="hidden" name="access" value="'+ $.addslashes($(index)[0].id) +'"></p>';
											});
											
											html += '<p style="clear: both;"></p>'
											
											$('#avatar-tool-subview-access').html(html);
											
											$('#avatar-tool-subview-access .button-tag').each(function(el){
												$(this).draggable({
													revert: true,
													stack: "#avatar-tool-subview-access .button-tag",
													helper:'clone',
													appendTo: 'body',
													zIndex: 910,
													start: function(){
														$('#avatar-toolbar .details .access').each(function(index){
															$(this).css('background','#137BAF');
														});
													},
													stop: function(){
														$('#avatar-toolbar .details .access').each(function(index){
															$(this).css('background','');
														});
													}
											    });
												
											});
										}
									})
				  				}
				  			});
				  		});
				  		
				  		access.droppable(
				  		{
				  			accept: "#avatar-tool-subview-access .button-tag",
							drop: function(event, ui) 
							{ 
						   		$(this).html(ui.draggable.html());
						   		 
						   		request = $.ajax({
								  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleAccessUpdate",
								  	type: "POST",
								  	data: $('#' + moduleForms[index].get('id')).serialize(),
								  	dataType: "json",
								});	
							}
						});
				  	});
				  	
				  	var buttonPositions = $('#avatar-tool-modules-search-results .details .position');
					
				  	buttonPositions.each(function(index)
				  	{
				  		var position = $(this);
				  		var itemIndex = index;
				  		position.click(function()
				  		{
				  			$('#avatar-tool-subview-position').dialog({
				  				width: 600,
				  				title: "<?php echo JText::_('AVATAR_TOOL_VIEW_POSITION_TITLE', true) ?>",
				  				zIndex: 900,
				  				open: function(event, ui)
				  				{
				  					request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=positionGet",
									  	type: "GET",
									  	dataType: "json",
									});	
									
									request.done(function(data)
									{
										if ($.isPlainObject(data)) 
										{
											var html = '';
											$.each(data, function(index, value)
											{
												var strClass = '';
												value.each(function(el){
													strClass += el + ' ';
												});
												
												html += '<p class="avatar-tool-button button-tag" title="'+ strClass +'">' + index;
												html += '<input type="hidden" name="position" value="'+ $.addslashes(index) +'"></p>';
											});
											
											html += '<p style="clear: both;"></p>'
											
											$('#avatar-tool-subview-position').html(html);
											
											$('#avatar-tool-subview-position .button-tag').each(function(el){
												$(this).draggable({
													revert: true,
													stack: "#avatar-tool-subview-position .button-tag",
													helper:'clone',
													appendTo: 'body',
													zIndex: 910,
													start: function(){
														$('#avatar-toolbar .details .position').each(function(index){
															$(this).css('background','#137BAF');
														});
													},
													stop: function(){
														$('#avatar-toolbar .details .position').each(function(index){
															$(this).css('background','');
														});
													}
											    });
												
											});
										}
									})
				  				}
				  			});
				  		});
				  		
				  		position.droppable(
				  		{
				  			accept: "#avatar-tool-subview-position .button-tag",
							drop: function(event, ui) 
							{ 
								$('.text', this).html(ui.draggable.html());
						   		 
						   		request = $.ajax({
								  	url: "index.php?option=avatar-tool&controller=ajax&task=modulePositionUpdate",
								  	type: "POST",
								  	data: $('#' + moduleForms[index].get('id')).serialize(),
								  	dataType: "json",
								});
								
								request.done(function() {
									//order the module
									$('#avatar-tool-modules-search-results .details .ordering')[itemIndex].click();
								});	
							}
						});
				  	});
				  	
				  	var buttonOrders = $('#avatar-tool-modules-search-results .details .ordering');
					
				  	buttonOrders.each(function(index)
				  	{
				  		var order = $(this);
				  		
				  		order.click(function()
				  		{
				  			$('#avatar-tool-subview-ordering').dialog(
				  			{
				  				title: "<?php echo JText::_('AVATAR_TOOL_VIEW_ORDERING_TITLE', true); ?>",
				  				modal: true, 
				  				
				  				buttons: { 
				  					"<?php echo JText::_('AVATAR_TOOL_UPDATE', true); ?>": function() { 
				  						$(this).dialog("close"); 
				  						request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleUpdateOrder",
									  	type: "POST",
									  	data: $('#avatar-tool-form-ordering').serialize(),
									  	dataType: "json",
									});	
				  					} 
				  				},
				  				
				  				zIndex: 900,
				  				
				  				open: function(event, ui)
				  				{
				  					request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleGetOrder",
									  	type: "GET",
									  	data: $('#' + moduleForms[index].get('id')).serialize(),
									  	dataType: "json",
									});	
									
									request.done(function(data)
									{
										if ($.isArray(data)) 
										{
											var html = '<form id="avatar-tool-form-ordering"><ul class="list-items">';
											data.each(function(index)
											{
												html += '<li><p class="avatar-tool-button button-tag">' + $(index)[0].title;
												html += '<input type="hidden" name="ordering[]" value="'+ $.addslashes($(index)[0].id) +'"></p></li>';
											});
											
											html += '</ul></form><p style="clear: both;"></p>'
											
											$('#avatar-tool-subview-ordering').html(html);
											
											$('#avatar-tool-subview-ordering .list-items').sortable();
										}
									});
				  				}
				  			});
				  		});
				  	});
				  	
				  	var buttonAssignments = $('#avatar-tool-modules-search-results .details .assignment');
					
				  	buttonAssignments.each(function(index)
				  	{
				  		var bttassignment = $(this);
				  		var itemIndex = index;
				  		
				  		bttassignment.click(function()
				  		{
				  			$('#avatar-tool-subview-assignment').dialog({
				  				width: 800,
				  				modal: true,
				  				title: "<?php echo JText::_('AVATAR_TOOL_VIEW_ASSIGNMENT_TITLE', true) ?>",
				  				buttons: { 
				  					"<?php echo JText::_('AVATAR_TOOL_UPDATE', true); ?>": function() { 
				  						$(this).dialog("close"); 
				  						request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleUpdateAssignment",
									  	type: "POST",
									  	data: $('#avatar-tool-form-assignment').serialize(),
									  	dataType: "json",
									});	
				  					} 
				  				},
				  				zIndex: 900,
				  				open: function(event, ui)
				  				{
				  					request = $.ajax({
									  	url: "index.php?option=avatar-tool&controller=ajax&task=moduleGetAssignment",
									  	type: "GET",
									  	data: $('#' + moduleForms[index].get('id')).serialize(),
									  	dataType: "json",
									});	
									
									request.done(function(data)
									{
										if ($.isPlainObject(data)) 
										{
											var onAllPage = '';
											
											var html = '<div id="avatar-tool-tab-assignment" ><form id="avatar-tool-form-assignment">';
											html += '<input type="hidden" name="moduleid" value="'+ $.addslashes(data.moduleid) +'">';
											html += '<select class="assignment" name="assignment" >';
											html +=	'<option value="0"><?php echo JText::_('AVATAR_TOOL_BUTTON_ON_ALL_PAGES', true) ?></option>';
											html +=	'<option value="-"><?php echo JText::_('AVATAR_TOOL_BUTTON_NO_PAGE', true) ?></option>';
											html +=	'<option value="1"><?php echo JText::_('AVATAR_TOOL_BUTTON_ONLY_THE_PAGES_SELECTED', true) ?></option>';
											html +=	'<option value="-1"><?php echo JText::_('AVATAR_TOOL_BUTTON_ON_ALL_PAGES_EXCEPT_THOSE_SELECTED', true) ?></option>';
											html +=	'</select>';
											
											var menus = '';
											var tab = '<ul>';
											var slider = '';
											var strClass = 0;
											var assignment = '-';
											
											var checked = '';
													
											if ($.inArray('0', data.assigned) >= 0) {
												checked = 'checked="checked"';
												assignment = 0;
											} else if (data.assigned.length && data.assigned[0] < 0) {
												assignment = -1;
											} else if (data.assigned.length && data.assigned[0] > 0) {
												assignment = 1;
											}
											
											data.menus.each(function(el)
											{
												tab += '<li><a href="#avatar-tool-tab-assignment-'+ el.id +'">'+ el.title +'</a></li>';
												
												slider += '<div id="avatar-tool-tab-assignment-'+ el.id +'">';
												slider += '<span class="avatar-tool-button button-select selectall"><?php echo JText::_('AVATAR_TOOL_BUTTON_SELECT_ALL', true) ?></span>';
												slider += '<span class="avatar-tool-button button-select unselectall"><?php echo JText::_('AVATAR_TOOL_BUTTON_UNSELECT_ALL', true) ?></span><hr/>';
												slider += '<p><ul class="menu-links">';
												
												var count = el.links.length;
												var i = 0;
												
												if (count) 
												{
													el.links.each(function(link)
													{
														if ($.inArray(link.value, data.assigned) >= 0) {
															checked = 'checked="checked"';	
														} else if ($.inArray( '-' + link.value, data.assigned) >= 0) {
															checked = 'checked="checked"';
														} else {
															checked = '';
														}
														
														slider += '<li class="menu-link">';
														slider += '<input id="link-' + link.value + '" type="checkbox" name="assigned[]" value="'+ $.addslashes(link.value) +'" '+ checked +'>';
														slider += '<label for="link-' + link.value + '">'+ link.text +'</label>';
														slider += '</li>';
														
														if (count > 10 && ++i == Math.ceil(count/2)) {
															slider += '</ul><ul class="menu-links">';
														}
													});	
												}
												
												slider += '</ul><div style="clear: both;"></div></p></div>';
											});
											
											tab += '</ul>'
											html += tab + slider + '</div></form>';
											
											$('#avatar-tool-subview-assignment').html(html);
											
											$('#avatar-tool-tab-assignment').tabs();
											
											function validateAssignMent(assign) 
											{
												if (assign != '' && assign != undefined) {
													$('#avatar-tool-tab-assignment .assignment').val(assign);
													var value = assign;	
												} else {
													var value = $('#avatar-tool-tab-assignment .assignment').val();
												}
												
												var list = $('#avatar-tool-tab-assignment .assignment');
												var buttons = $('#avatar-tool-tab-assignment .ui-tabs-panel .button-select');
												var inputs =  $('#avatar-tool-tab-assignment .ui-tabs-panel input');
												
												if(value == '-' || value == '0') 
												{
													buttons.each(function(){
														$(this).attr('disabled', true);
													});
													
													inputs.each(function() {
														$(this).attr('disabled', true);
														if (value == '-') {
															$(this).attr('checked', false);
														} else {
															$(this).attr('checked', true);
														}
													});	
												} 
												else 
												{
													buttons.each(function(){
														$(this).attr('disabled', false);
													});
													
													inputs.each(function() {
														$(this).attr('disabled', false);
													});
												}
											}
											
											validateAssignMent(assignment);
											
											$('#avatar-tool-tab-assignment .assignment').change(function() {
												validateAssignMent();
											});
											
											$('#avatar-tool-tab-assignment .ui-tabs-panel .button-select').each(function()
											{
												var parent = $(this).parent();
												
												if($(this).hasClass('selectall')) 
												{
													$(this).click(function(){
														
														$('.menu-link input', parent).each(function(){
															$(this).attr('checked', true);
															$(this).parent().addClass('selected');
														})			
													});
												}
												
												if($(this).hasClass('unselectall')) 
												{
													$(this).click(function() {
														$('.menu-link input', parent).each(function(){
															$(this).attr('checked', false);
															$(this).parent().removeClass('selected');
														})
													});
												}
											});
										}
									})
				  				}
				  			});
				  		});
				  	});
				});	
			});
		})		
	})(jQuery);
</script>

<div class="avatar-view" id="avatar-view-modules">
	<form id="avatar-tool-form-modules" name="avatar-tool-form-modules">
		<ul class="list-item">
			<li class="item">
				<p class="label"><?php echo JText::_('AVATAR_TOOL_MODULES_SEARCH'); ?></p>
				<p class="description"><?php echo JText::_('AVATAR_TOOL_MODULES_SEARCH_DESC') ?></p>
				<input id="avatar-tool-modules-search" size="50" name="search"/>	
				<p class="description"><?php echo JText::_('AVATAR_TOOL_MODULES_SEARCH_OPTIONS_DESC') ?></p>
				<?php echo JText::_('AVATAR_TOOL_LIMIT'); ?> <input type="text" name="search-options[limit]" value="100" size="5"/> &nbsp;&nbsp;
				<?php echo JText::_('AVATAR_TOOL_POSITION'); ?> <?php echo PlgAvatarModules::getPositionHTML('Selectbox', array('name' => 'search-options[position]', 'js' => 'onchange="AvatarTools.modules.triggerSearch()"')); ?> &nbsp;&nbsp;
				<?php echo JText::_('AVATAR_TOOL_ELEMENT'); ?> <?php echo PlgAvatarModules::getModuleHTML('Selectbox', array('name' => 'search-options[module]', 'js' => 'onchange="AvatarTools.modules.triggerSearch()"')); ?> &nbsp;&nbsp;
				<br/><br/>
				<span class="avatar-tool-button" onclick="AvatarTools.fillter.reset('#avatar-tool-modules-search-results li', '#avatar-tool-modules-search', '#avatar-tool-form-modules .list-item select', '#avatar-tool-modules-search');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_RESET'); ?></span> &nbsp;&nbsp;
				<span class="avatar-tool-button" onclick="AvatarTools.fillter.fillter('module-publish', '#avatar-tool-modules-search-results li');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_PUBLISH'); ?></span> &nbsp;&nbsp;
				<span class="avatar-tool-button" onclick="AvatarTools.fillter.fillter('module-unpublish', '#avatar-tool-modules-search-results li');" > <?php echo JText::_('AVATAR_TOOL_ARTICLE_UNPUBLISH'); ?></span> &nbsp;&nbsp;
			</li>
		</ul>	
	</form>
	
	<ul id="avatar-tool-modules-search-results" class="list-item">
		
	</ul>	
</div>
Return current item: Avatar Tools