Exemplo n.º 1
0
function structure_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $events;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we can use media browser in this function
    if (empty($item->id)) {
        $navibars->title(t(16, 'Structure') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(16, 'Structure') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>'));
    if (empty($item->id)) {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    } else {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
        $delete_html = array();
        $delete_html[] = '<div id="navigate-delete-dialog" class="hidden">' . t(57, 'Do you really want to delete this item?') . '</div>';
        $delete_html[] = '<script language="javascript" type="text/javascript">';
        $delete_html[] = 'function navigate_delete_dialog()';
        $delete_html[] = '{';
        $delete_html[] = '$("#navigate-delete-dialog").removeClass("hidden");';
        $delete_html[] = '$("#navigate-delete-dialog").dialog({
							resizable: true,
							height: 150,
							width: 300,
							modal: true,
							title: "' . t(59, 'Confirmation') . '",
							buttons: {
								"' . t(58, 'Cancel') . '": function() {
									$(this).dialog("close");
								},
								"' . t(35, 'Delete') . '": function() {
									$(this).dialog("close");
									window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=4&id=' . $item->id . '";
								}
							}
						});';
        $delete_html[] = '}';
        $delete_html[] = '</script>';
        $navibars->add_content(implode("\n", $delete_html));
    }
    $extra_actions = array();
    if (!empty($item->id)) {
        $DB->query('
            SELECT s.id, wd.text as title, s.position
              FROM nv_structure s, nv_webdictionary wd
             WHERE s.website = ' . $item->website . '
               AND s.parent = ' . $item->parent . '
               AND wd.website  = ' . $item->website . '
               AND wd.node_type = "structure"
               AND wd.lang = "' . $website->languages_list[0] . '"
               AND wd.subtype = "title"
               AND wd.node_id = s.id
          ORDER BY s.position ASC, s.id ASC
        ');
        $brothers = $DB->result();
        $previous_brother = NULL;
        $next_brother = NULL;
        for ($b = 0; $b < count($brothers); $b++) {
            if ($brothers[$b]->id == $item->id) {
                $previous_brother = @$brothers[$b - 1]->id;
                $previous_brother_title = @$brothers[$b - 1]->title;
                $next_brother = @$brothers[$b + 1]->id;
                $next_brother_title = @$brothers[$b + 1]->title;
            }
        }
        if (!empty($item->parent)) {
            $parent = new structure();
            $parent->load($item->parent);
            $extra_actions[] = '    <a href="?fid=structure&act=edit&id=' . $parent->id . '">
                                        <img height="16" align="absmiddle" width="16" src="img/icons/silk/resultset_first.png"> 
                                        <small>(' . strtolower(t(84, 'Parent')) . ')</small> ' . $parent->dictionary[$website->languages_list[0]]["title"] . '</a>';
        }
        if (!empty($previous_brother)) {
            $extra_actions[] = '    <a href="?fid=structure&act=edit&id=' . $previous_brother . '">
                                        <img height="16" align="absmiddle" width="16" src="img/icons/silk/resultset_previous.png"> 
                                        <small>(' . strtolower(t(501, 'Previous')) . ')</small> ' . $previous_brother_title . '</a>';
        }
        if (!empty($next_brother)) {
            $extra_actions[] = '    <a href="?fid=structure&act=edit&id=' . $next_brother . '">
                                        <img height="16" align="absmiddle" width="16" src="img/icons/silk/resultset_next.png"> 
                                        <small>(' . strtolower(t(502, 'Next')) . ')</small> ' . $next_brother_title . '</a>';
        }
    }
    $events->add_actions('structure', array('item' => &$item, 'navibars' => &$navibars), $extra_actions);
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=structure&act=edit&parent=' . $item->parent . '&template=' . $item->template . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=structure&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/sitemap_color.png"> ' . t(61, 'Tree') . '</a>', 'search_form'));
    $navibars->form();
    $navibars->add_tab(t(43, "Main"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    if (empty($item->id)) {
        $item->parent = $_GET['parent'];
    }
    $navibars->add_tab_content($naviforms->hidden('id', $item->id));
    //$navibars->add_tab_content($naviforms->hidden('parent', $item->parent));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->parent);
    if (empty($categories_list)) {
        $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>';
    }
    $navibars->add_tab_content_row(array('<label>' . t(84, 'Parent') . '</label>', $naviforms->dropdown_tree('parent', $categories_list, $item->parent, 'navigate_parent_category_change')), 'category_tree');
    $layout->add_script('
        function navigate_parent_category_change(id)
        {
            $.ajax(
            {
                url: NAVIGATE_APP + "?fid=structure&act=category_path&id=" + id,
                dataType: "json",
                data: {},
                success: function(data, textStatus, xhr)
                {
                    item_category_path = data;
                }
            });
        }
    ');
    if (empty($item->template) && isset($_GET['template'])) {
        $item->template = $_GET['template'];
    }
    $templates = template::elements('structure');
    $template_select = $naviforms->select_from_object_array('template', $templates, 'id', 'title', $item->template);
    $navibars->add_tab_content_row(array('<label>' . t(79, 'Template') . '</label>', $template_select));
    $navibars->add_tab_content_row(array('<label>' . t(85, 'Date published') . '</label>', $naviforms->datefield('date_published', $item->date_published, true)));
    $navibars->add_tab_content_row(array('<label>' . t(90, 'Date unpublished') . '</label>', $naviforms->datefield('date_unpublish', $item->date_unpublish, true)));
    $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in')))));
    $webuser_groups = webuser_group::all_in_array();
    $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field');
    $layout->add_script('
        function navigate_webuser_groups_visibility(access_value)
        {
            if(access_value==3)
                $("#webuser-groups-field").show();
            else
                $("#webuser-groups-field").hide();
        }

        navigate_webuser_groups_visibility(' . $item->access . ');
    ');
    $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')), $item->permission, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody')))));
    $navibars->add_tab_content_row(array('<label>' . t(283, 'Shown in menus') . '</label>', $naviforms->checkbox('visible', $item->visible)));
    if ($item->views > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(280, 'Page views') . '</label>', $item->views));
    }
    $navibars->add_tab(t(54, "Text") . ' / ' . t(74, "Paths"));
    $lang_selector = array();
    $lang_selector[] = '<div class="buttonset">';
    $checked = ' checked="checked" ';
    foreach ($website->languages_list as $lang_code) {
        $lang_selector[] = '<input type="radio" id="language_selector_' . $lang_code . '" name="language_selector" value="' . $lang_code . '" ' . $checked . ' />
							<label for="language_selector_' . $lang_code . '"  onclick="navigate_structure_select_language(\'' . $lang_code . '\');">' . language::name_by_code($lang_code) . '</label>';
        $checked = "";
    }
    $lang_selector[] = '</div>';
    $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', implode("\n", $lang_selector)));
    foreach ($website->languages_list as $lang_code) {
        $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang_code . '" style=" display: none; ">');
        $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang_code, @$item->dictionary[$lang_code]['title'])));
        $open_live_site = '';
        if (!empty($item->paths[$lang_code])) {
            $open_live_site = ' <a target="_blank" href="' . $website->absolute_path(true) . $item->paths[$lang_code] . '"><img src="img/icons/silk/world_go.png" align="absmiddle" /></a>';
        }
        $navibars->add_tab_content_row(array('<label>' . t(75, 'Path') . $open_live_site . '</label>', $naviforms->textfield('path-' . $lang_code, @$item->paths[$lang_code], NULL, 'navigate_structure_path_check(this);'), '<span>&nbsp;</span>'));
        /*									
        $navibars->add_tab_content_row(array(	'<label>&nbsp;</label>',
        										'<div class="subcomment"><sup>*</sup> '.t(83, 'Leave blank to disable this item').'</div>',
        									));		
        */
        $navibars->add_tab_content_row(array('<label>' . t(172, 'Action') . '</label>', $naviforms->selectfield('action-type-' . $lang_code, array(0 => 'url', 1 => 'jump-branch', 2 => 'jump-item', 3 => 'do-nothing'), array(0 => t(173, 'Open URL'), 1 => t(322, 'Jump to another branch'), 2 => t(323, 'Jump to an element'), 3 => t(183, 'Do nothing')), $item->dictionary[$lang_code]['action-type'], "navigate_structure_action_change('" . $lang_code . "', this);")));
        // load item title if action was "jump to an element"
        $jump_item_id = '';
        $jump_item_title = '';
        if (!empty($item->dictionary[$lang_code]['action-jump-item'])) {
            $tmp = new Item();
            $tmp->load($item->dictionary[$lang_code]['action-jump-item']);
            $jump_item_title = array($tmp->dictionary[$lang_code]['title']);
            $jump_item_id = array($item->dictionary[$lang_code]['action-jump-item']);
        }
        $navibars->add_tab_content_row(array('<label>' . t(180, 'Item') . ' [' . t(67, 'Title') . ']</label>', $naviforms->selectfield('action-jump-item-' . $lang_code, $jump_item_id, $jump_item_title, $item->dictionary[$lang_code]['action-jump-item'], null, false, null, null, false), '<div class="subcomment"><span class="ui-icon ui-icon-info" style=" float: left; margin-left: -3px; "></span> ' . t(534, "You can only select elements which have their own path (no category embedded elements)") . '</div>'));
        $categories_list = structure::hierarchyList($hierarchy, $item->dictionary[$lang_code]['action-jump-branch'], $lang_code);
        $navibars->add_tab_content_row(array('<label>' . t(325, 'Branch') . '</label>', '<div class="category_tree" id="category_tree_jump_branch_' . $lang_code . '">
				        <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="category_tree_ul">' . $categories_list . '</div>' . '</div>', $naviforms->hidden('action-jump-branch-' . $lang_code, $item->dictionary[$lang_code]['action-jump-branch'])));
        $navibars->add_tab_content_row(array('<label>' . t(324, 'New window') . '</label>', $naviforms->checkbox('action-new-window-' . $lang_code, $item->dictionary[$lang_code]['action-new-window'])));
        $navibars->add_tab_content('</div>');
    }
    $parent = new structure();
    $parent->paths = array();
    if (!empty($item->parent)) {
        $parent->load($item->parent);
    }
    $layout->add_script('
		function navigate_structure_select_language(code)
		{
			$(".language_fields").css("display", "none");
			$("#language_fields_" + code).css("display", "block");
		}
		
		var active_languages = ["' . implode('", "', $website->languages_list) . '"];
		var last_check = [];
		var item_category_path = ' . json_encode($parent->paths) . ';
		
		function navigate_structure_path_generate(el)
		{
			var language = $(el).attr("id").substr(5);
			var surl = "";
			if(item_category_path[language] && item_category_path[language]!="")
				surl = item_category_path[language];
			else
				surl = "/" + language;
			var title = $("#title-"+language).val();
            title = title.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			title = title.replace(/[.\\s]+/g, navigate["word_separator"]);

			surl += "/" + title;
			$(el).val(surl.toLowerCase());
			navigate_structure_path_check(el);
		}		
		
		function navigate_structure_path_check(el)		
		{
		    var caret_position = null;
            if($(el).is("input") && $(el).is(":focus"))
                caret_position = $(el).caret();

			var path = $(el).val();
			
			if(path=="") return;			
			if(path==last_check[$(el).id]) return;
			if(path.indexOf("http")==0) return; // ignore paths starting with http/https

            path = path.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			path = path.replace(/[.\\s]+/g, navigate["word_separator"]);

			$(el).val(path);
			
			last_check[$(el).id] = path;
			
			$(el).next().html("<img src=\\"' . NAVIGATE_URL . '/img/loader.gif\\" align=\\"absmiddle\\" />");
			
			$.ajax({
			  url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=95",
			  dataType: "json",
			  data: "id=' . $item->id . '&path=" + $(el).val(),
			  type: "get",
			  success: function(data, textStatus)
			  {
				  var free = true;

				  if(data && data.length==1)
				  {
					 // same element?
					 if( data[0].object_id != "' . $item->id . '" ||
						 data[0].type != "structure" )
					 {
						free = false; 
					 }
				  }
				  else if(data && data.length > 1)
				  {
					  free = false;
				  }
				  
				  if(free)	free = "<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/tick.png\\" align=\\"absmiddle\\" />";
				  else		free = "<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/cancel.png\\" align=\\"absmiddle\\" />";

                  free += "<img class=\\"erase_path\\" src=\\"" + NAVIGATE_URL + "/img/icons/silk/erase.png\\" align=\\"absmiddle\\" />";
                  $(el).next().find(".erase_path").off();
                  $(el).next().html(free);
                  $(el).next().find(".erase_path").on("click", function()
                  {
                    $(el).focus();
                    $(el).val("");
                  }).css("cursor", "pointer");
			  }
			});

            if($(el).is("input") && $(el).is(":focus"))
            $(el).caret(caret_position)
		}
				
		function navigate_structure_action_change(language, element)
		{			
			$("#action-new-window-" + language).parent().hide();
			$("#action-jump-item-" + language).parent().hide();
			$("#action-jump-branch-" + language).parent().hide();			
			
			switch(jQuery(element).val())
			{
				case "do-nothing":
				
					break;
					
				case "jump-branch":
					$("#action-new-window-" + language).parent().show();
					$("#action-jump-branch-" + language).parent().show();
					
					$("#category_tree_jump_branch_" + language+ " .category_tree_ul").jstree({
                        plugins: ["changed", "types"],
                        "types" : 
                        {
                            "default":  {   "icon": "img/icons/silk/folder.png"    },
                            "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
                        },
                        "core" : 
                        {
                            "multiple" : false
                        }
					}).on("changed.jstree", function(e, data) 
					{
                        var i, j, r = [];
                        for(i = 0, j = data.selected.length; i < j; i++) 
                        {
                            var selected_node = data.instance.get_node(data.selected[i]).data.nodeId;
                            $("#action-jump-branch-" + language).val(selected_node);
                        }
                    });                    
					break;
					
				case "jump-item":
					$("#action-new-window-" + language).parent().show();
					$("#action-jump-item-" + language).parent().show();
					break;
					
				case "url":
					$("#action-new-window-" + language).parent().show();
					break;
			}
	
		}
		
		$(window).on("load", function()
		{
			for(al in active_languages)
			{
				navigate_structure_path_check($("#path-" + active_languages[al]));
				
				$("#path-" + active_languages[al]).on("focus", function()
				{
					if($(this).val() == "")
						navigate_structure_path_generate($(this));
				});

                $("#action-jump-item-" + active_languages[al]).select2(
                {
                    placeholder: "' . t(533, "Find element by title") . '",
                    minimumInputLength: 1,
                    ajax: {
                        url: NAVIGATE_APP + "?fid=" + navigate_query_parameter(\'fid\') + "&act=json_find_item",
                        dataType: "json",
                        delay: 100,
                        data: function(params)
                        {
	                        return {
				                title: params.term,
				                lang: $("input[name=\\"language_selector\\"]:checked").val(),
				                nd: new Date().getTime(),
				                page_limit: 30, // page size
				                page: params.page // page number
				            };
                        },
                        processResults: function (data, params)
				        {
				            params.page = params.page || 1;
				            return {
								results: data.items,
								pagination: { more: (params.page * 30) < data.total_count }
							};
				        }
                    },
                    templateSelection: function(row)
					{
						if(row.id)
							return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>";
						else
							return row.text;
					},
					escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                    triggerChange: true,
                    allowClear: true
                });

				navigate_structure_action_change(active_languages[al], $("#action-type-" + active_languages[al]));
			}
		});
				
	');
    $layout->add_script('navigate_structure_select_language("' . $website->languages_list[0] . '")');
    if (!empty($item->template)) {
        $properties_html = navigate_property_layout_form('structure', $item->template, 'structure', $item->id);
        if (!empty($properties_html)) {
            $navibars->add_tab(t(77, "Properties"));
            $navibars->add_tab_content($properties_html);
        }
    }
    if ($item->votes > 0) {
        $navibars->add_tab(t(352, "Votes"));
        $score = $item->score / $item->votes;
        $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_pie.png" align="absmiddle" /> ' . t(337, 'Summary'), array('<div class="navigate-panels-summary ui-corner-all"><h2>' . $item->votes . '</h2><br />' . t(352, 'Votes') . '</div>', '<div class="navigate-panels-summary ui-corner-all""><h2>' . $score . '</h2><br />' . t(353, 'Score') . '</div>', '<div style=" float: left; margin-left: 8px; "><a href="#" class="uibutton" id="items_votes_webuser">' . t(15, 'Users') . '</a></div>', '<div style=" float: right; margin-right: 8px; "><a href="#" class="uibutton" id="items_votes_reset">' . t(354, 'Reset') . '</a></div>', '<div id="items_votes_webuser_window" style=" display: none; width: 600px; height: 350px; "></div>'), 'navigate-panel-web-summary', '385px', '200px');
        $layout->add_script('
			$("#items_votes_reset").bind("click", function()
			{
				$.post("?fid=' . $_REQUEST['fid'] . '&act=votes_reset&id=' . $item->id . '", function(data)
				{
					$("#navigate-panel-web-summary").addClass("ui-state-disabled");
					navigate_notification("' . t(355, 'Votes reset') . '");
				});
			});
			
			$("#items_votes_webuser").bind("click", function()
			{
				$( "#items_votes_webuser_window" ).dialog(
				{
					title: "' . t(357, 'User votes') . '",
					width: 700,
					height: 400,
					modal: true,
					open: function()
					{
						$( "#items_votes_webuser_window" ).html("<table id=\\"items_votes_webuser_grid\\"></table>");
						$( "#items_votes_webuser_window" ).append("<div id=\\"items_votes_webuser_grid_pager\\"></div>");
						
						jQuery("#items_votes_webuser_grid").jqGrid(
						{
						  url: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '",
						  editurl: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '",
						  datatype: "json",
						  mtype: "GET",
						  pager: "#items_votes_webuser_grid_pager",	
						  colNames:["ID", "' . t(86, 'Date') . '", "' . t(1, 'Username') . '"],
						  colModel:[
							{name:"id", index:"id", width: 75, align: "left", sortable:true, editable:false, hidden: true},
							{name:"date",index:"date", width: 180, align: "center", sortable:true, editable:false},
							{name:"username", index:"username", align: "left", width: 380, sortable:true, editable:false}
							
						  ],
						  scroll: 1,
						  loadonce: false,
						  autowidth: true,
						  forceFit: true,
						  rowNum: 12,
						  rowList: [12],	
						  viewrecords: true,
						  multiselect: true,		  
						  sortname: "date",
						  sortorder: "desc"
						});	
						
						$("#items_votes_webuser_grid").jqGrid(	"navGrid", 
																"#items_votes_webuser_grid_pager", 
																{
																	add: false,
																	edit: false,
																	del: true,
																	search: false
																}
															);
					}
				});
			});				
		');
        $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(353, 'Score'), array('<div id="navigate-panel-web-score-graph" style=" height: 171px; width: 385px; "></div>'), 'navigate-panel-web-score', '385px', '200px');
        $votes_by_score = webuser_vote::object_votes_by_score('structure', $item->id);
        $gdata = array();
        $colors = array('#0a2f42', '#62bbe8', '#1d8ec7', '#44aee4', '#bbe1f5');
        foreach ($votes_by_score as $vscore) {
            $gdata[] = (object) array('label' => $vscore->value, 'data' => (int) $vscore->votes, 'color' => $colors[$vscore->value % count($colors)]);
        }
        $layout->add_script('
			$(document).ready(function()
			{		
				var gdata = ' . json_encode($gdata) . ';				
			
				$.plot($("#navigate-panel-web-score-graph"), gdata,
				{						
						series: 
						{
							pie: 
							{
								show: true,
								radius: 1,
								tilt: 0.5,
								startAngle: 3/4,
								label: 
								{
									show: true,
									formatter: function(label, series)
									{
										return \'<div style="font-size:12px;text-align:center;padding:2px;color:#fff;"><span style="font-size: 20px; font-weight: bold; ">\'+label+\'</span><br/>\'+Math.round(series.percent)+\'% (\'+series.data[0][1]+\')</div>\';
									},
									background: { opacity: 0.6 }
								},
								stroke: 
								{
									color: "#F2F5F7",
									width: 4
								},
							}
						},
						legend: 
						{
							show: false
						}
				});
		');
        $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(352, 'Votes') . ' (' . t(356, 'last 90 days') . ')', array('<div id="navigate-panel-web-votes-graph" style=" height: 171px; width: 385px; "></div>'), 'navigate-panel-web-votes', '385px', '200px');
        $votes_by_date = webuser_vote::object_votes_by_date('structure', $item->id, 90);
        $layout->add_script('
								
				var plot = $.plot(
					$("#navigate-panel-web-votes-graph"), 
					[' . json_encode($votes_by_date) . '], 
					{
						series:
						{
							points: { show: true, radius: 3 }
						},
						xaxis: 
						{ 
							mode: "time", 
							tickLength: 5
						},
						yaxis:
						{
							tickDecimals: 0,
							zoomRange: false,
							panRange: false
						},
						grid: 
						{ 
							markings: function (axes) 
							{
								var markings = [];
								var d = new Date(axes.xaxis.min);
								// go to the first Saturday
								d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
								d.setUTCSeconds(0);
								d.setUTCMinutes(0);
								d.setUTCHours(0);
								var i = d.getTime();
								do {
									// when we dont set yaxis, the rectangle automatically
									// extends to infinity upwards and downwards
									markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
									i += 7 * 24 * 60 * 60 * 1000;
								} while (i < axes.xaxis.max);
						
								return markings;
							},
							markingsColor: "#e7f5fc"								
						},
						zoom: 
						{
							interactive: true
						},
						pan: 
						{
							interactive: true
						}
					});

				});					
		
		');
    }
    $elements = $item->elements();
    if (count($elements) > 0) {
        $ids = array();
        $navibars->add_tab(t(22, "Elements"));
        $table = new naviorderedtable("structure_elements");
        $table->setDblclickCallback("structure_elements_open");
        $table->setHiddenInput('elements-order');
        $table->addHeaderColumn('ID', 24);
        $table->addHeaderColumn(t(486, 'Title'), 500);
        foreach ($elements as $element) {
            $table->addRow($element->id, array(array('content' => $element->id, 'align' => 'left'), array('content' => $element->dictionary[$website->languages_list[0]]['title'], 'align' => 'left')));
            $ids[] = $element->id;
        }
        $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                    <input type="hidden" name="elements-order" id="elements-order" value="' . implode("#", $ids) . '" />
                    <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '
                </div>'));
        $layout->add_script('
            function structure_elements_open(element)
            {
                window.location.replace("?fid=items&act=edit&id=" + $(element).attr("id") );
            }
        ');
    }
    $events->trigger('structure', 'edit', array('item' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms));
    return $navibars->generate();
}
Exemplo n.º 2
0
function blocks_type_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $events;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item['id'])) {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(167, 'Types') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(167, 'Types') . ' / ' . t(170, 'Edit') . ' [' . $item['id'] . ']');
    }
    $readonly = false;
    if (empty($item['id'])) {
        $navibars->add_actions(array('<a href="#" onclick="$(\'#navigate-content\').find(\'form\').eq(0).submit();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    } else {
        if (!empty($item['id']) && !is_numeric($item['id'])) {
            $layout->navigate_notification(t(432, "Read only mode"), false, true);
            $readonly = true;
        } else {
            $navibars->add_actions(array('<a href="#" onclick="$(\'#navigate-content\').find(\'form\').eq(0).submit();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
            $layout->add_script('
            function navigate_delete_dialog()
            {
                navigate_confirmation_dialog(
                    function() { window.location.href = "?fid=blocks&act=block_type_delete&id=' . $item['id'] . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
        }
    }
    $group_blocks_links = array();
    list($bg_rs, $bg_total) = block_group::paginated_list(0, 10, 'title', 'desc');
    if ($bg_total > 0 && $bg_total <= 10) {
        foreach ($bg_rs as $bg) {
            $group_blocks_links[] = '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_group_edit&id=' . $bg['id'] . '"><i class="fa fa-fw fa-caret-right"></i> ' . $bg['title'] . '</a>';
        }
        $events->add_actions('blocks', array('item' => null, 'navibars' => &$navibars), $group_blocks_links, '<a class="content-actions-submenu-trigger" href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . ' &#9662;</a>');
    }
    $navibars->add_actions(array('<a href="?fid=' . $_REQUEST['fid'] . '&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/brick.png"> ' . t(23, 'Blocks') . '</a>', !empty($group_blocks_links) ? '' : '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . '</a>'));
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_type_edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_types_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>'));
    $navibars->form();
    $navibars->add_tab(t(43, "Main"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content($naviforms->hidden('id', $item['id']));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item['id']) ? $item['id'] : t(52, '(new)')) . '</span>'));
    // TODO: in Navigate CMS 2.0+ add several block types (p.e. Ad (Google adsense, ...), Map (Bing, Yahoo, Google, ...))
    $block_modes = block::modes();
    $navibars->add_tab_content_row(array('<label>' . t(491, 'Class') . '</label>', $naviforms->selectfield('type', array_keys($block_modes), array_values($block_modes), $item['type'], '', false)));
    $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title', $item['title'])));
    $navibars->add_tab_content_row(array('<label>' . t(237, 'Code') . '</label>', $naviforms->textfield('code', $item['code']), '<div class="subcomment">
            <span style=" float: left; margin-left: -3px; " class="ui-icon ui-icon-lightbulb"></span>' . t(436, 'Used as a class in HTML elements') . '</div>'));
    $navibars->add_tab_content_row(array('<label>' . t(168, 'Notes') . '</label>', $naviforms->textarea('notes', $item['notes'])));
    $navibars->add_tab(t(145, "Size") . ' & ' . t(438, "Order"));
    $navibars->add_tab_content_row(array('<label>' . t(155, 'Width') . '<sup>*</sup></label>', $naviforms->textfield('width', $item['width']), 'px'));
    $navibars->add_tab_content_row(array('<label>' . t(156, 'Height') . '<sup>*</sup></label>', $naviforms->textfield('height', $item['height']), 'px'));
    $navibars->add_tab_content_row(array('<div class="subcomment italic">* ' . t(169, 'You can leave blank a field to not limit the size') . '</div>'));
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<a id="wikipedia_web_banner_entry" class="italic" href="http://en.wikipedia.org/wiki/Web_banner" target="_blank"><span class="ui-icon ui-icon-info" style=" float: left;"></span> ' . t(393, 'Standard banner sizes') . ' (Wikipedia)</a>'));
    $navibars->add_tab_content_row(array('<label>' . t(404, 'Order by') . '</label>', $naviforms->selectfield('order', array('theme', 'priority', 'random'), array(t('368', 'Theme'), t('66', 'Priority'), t('399', 'Random')), $item['order'])));
    $navibars->add_tab_content_row(array('<label>' . t(397, 'Maximum') . '</label>', $naviforms->textfield('maximum', $item['maximum']), '<div class="subcomment"><span class="ui-icon ui-icon-lightbulb" style=" float: left; margin-left: -3px; "></span> ' . t(400, 'Enter 0 to display all') . '</div>'));
    $layout->add_script('
        function navigate_blocks_code_generate(el)
        {
            if($("#code").val()!="")
                return;
            var title = $("#title").val();
			title = title.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			title = title.replace(/[.\\s]+/g, navigate["word_separator"]);
            $("#code").val(title.toLowerCase());
        }

        $("#code").on("focus", function()
        {
            if($(this).val() == "")
                navigate_blocks_code_generate();
        });
        ');
    if (!empty($item['id'])) {
        $navibars->add_tab(t(77, "Properties"));
        $table = new naviorderedtable("block_properties_table");
        $table->setWidth("550px");
        $table->setHiddenInput("block-properties-order");
        $table->setDblclickCallback("navigate_block_edit_property");
        $navibars->add_tab_content($naviforms->hidden('block-properties-order', ""));
        $table->addHeaderColumn(t(159, 'Name'), 350, true);
        $table->addHeaderColumn(t(160, 'Type'), 150);
        $table->addHeaderColumn(t(65, 'Enabled'), 50);
        $properties = property::elements($item['id'], 'block');
        $types = property::types();
        for ($p = 0; $p < count($properties); $p++) {
            $table->addRow($properties[$p]->id, array(array('content' => $properties[$p]->name, 'align' => 'left'), array('content' => $types[$properties[$p]->type], 'align' => 'left'), array('content' => '<input type="checkbox" name="property-enabled[]" value="' . $properties[$p]->id . '" disabled="disabled" id="block-type-property-enabled-' . $properties[$p]->id . '" ' . ($properties[$p]->enabled == '1' ? ' checked=checked ' : '') . ' />
                                    <label for="block-type-property-enabled-' . $properties[$p]->id . '"></label>', 'align' => 'center')));
        }
        if ($readonly) {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>'));
        } else {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                    <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '.
                     ' . t(192, 'Double click any row to edit') . '
                </div>'));
            $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="block-properties-create"><img src="img/icons/silk/add.png" align="absmiddle" /> ' . t(38, 'Create') . '</button>'));
        }
        $navibars->add_content('
		<form id="block-properties-edit-dialog" style="display: none;">
			<div class="navigate-form-row">
				<label>ID</label>
				<span id="property-id-span">' . t(52, '(new)') . '</span>
				' . $naviforms->hidden('property-id', '') . '
				' . $naviforms->hidden('property-template', $item->id) . '
				' . $naviforms->hidden('property-element', "block") . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(67, 'Title') . '</label>
				' . $naviforms->textfield('property-name', '') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(160, 'Type') . '</label>
				' . $naviforms->selectfield('property-type', array_keys($types), array_values($types), 'value', 'navigate_block_property_type_change()') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(200, 'Options') . '</label>
				' . $naviforms->textarea('property-options', '') . '
				<div class="subcomment">
					' . t(201, 'One line per option, formatted like this: value#title') . '
				</div>
			</div>
			<div class="navigate-form-row">
				<label>' . t(199, 'Default value') . '</label>
				' . $naviforms->textfield('property-dvalue', '') . '
				<div class="subcomment">
				    <span id="property-comment-boolean">' . t(426, 'Enter "1" for true, "0" for false') . '</span>
					<span id="property-comment-option">' . t(202, 'Enter only the value') . '</span>
					<span id="property-comment-moption">' . t(212, 'Enter the selected values separated by commas') . ': 3,5,8</span>
					<span id="property-comment-text">' . t(203, 'Same value for all languages') . '</span>
					<span id="property-comment-rating">' . t(223, 'Default is 5 stars, if you want a different number: default_value#number_of_stars') . ' 5#10</span>
					<span id="property-comment-date">' . t(50, 'Date format') . ': ' . date($user->date_format) . '</span>
					<span id="property-comment-color">' . t(442, 'Hexadecimal color code') . ': #ffffff</span>
					<span id="property-comment-country">' . t(225, 'Alpha-2 country code') . ' (es, us, uk...)</span>
					<span id="property-comment-file">' . t(204, 'ID of the file') . '</span>
					<span id="property-comment-coordinates">' . t(298, 'Latitude') . '#' . t(299, 'Longitude') . ': 40.689231#-74.044505</span>
				</div>
			</div>
			<div class="navigate-form-row">
				<label>' . t(65, 'Enabled') . '</label>
				' . $naviforms->checkbox('property-enabled', 1) . '
			</div>
		</form>');
        $layout->add_script('
			$("#block-properties-create").bind("click", function()
			{
				navigate_block_edit_property();
				return false;
			});

			function navigate_block_edit_property(el)
			{
				if(!el)	// new property
				{
					$("#property-id").val("");
					$("#property-id-span").html("' . t(52, '(new)') . '");
					$("#property-template").val("' . $item['id'] . '");
					$("#property-name").val("");
					$("#property-type").val("value");
					$("#property-element").val("block");
					$("#property-options").val("");
					$("#property-dvalue").val("");
				    $("#property-enabled").attr("checked", "checked");
				}
				else
				{
					$.ajax({
					   type: "GET",
					   async: false,
					   dateType: "json",
					   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=block_property_load&block=' . $item->id . '&id=" + $(el).attr("id"),
					   success: function(data)
					   {
						   $("#property-id-span").html(data.id);
						   $("#property-id").val(data.id);
						   $("#property-template").val(data.template);
						   $("#property-name").val(data.name);
						   $("#property-type").val(data.type);
						   $("#property-element").val("block");
						   $("#property-options").val(data.options);
						   $("#property-dvalue").val(data.dvalue);
						   if(data.enabled=="1")
							   $("#property-enabled").attr("checked", "checked");
							else
							   $("#property-enabled").removeAttr("checked");

						   var options = "";
						   for(var o in data.options)
						   {
							   options += o + "#" + data.options[o] + "\\n";
						   }
						   $("#property-options").val(options);

					   }
					 });
				}

				navigate_block_property_type_change();

				if(' . ($readonly ? 'true' : 'false') . ')
				{
                    $("#block-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 360,
                        width: 650,
                        modal: true,
                    });
				}
				else // show dialog with action buttons
				{
                    $("#block-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 410,
                        width: 650,
                        modal: true,
                        buttons: {
                            "' . t(58, 'Cancel') . '": function() {
                                $(this).dialog("close");
                            },
                            "' . t(35, 'Delete') . '": function() {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=block_property_remove",
                                   data: $("#block-properties-edit-dialog").serialize(),
                                   success: function(msg)
                                   {
                                     $("#block_properties_table").find("#" + $("#property-id").val()).remove();
                                     navigate_naviorderedtable_block_properties_table_reorder();
                                     $("#block-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            },
                            "' . t(190, 'Ok') . '": function()
                            {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=block_property_save",
                                   data: $("#block-properties-edit-dialog").serialize(),
                                   success: function(data)
                                   {
                                       if($("#property-id").val() > 0)
                                       {
                                           // update
                                           var tr = $("#block_properties_table").find("#" + $("#property-id").val());
                                           tr.find("td").eq(0).html(data.name);
                                           tr.find("td").eq(1).html(data.type_text);
                                           tr.find("input[type=checkbox]").attr("checked", (data.enabled==1));
                                       }
                                       else
                                       {
                                           // insert
                                           var checked = "";

                                           if(data.enabled) checked = \' checked="checked" \';
                                           var tr = \'<tr id="\'+data.id+\'"><td>\'+data.name+\'</td><td>\'+data.type_text+\'</td><td align="center"><input name="property-enabled[]" id="block-type-property-enabled-\'+data.id+\'" type="checkbox" disabled="disabled" value="\'+data.id+\'" \'+checked+\' /><label for="block-type-property-enabled-\'+data.id+\'"></label></td></tr>\';
                                           $("#block_properties_table").find("tbody:last").append(tr);
                                           $("#block_properties_table").find("tr:last").on("dblclick", function() { navigate_block_edit_property(this); });
                                           $("#block_properties_table").tableDnD(
                                            {
                                                onDrop: function(table, row)
                                                {		navigate_naviorderedtable_block_properties_table_reorder();		}
                                            });
                                       }
                                       navigate_naviorderedtable_block_properties_table_reorder();
                                       $("#block-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            }
                        }
                    });
                }
			}

			function navigate_block_property_type_change()
			{
				$("#property-options").parent().hide();
				$("#property-dvalue").next().find("span").hide();

				switch($("#property-type").val())
				{
					case "option":
						$("#property-options").parent().show();
						$("#property-comment-option").show();
						break;

					case "moption":
						$("#property-options").parent().show();
						$("#property-comment-moption").show();
						break;

					case "text":
					case "textarea":
					case "link":
						$("#property-comment-text").show();
						break;

					case "date":
					case "datetime":
						$("#property-comment-date").show();
						break;

					case "image":
					case "file":
						$("#property-comment-file").show();
						break;

					case "rating":
						$("#property-comment-rating").show();
						break;

                    case "color":
						$("#property-comment-color").show();
						break;

					case "coordinates":
						$("#property-comment-coordinates").show();
						break;

					case "country":
						$("#property-comment-country").show();
						break;

                    case "boolean":
						$("#property-comment-boolean").show();
						break;

					case "comment":
					case "value":
					default:
				}
			}

			navigate_naviorderedtable_block_properties_table_reorder();
		');
    }
    return $navibars->generate();
}
Exemplo n.º 3
0
function templates_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item->id)) {
        $navibars->title(t(20, 'Templates') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(20, 'Templates') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $readonly = false;
    if (!empty($item->id) && !is_numeric($item->id)) {
        $layout->navigate_notification(t(432, "Read only mode"), false, true);
        $readonly = true;
    } else {
        if (empty($item->id)) {
            $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
        } else {
            $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
            $delete_html = array();
            $delete_html[] = '<div id="navigate-delete-dialog" class="hidden">' . t(57, 'Do you really want to delete this item?') . '</div>';
            $delete_html[] = '<script language="javascript" type="text/javascript">';
            $delete_html[] = 'function navigate_delete_dialog()';
            $delete_html[] = '{';
            $delete_html[] = '$("#navigate-delete-dialog").removeClass("hidden");';
            $delete_html[] = '$("#navigate-delete-dialog").dialog({
							resizable: true,
							height: 150,
							width: 300,
							modal: true,
							title: "' . t(59, 'Confirmation') . '",
							buttons: {
								"' . t(58, 'Cancel') . '": function() {
									$(this).dialog("close");
								},
								"' . t(35, 'Delete') . '": function() {
									$(this).dialog("close");
									window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=4&id=' . $item->id . '";
								}
							}
						});';
            $delete_html[] = '}';
            $delete_html[] = '</script>';
            $navibars->add_content(implode("\n", $delete_html));
        }
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=templates&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=templates&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form'));
    $navibars->form();
    $navibars->add_tab(t(43, "Main"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content($naviforms->hidden('id', $item->id));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title', $item->title)));
    if ($readonly) {
        $navibars->add_tab_content_row(array('<label>' . t(82, 'File') . '</label>', '<span>' . $item->file . '</span>'));
    } else {
        $navibars->add_tab_content_row(array('<label>' . t(82, 'File') . '</label>', '<span>' . NAVIGATE_PRIVATE . '/' . $website->id . '/templates/</span>', $naviforms->textfield('file', $item->file, '236px'), empty($item->file) ? '' : '<a href="#" onclick="navigate_templates_editor();"><img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" /></a>'));
    }
    $navibars->add_content('
		<div id="templates-file-edit-dialog" style=" display: none; ">
			<textarea name="templates-file-edit-area" id="templates-file-edit-area" style=" width: 99%; height: 98%; ">' . htmlentities(@file_get_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $item->file), ENT_COMPAT, 'UTF-8') . '</textarea>
		</div>
	');
    $layout->add_script('
		var current_template_editor = null;
		function navigate_templates_editor()
		{
			var file = $("#file").val();

			$("#templates-file-edit-dialog").dialog(
			{
				title: \'<img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . ' \' + file,
				resizable: true,
				draggable: true,
				width: $(window).width() - 60,
				height: $(window).height() - 50,
				position: { my: "center", at: "center", of: window },
				modal: true,
				open: function()
				{
                    current_template_editor = CodeMirror.fromTextArea(
                        $("#templates-file-edit-area")[0],
                        {
                            mode: "text/html",
                            tabMode: "indent",
                            lineNumbers: true,
                            matchBrackets: true
                        }
                    );

					$(".CodeMirror").css({ width: "99%", height: "98%"});
					$(".CodeMirror-scroll").css({ width: "100%", height: "100%"});
				},
				beforeClose: function() {
				    // dialog may be closed by clicking on a footer button or clicking the close "x" icon on top
				    if(current_template_editor)
				    {
				        current_template_editor.toTextArea();
					    current_template_editor = null;
                    }
				},
				buttons: {
					"' . t(58, 'Cancel') . '": function() {
						$("#templates-file-edit-dialog").dialog("close");
					},
					"' . t(34, 'Save') . '": function()
					{ 					
						current_template_editor.toTextArea();					
						current_template_editor = null;
						
						$.ajax({
						   type: "POST",
						   async: false,
						   dateType: "text",
						   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&id=' . $item->id . '&act=save_template_file",
						   data: $("#templates-file-edit-area").serialize(),
						   success: function(data)
						   {			
							   	if(data=="true")
								{						
									$("#templates-file-edit-dialog").dialog("close"); 
									navigate_notification("' . t(235, 'File saved successfully.') . '");
								}
								else
								{
									$("#templates-file-edit-dialog").dialog("close"); 
									navigate_notification("' . t(56, 'Unexpected error.') . '");
								}
						   }
						 });
					}					
				}				
			}).dialogExtend(
			{
				maximizable: true
			});
		}
	');
    $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')), $item->permission, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody')))));
    $navibars->add_tab_content_row(array('<label>' . t(62, 'Statistics') . '</label>', $naviforms->checkbox('statistics', $item->statistics)));
    $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled)));
    if (!empty($item->id)) {
        $navibars->add_tab(t(236, "Sections"));
        $table = new naviorderedtable("template_sections_table");
        $table->setWidth("600px");
        $table->setHiddenInput("template-sections-order");
        $navibars->add_tab_content($naviforms->hidden('template-sections-order', ""));
        $table->addHeaderColumn(t(237, 'Code'), 100);
        $table->addHeaderColumn(t(159, 'Name'), 250);
        $table->addHeaderColumn(t(267, 'Editor'), 100);
        $table->addHeaderColumn(t(155, 'Width'), 100);
        $table->addHeaderColumn(t(35, 'Remove'), 100);
        for ($p = 0; $p < count($item->sections); $p++) {
            $disabled = $item->sections[$p]['code'] == 'main';
            unset($selected);
            $selected = array();
            $selected[$item->sections[$p]['editor']] = ' selected="selected" ';
            $select_editor = '<select name="template-sections-editor[]" style=" width: 125px; ">';
            $select_editor .= '	<option value="tinymce" ' . $selected['tinymce'] . '>TinyMCE</option>';
            $select_editor .= '	<option value="html" ' . $selected['html'] . '>' . t(269, 'HTML code') . '</option>';
            $select_editor .= '	<option value="raw" ' . $selected['raw'] . '>' . t(268, 'Raw') . '</option>';
            $select_editor .= '</select>';
            $table->addRow($p, array(array('content' => '<input type="text" name="template-sections-code[]" value="' . $item->sections[$p]['code'] . '" style="width: 140px;" />', 'align' => 'left'), array('content' => '<input type="text" name="template-sections-name[]" value="' . template::section_name($item->sections[$p]['name']) . '" style="width: 290px;" />', 'align' => 'left'), array('content' => $select_editor, 'align' => 'left'), array('content' => '<div style=" white-space: nowrap; "><input type="text" name="template-sections-width[]" value="' . template::section_name($item->sections[$p]['width']) . '" style="width: 40px;" /> px</div>', 'align' => 'left'), array('content' => !empty($disabled) || $readonly ? '' : '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" onclick="navigate_templates_sections_remove(this);" />', 'align' => 'center')));
        }
        if ($readonly) {
            $navibars->add_tab_content_row(array('<label>' . t(236, 'Sections') . '</label>', '<div>' . $table->generate() . '</div>'));
        } else {
            $navibars->add_tab_content_row(array('<label>' . t(236, 'Sections') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                                                        <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '.
                                                         ' . t(192, 'Double click any row to edit') . '
                                                    </div>'));
            $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="templates-sections-create"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(38, 'Create') . '</button>'));
        }
        $navibars->add_content('
			<form id="templates-sections-edit-dialog" style="display: none;">
				' . $naviforms->hidden('section-id', '') . '
				<div class="navigate-form-row">
					<label>' . t(67, 'Title') . '</label>
					' . $naviforms->textfield('section-name', '') . '
				</div>
				<div class="navigate-form-row">
					<label>' . t(237, 'Code') . '</label>
					' . $naviforms->textfield('section-code', '') . '					
				</div>			
			</form>');
        $section_widths = templates_section_widths();
        $layout->add_script('
			$("#templates-sections-create").on("click", function() {
				var tr = \'<tr id="\'+(new Date().getTime())+\'">\';
				tr += \'<td><input type="text" name="template-sections-code[]" value="" style="width: 140px;" /></td>\';
				tr += \'<td><input type="text" name="template-sections-name[]" value="" style="width: 290px;" /></td>\';
				tr += \'<td><select style="width: 125px;" name="template-sections-editor[]"><option selected="selected" value="tinymce">TinyMCE</option><option value="html">' . t(269, 'HTML code') . '</option><option value="raw">' . t(268, 'Raw') . '</option></select></td>\';
				tr += \'<td><div style="white-space: nowrap;"><input type="text" style="width: 40px;" value="950" name="template-sections-width[]"> px</div></td>\';
				tr += \'<td align="center"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" onclick="navigate_templates_sections_remove(this);" style="cursor:pointer;" /></td>\';				
				tr += \'</tr>\';
				
				$("#template_sections_table").find("tbody:last").append(tr);
				$("#template_sections_table").tableDnD(
				{
					onDrop: function(table, row) 
					{		navigate_naviorderedtable_template_sections_table_reorder();		}
				});			

				$(\'input[name="template-sections-width[]"]\').autocomplete(
				{
					source: function(request, response) { response(' . json_encode($section_widths) . '); },
					minLength: 0			
				});				

				return false;
			});
			
			function navigate_templates_sections_remove(el)
			{				
				$(el).parent().parent().remove();
			}
			
			$(\'input[name="template-sections-width[]"]\').autocomplete(
			{
				source: function(request, response) { response(' . json_encode($section_widths) . '); },
				minLength: 0			
			});
			
			$(document).on(\'click\', \'input[name="template-sections-width[]"]\', function()			
			{
				$(this).autocomplete( "search" , $(this).val());
			});
		');
        $navibars->add_tab_content_row(array('<label>' . t(210, 'Gallery') . '</label>', $naviforms->checkbox('gallery', $item->gallery)));
        $navibars->add_tab_content_row(array('<label>' . t(250, 'Comments') . '</label>', $naviforms->checkbox('comments', $item->comments)));
        $navibars->add_tab_content_row(array('<label>' . t(265, 'Tags') . '</label>', $naviforms->checkbox('tags', $item->tags)));
        $navibars->add_tab(t(77, "Properties"));
        $table = new naviorderedtable("template_properties_table");
        $table->setWidth("550px");
        $table->setHiddenInput("template-properties-order");
        $table->setDblclickCallback("navigate_templates_edit_property");
        $navibars->add_tab_content($naviforms->hidden('template-properties-order', ""));
        $table->addHeaderColumn(t(159, 'Name'), 250, true);
        $table->addHeaderColumn(t(160, 'Type'), 150);
        $table->addHeaderColumn(t(87, 'Association'), 100);
        $table->addHeaderColumn(t(65, 'Enabled'), 50);
        $properties = property::elements($item->id);
        $types = property::types();
        $element_types = array('item' => t(180, 'Item'), 'structure' => t(16, 'Structure'));
        for ($p = 0; $p < count($properties); $p++) {
            $table->addRow($properties[$p]->id, array(array('content' => $properties[$p]->name, 'align' => 'left'), array('content' => $types[$properties[$p]->type], 'align' => 'left'), array('content' => $element_types[$properties[$p]->element], 'align' => 'left'), array('content' => '<input type="checkbox" name="property-enabled[]" class="raw-checkbox" value="' . $properties[$p]->id . '" ' . ($properties[$p]->enabled == '1' ? ' checked=checked ' : '') . ' />', 'align' => 'center')));
        }
        if ($readonly) {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>'));
        } else {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                                                        <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '.
                                                         ' . t(192, 'Double click any row to edit') . '
                                                    </div>'));
            $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="templates-properties-create"><img src="img/icons/silk/add.png" align="absmiddle" /> ' . t(38, 'Create') . '</button>'));
        }
        $navibars->add_content('
		<form id="templates-properties-edit-dialog" style="display: none;">
			<div class="navigate-form-row">
				<label>ID</label>
				<span id="property-id-span">' . t(52, '(new)') . '</span>
				' . $naviforms->hidden('property-id', '') . '
				' . $naviforms->hidden('property-template', $item->id) . '			
			</div>	
			<div class="navigate-form-row">
				<label>' . t(67, 'Title') . '</label>
				' . $naviforms->textfield('property-name', '') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(87, 'Association') . '</label>
				' . $naviforms->selectfield('property-element', array_keys($element_types), array_values($element_types), 'value') . '
			</div>			
			<div class="navigate-form-row">
				<label>' . t(160, 'Type') . '</label>
				' . $naviforms->selectfield('property-type', array_keys($types), array_values($types), 'value', 'navigate_templates_property_type_change()') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(200, 'Options') . '</label>
				' . $naviforms->textarea('property-options', '') . '
				<div class="subcomment">
					' . t(201, 'One line per option, formatted like this: value#title') . '
				</div>				
			</div>
			<div class="navigate-form-row">
				<label>' . t(547, 'Multilanguage') . '</label>
				' . $naviforms->checkbox('property-multilanguage', false) . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(199, 'Default value') . '</label>
				' . $naviforms->textfield('property-dvalue', '') . '	
				<div class="subcomment">
				    <span id="property-comment-boolean">' . t(426, 'Enter "1" for true, "0" for false') . '</span>
					<span id="property-comment-option">' . t(202, 'Enter only the value') . '</span>
					<span id="property-comment-moption">' . t(212, 'Enter the selected values separated by commas') . ': 3,5,8</span>
					<span id="property-comment-text">' . t(203, 'Same value for all languages') . '</span>
					<span id="property-comment-rating">' . t(223, 'Default is 5 stars, if you want a different number: default_value#number_of_stars') . ' 5#10</span>
					<span id="property-comment-date">' . t(50, 'Date format') . ': ' . date($user->date_format) . '</span>										
					<span id="property-comment-color">' . t(442, 'Hexadecimal color code') . ': #ffffff</span>
					<span id="property-comment-country">' . t(225, 'Alpha-2 country code') . ' (es, us, uk...)</span>
					<span id="property-comment-file">' . t(204, 'ID of the file') . '</span>
					<span id="property-comment-video">' . t(490, 'ID of the file or public video URL') . '</span>
					<span id="property-comment-coordinates">' . t(298, 'Latitude') . '#' . t(299, 'Longitude') . ': 40.689231#-74.044505</span>
				</div>
			</div>
			<div class="navigate-form-row">
				<label>' . t(65, 'Enabled') . '</label>
				' . $naviforms->checkbox('property-enabled', 1) . '
			</div>
            <div class="navigate-form-row">
				<label>' . t(550, 'Help text') . '</label>
				' . $naviforms->textfield('property-helper', '') . '
			</div>
		</form>');
        $layout->add_script('
			$("#templates-properties-create").bind("click", function()
			{
				navigate_templates_edit_property();
				return false;
			});
		
			function navigate_templates_edit_property(el)
			{
				if(!el)	// new property
				{
					$("#property-id").val("");
					$("#property-id-span").html("' . t(52, '(new)') . '");
					$("#property-element").val("template");
					$("#property-template").val("' . $item->id . '");
					$("#property-name").val("");
					$("#property-type").val("value");
					$("#property-options").val("");
					$("#property-dvalue").val("");
					$("#property-helper").val("");
					$("#property-multilanguage").removeAttr("checked");
				    $("#property-enabled").attr("checked", "checked");
				}
				else
				{
					$.ajax({
					   type: "GET",
					   async: false,
					   dateType: "json",
					   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=template_property_load&template=' . $item->id . '&id=" + $(el).attr("id"),
					   success: function(data)
					   {
						   $("#property-id-span").html(data.id);
						   $("#property-id").val(data.id);
						   $("#property-element").val(data.element);
						   $("#property-template").val(data.template);
						   $("#property-name").val(data.name);
						   $("#property-type").val(data.type);
						   $("#property-options").val(data.options);
						   $("#property-dvalue").val(data.dvalue);
						   $("#property-helper").val(data.helper);

						   if(data.multilanguage=="true")
							   $("#property-multilanguage").attr("checked", "checked");
							else
							   $("#property-multilanguage").removeAttr("checked");

						   if(data.enabled=="1")
							   $("#property-enabled").attr("checked", "checked");
							else
							   $("#property-enabled").removeAttr("checked");
							   
						   var options = "";
						   for(var o in data.options)
						   {
							   options += o + "#" + data.options[o] + "\\n";
						   }
						   $("#property-options").val(options);

					   }
					 });					
				}
				
				navigate_templates_property_type_change();
				
				var navigate_templates_element_types = new Array();
				navigate_templates_element_types["item"] = "' . t(180, 'Item') . '";
				navigate_templates_element_types["structure"] = "' . t(16, 'Structure') . '";
				//navigate_templates_element_types["product"] = "' . t(214, 'Product') . '";

				if(' . ($readonly ? 'true' : 'false') . ')
				{
                    $("#templates-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 360,
                        width: 650,
                        modal: true,
                    });
				}
				else // show dialog with action buttons
				{
                    $("#templates-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 410,
                        width: 650,
                        modal: true,
                        buttons: {
                            "' . t(58, 'Cancel') . '": function() {
                                $(this).dialog("close");
                            },
                            "' . t(35, 'Delete') . '": function() {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=template_property_remove",
                                   data: $("#templates-properties-edit-dialog").serialize(),
                                   success: function(msg)
                                   {
                                     $("#template_properties_table").find("#" + $("#property-id").val()).remove();
                                     navigate_naviorderedtable_template_properties_table_reorder();
                                     $("#templates-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            },
                            "' . t(190, 'Ok') . '": function()
                            {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=template_property_save",
                                   data: $("#templates-properties-edit-dialog").serialize(),
                                   success: function(data)
                                   {
                                       if($("#property-id").val() > 0)
                                       {
                                           // update
                                           var tr = $("#template_properties_table").find("#" + $("#property-id").val());
                                           tr.find("td").eq(0).html(data.name);
                                           tr.find("td").eq(1).html(data.type_text);
                                           tr.find("td").eq(2).html(navigate_templates_element_types[data.element]);
                                           tr.find("input[type=checkbox]").attr("checked", (data.enabled==1));
                                       }
                                       else
                                       {
                                           // insert
                                           var checked = "";
                                           if(data.enabled) checked = \' checked="checked" \';
                                           var tr = \'<tr id="\'+data.id+\'"><td>\'+data.name+\'</td><td>\'+data.type_text+\'</td><td>\'+navigate_templates_element_types[data.element]+\'</td><td align="center"><input name="property-enabled[]" class="raw-checkbox" type="checkbox" value="\'+data.id+\'" \'+checked+\' /></td></tr>\';
                                           $("#template_properties_table").find("tbody:last").append(tr);
                                           $("#template_properties_table").find("tr:last").bind("dblclick", function() { navigate_templates_edit_property(this); });
                                           $("#template_properties_table").tableDnD(
                                            {
                                                onDrop: function(table, row)
                                                {		navigate_naviorderedtable_template_properties_table_reorder();		}
                                            });
                                       }
                                       navigate_naviorderedtable_template_properties_table_reorder();
                                       $("#templates-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            }
                        }
                    });
                }
			}
			
			function navigate_templates_property_type_change()
			{
				$("#property-options").parent().hide();
				$("#property-multilanguage").parent().hide();
				$("#property-dvalue").next().find("span").hide();
				
				switch($("#property-type").val())
				{						
					case "option":
						$("#property-options").parent().show();
						$("#property-comment-option").show();
						break;
						
					case "moption":
						$("#property-options").parent().show();
						$("#property-comment-moption").show();
						break;						
						
					case "text":
					case "textarea":
					case "link":
					case "rich_textarea":
					case "source_code":
						$("#property-comment-text").show();
						break;
						
					case "date":
					case "datetime":
						$("#property-comment-date").show();
						break;
						
					case "image":
					case "file":
						$("#property-comment-file").show();
						$("#property-multilanguage").parent().show();
						break;

                    case "video":
						$("#property-comment-video").show();
						break;

					case "rating":
						$("#property-comment-rating").show();
						break;	

                    case "color":
						$("#property-comment-color").show();
						break;

					case "coordinates":
						$("#property-comment-coordinates").show();
						break;							
						
					case "country":
						$("#property-comment-country").show();
						break;

                    case "boolean":
						$("#property-comment-boolean").show();
						break;
					
					case "comment":
					case "value":
					default:
				}
			}
			
			navigate_naviorderedtable_template_properties_table_reorder();	
		');
    }
    return $navibars->generate();
}