public function languages()
 {
     $options = array();
     foreach ($this->languages_list as $active_language_code) {
         $options[$active_language_code] = language::name_by_code($active_language_code);
     }
     return $options;
 }
示例#2
0
function nvweb_languages($vars = array())
{
    global $website;
    global $current;
    $out = array();
    $class = value_or_default($vars['class'], "");
    switch ($vars['mode']) {
        case 'code':
            foreach ($website->languages_published as $lang) {
                if ($current['lang'] == $lang) {
                    $out[] = '<a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active">' . $lang . '</a>';
                } else {
                    $out[] = '<a href="?lang=' . $lang . '" class="' . $class . '">' . $lang . '</a>';
                }
            }
            $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out);
            break;
        case 'name':
            foreach ($website->languages_published as $lang) {
                $lang_name = language::name_by_code($lang);
                if ($current['lang'] == $lang) {
                    $out[] = '<a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active">' . $lang_name . '</a>';
                } else {
                    $out[] = '<a href="?lang=' . $lang . '" class="' . $class . '">' . $lang_name . '</a>';
                }
            }
            $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out);
            break;
        case 'flag':
            foreach ($website->languages_published as $lang) {
                $flag = $lang;
                if (strpos($lang, '_') > 0) {
                    $code = explode('_', $lang);
                    $flag = $code[0];
                    $extra = ' ' . $code[1];
                }
                if ($current['lang'] == $lang) {
                    $out[] = '<a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active"><img src="' . NVWEB_ABSOLUTE . '/object?type=flag&code=' . $flag . '" />' . $extra . '</a>';
                } else {
                    $out[] = '<a href="?lang=' . $lang . '" class="' . $class . '"><img src="' . NVWEB_ABSOLUTE . '/object?type=flag&code=' . $flag . '" alt="' . $flag . '" />' . $extra . '</a>';
                }
            }
            $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out);
            break;
        case 'li':
            foreach ($website->languages_published as $lang) {
                if (empty($lang)) {
                    continue;
                }
                $lang_name = language::name_by_code($lang);
                if ($current['lang'] == $lang) {
                    $out[] = '<li><a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active">' . $lang_name . '</a></li>';
                } else {
                    $out[] = '<li><a href="?lang=' . $lang . '" class="' . $class . '">' . $lang_name . '</a></li>';
                }
            }
            $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out);
            break;
        case 'select':
        default:
            $out[] = '<select class="' . $class . '" onchange="if(this.value!=\'' . $current['lang'] . '\') window.location.href = \'?lang=\'+this.value;">';
            foreach ($website->languages_published as $lang) {
                if (empty($lang)) {
                    continue;
                }
                $lang_name = language::name_by_code($lang);
                if ($current['lang'] == $lang) {
                    $out[] = '<option value="' . $lang . '" selected="selected">' . $lang_name . '</option>';
                } else {
                    $out[] = '<option value="' . $lang . '">' . $lang_name . '</option>';
                }
            }
            $out[] = '</select>';
            $out = implode("\n", $out);
            break;
    }
    return $out;
}
function webdictionary_edit_language_form($code)
{
    global $DB;
    global $website;
    global $theme;
    global $events;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $navibars->title(t(21, 'Dictionary') . ' / ' . t(602, 'Edit language'));
    $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    $navibars->add_actions(array('<a href="?fid=webdictionary&act=0"><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(188, "Translate"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $origin = "";
    foreach ($website->languages_list as $l) {
        if ($l == $code) {
            continue;
        } else {
            $origin = $l;
            break;
        }
    }
    // retrieve original theme translations, if any
    $theme->get_translations();
    $dict_dest = array();
    foreach ($theme->dictionaries as $otext) {
        if ($otext['lang'] == $code) {
            $dict_dest[$otext['node_id']] = $otext['text'];
        }
    }
    // retrieve existing database dictionary translations
    $DB->query('
		SELECT *
		  FROM nv_webdictionary
		 WHERE (	(node_type = "global")
		    		OR (node_type = "theme" AND theme= "' . $theme->name . '")
		       ) AND
		       website = ' . $website->id . '
    ');
    $db_trans = $DB->result();
    foreach ($db_trans as $otext) {
        $text_id = $otext->node_id;
        if ($otext->node_type == "theme") {
            $text_id = $otext->subtype;
        }
        if ($otext->lang == $code) {
            $dict_dest[$text_id] = $otext->text;
        } else {
            if ($otext->lang == $origin && $otext->node_type == "global") {
                array_push($theme->dictionaries, array("source" => $text_id, "node_id" => $text_id, "text" => $otext->text, "lang" => $otext->lang));
            }
        }
    }
    $extensions_translations = array();
    $extensions = extension::list_installed();
    if (!is_array($extensions)) {
        $extensions = array();
    }
    foreach ($extensions as $extension) {
        $ext = new extension();
        $ext->load($extension['code']);
        $extension_translations = $ext->get_translations();
        // load all translations of the extension
        $extensions_translations = array_merge($extensions_translations, $extension_translations);
    }
    $DB->query('
		SELECT *
		  FROM nv_webdictionary
		 WHERE node_type = "extension" AND
		       website = ' . $website->id, 'array');
    $resultset = $DB->result();
    for ($dbrs = 0; $dbrs < count($resultset); $dbrs++) {
        $found = false;
        for ($trs = 0; $trs < count($extensions_translations); $trs++) {
            if ($resultset[$dbrs]['node_type'] == "extension" && $resultset[$dbrs]['extension'] == $extensions_translations[$trs]['extension'] && $resultset[$dbrs]['subtype'] == $extensions_translations[$trs]['node_id'] && $resultset[$dbrs]['lang'] == $extensions_translations[$trs]['lang']) {
                $found = true;
                $extensions_translations[$trs]['text'] = $resultset[$dbrs]['text'];
            }
        }
        // translation was not included in the extension languages, so we need to add it to our array
        if (!$found) {
            $extensions_translations[] = array('extension' => $resultset[$dbrs]['extension'], 'source' => 'extension.' . $resultset[$dbrs]['extension'] . '.' . $resultset[$dbrs]['subtype'], 'node_id' => $resultset[$dbrs]['subtype'], 'lang' => $resultset[$dbrs]['lang'], 'text' => $resultset[$dbrs]['text']);
        }
    }
    // generate table
    $table = '<table class="box-table">';
    $table .= '<tr><th>' . t(237, "Code") . '</th><th>' . language::name_by_code($origin) . '</th><th>' . language::name_by_code($code) . '</th></tr>';
    foreach ($theme->dictionaries as $otext) {
        if ($otext['lang'] == $origin) {
            $translation = $dict_dest[$otext['node_id']];
            if (is_numeric($otext['source'])) {
                $otext['source'] = 'global.' . $otext['source'];
            }
            // note: PHP does not allow using dots in $_POST variable names, unless they are used in an array
            $table .= '
				<tr>
					<td>' . $otext['node_id'] . '</textarea></td>
					<td><textarea rows="2" cols="60" disabled="disabled">' . $otext['text'] . '</textarea></td>
					<td><textarea name="data[' . $code . '.' . $otext['source'] . ']" rows="2" cols="60">' . $translation . '</textarea></td>
				</tr>
			';
        }
    }
    foreach ($extensions_translations as $otext) {
        if ($otext['lang'] == $origin) {
            $translation = "";
            foreach ($extensions_translations as $dtext) {
                if ($otext['source'] == $dtext['source'] && $dtext['lang'] == $code) {
                    $translation = $dtext['text'];
                }
            }
            $table .= '
				<tr>
					<td>' . $otext['source'] . '</textarea></td>
					<td><textarea rows="2" cols="60" disabled="disabled">' . $otext['text'] . '</textarea></td>
					<td><textarea name="data[' . $code . '.' . $otext['source'] . ']" rows="2" cols="60">' . $translation . '</textarea></td>
				</tr>
			';
        }
    }
    $table .= '</table>';
    $navibars->add_tab_content($table);
    return $navibars->generate();
}
示例#4
0
function block_group_form($item)
{
    global $DB;
    global $website;
    global $layout;
    global $theme;
    global $current_version;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item->id)) {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(506, 'Groups') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(506, 'Groups') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    if (empty($item->id)) {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"><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(0);"><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_group_delete&id=' . $item->id . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
    }
    $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>', '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_types_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/brick_edit.png"> ' . t(167, 'Types') . '</a>'));
    if (!empty($item->id)) {
        $notes = grid_notes::comments('block_group', $item->id);
        $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_display_notes_dialog();"><span class="navigate_grid_notes_span" style=" width: 20px; line-height: 16px; ">' . count($notes) . '</span><img src="img/skins/badge.png" width="20px" height="18px" style="margin-top: -2px;" class="grid_note_edit" align="absmiddle" /> ' . t(168, 'Notes') . '</a>'));
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_group_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_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>'));
    $navibars->form();
    if (!empty($item->id)) {
        $navibars->add_tab(t(23, "Blocks"));
        $allowed_types = array();
        if (!empty($item->code)) {
            for ($bg = 0; $bg < count($theme->block_groups); $bg++) {
                if ($theme->block_groups[$bg]->id == $item->code) {
                    if (isset($theme->block_groups[$bg]->allowed_types)) {
                        $allowed_types = $theme->block_groups[$bg]->allowed_types;
                    }
                    break;
                }
            }
        }
        $blocks_selected = array();
        if (!is_array($item->blocks)) {
            $item->blocks = array();
        }
        $navibars->add_tab_content($naviforms->hidden('blocks_group_selection', json_encode($item->blocks)));
        $navibars->add_tab_content($naviforms->hidden('blocks-order', ""));
        $block_types = block::types();
        $lang = $website->languages_published[0];
        $extensions_blocks = extension::blocks();
        for ($p = 0; $p < count($item->blocks); $p++) {
            unset($block);
            switch ($item->blocks[$p]['type']) {
                case "block":
                    $block = new block();
                    $block->load($item->blocks[$p]['id']);
                    if (empty($block) || empty($block->type)) {
                        continue;
                    }
                    $blocks_selected[] = '
                        <div class="block_group_block ui-state-default" data-block-id="' . $block->id . '" data-block-type="block" data-block-uid="' . $item->blocks[$p]['uid'] . '">
                            <div class="actions">
                                <a href="?fid=blocks&act=edit&id=' . $block->id . '"><img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" /></a>
                                <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                            </div>
                            <div class="title">' . $block->dictionary[$lang]['title'] . '</div>
                            <div class="subcomment"><span style="float: right;">ID ' . $block->id . '</span><img src="img/icons/silk/brick.png" /> ' . $theme->t($block->type) . '</div>
                        </div>
                    ';
                    break;
                case "block_type":
                    for ($bt = 0; $bt < count($block_types); $bt++) {
                        if ($block_types[$bt]['id'] == $item->blocks[$p]['id']) {
                            $block = $block_types[$bt];
                            break;
                        }
                    }
                    $blocks_selected[] = '
                        <div class="block_group_block ui-state-default" data-block-id="' . $block['code'] . '" data-block-type="block_type" data-block-uid="' . $item->blocks[$p]['uid'] . '">
                            <div class="actions">
                                <a href="#" data-block-group="' . $block['block_group'] . '" data-block-type-code="' . $block['code'] . '" data-block-type-title="(span)" onclick="navigate_blocks_block_type_title(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/text_horizontalrule.png" /><span class="hidden">' . $item->blocks[$p]['title'] . '</span></a>
                                <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                            </div>
                            <div class="title" title="' . $block['description'] . '">' . $block['title'] . '</div>
                            <div class="subcomment">
                                <span style="float: right;">ID ' . $block['code'] . '</span>
                                <img src="img/icons/silk/brick_link.png" /> ' . $block['count'] . ' ' . ($block['count'] == 1 ? t(437, "Block") : t(23, "Blocks")) . '
                            </div>
                        </div>
                    ';
                    break;
                case "block_group_block":
                    if (is_array($theme->block_groups)) {
                        foreach ($theme->block_groups as $key => $bg) {
                            for ($i = 0; $i < count($bg->blocks); $i++) {
                                if ($bg->blocks[$i]->id == $item->blocks[$p]['id']) {
                                    $block = array('code' => $bg->blocks[$i]->id, 'type' => $bg->blocks[$i]->id, 'title' => $theme->t($bg->blocks[$i]->title), 'description' => $theme->t($bg->blocks[$i]->description), 'properties' => $bg->blocks[$i]->properties, 'block_group' => $bg->id);
                                    break;
                                }
                            }
                        }
                    }
                    $blocks_selected[] = '
                        <div class="block_group_block ui-state-default" data-block-id="' . $block['code'] . '" data-block-type="block_group_block"  data-block-uid="' . $item->blocks[$p]['uid'] . '">
                            <div class="actions">
                                ' . (empty($block['properties']) ? '' : '<a href="#" data-block-group="' . $block['block_group'] . '" data-block-group-block="' . $block['code'] . '" data-block-group-action="settings" onclick="navigate_blocks_group_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . '
                                <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                            </div>
                            <div class="title" title="' . $block['description'] . '">' . $block['title'] . '</div>
                            <div class="subcomment"><span style="float: right;">ID ' . $block['type'] . '</span><img src="img/icons/silk/bricks.png" /> ' . $theme->t($block['type']) . '</div>
                        </div>
                    ';
                    break;
                case "extension":
                    $block = $item->blocks[$p];
                    for ($be = 0; $be < count($extensions_blocks); $be++) {
                        if ($block['id'] == $extensions_blocks[$be]->id) {
                            $extension = new extension();
                            $extension->load($block['extension']);
                            $blocks_selected[] = '
                                <div class="block_group_block ui-state-default" data-block-id="' . $block['id'] . '" data-block-type="extension" data-block-extension="' . $block['extension'] . '"  data-block-uid="' . $item->blocks[$p]['uid'] . '">
                                    <div class="actions">
                                        ' . (empty($extensions_blocks[$be]->properties) ? '' : '<a href="#" data-block-group="' . $item->code . '" data-block-id="' . $block['id'] . '" data-block-extension="' . $block['extension'] . '" data-block-group-action="settings" onclick="navigate_block_group_extension_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . '
                                        <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                                    </div>
                                    <div class="title">' . $extension->t($extensions_blocks[$be]->title) . '</div>
                                    <div class="subcomment"><span style="float: right;">ID ' . $block['id'] . '</span><img src="img/icons/silk/plugin.png" /> ' . $extension->title . '</div>
                                </div>
                            ';
                            break;
                        }
                    }
                    break;
            }
        }
        $blocks_selected = implode("\n", $blocks_selected);
        $navibars->add_tab_content('<div id="block_group_selected_blocks" style="width: 49%; float: left; margin-right: 2%;">
                <div class="ui-accordion ui-widget ui-helper-reset">
                    <h3 class="ui-accordion-header ui-state-default ui-accordion-icons ui-accordion-header-active ui-state-active ui-corner-top">
                        <img src="img/icons/silk/bricks.png" style="vertical-align: middle;" /> ' . t(405, 'Selection') . '
                    </h3>
                    <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">' . $blocks_selected . '</div>
                </div>
                <div class="subcomment">
                    <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, "Drag any row to assign priorities") . '
                </div>
             </div>');
        // **** ADD specific BLOCKS ****
        $sql = '
             SELECT b.type, b.id, d.text as title
               FROM nv_blocks b
          LEFT JOIN nv_webdictionary d
                     ON b.id = d.node_id
                    AND d.node_type = "block"
                    AND d.subtype = "title"
                    AND d.lang = "' . $website->languages_list[0] . '"
                    AND d.website = ' . $website->id . '
              WHERE b.website = ' . $website->id . '
           ORDER BY b.id DESC';
        $DB->query($sql);
        $block_elements = $DB->result();
        $block_group_blocks = array();
        for ($bg = 0; $bg < count($theme->block_groups); $bg++) {
            if ($theme->block_groups[$bg]->id == $item->code) {
                $block_group_blocks = $theme->block_groups[$bg]->blocks;
            }
        }
        // blocks available in the accordion
        $navibars->add_tab_content('<div id="blocks_available_wrapper" style="float: left; width: 49%; ">
                <div id="blocks_available_accordion">
                    <h3><i class="fa fa-fw fa-cube"></i> ' . t(437, 'Block') . '</h3>
                    <div>
                    ' . implode("\n", array_map(function ($b) use($allowed_types) {
            global $theme;
            $classes = 'block_group_block ui-state-default';
            if (!empty($allowed_types) && !in_array($b->type, $allowed_types)) {
                $classes .= ' ui-state-disabled hidden';
            }
            $html = '<div class="' . $classes . '" data-block-id="' . $b->id . '" data-block-type="block">' . '<div class="actions">
                                                <a href="?fid=blocks&act=edit&id=' . $b->id . '"><img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" /></a>
                                                <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                                            </div>' . '<div class="title">' . $b->title . '</div>' . '<div class="subcomment"><span style="float: right;">ID ' . $b->id . '</span><img src="img/icons/silk/brick.png" /> ' . $theme->t($b->type) . '</div>' . '</div>';
            return $html;
        }, $block_elements)) . '
                        <div class="navigate-block_group-accordion-info-link hidden"><i class="fa fa-eye-slash"></i>&nbsp;&nbsp;<a href="#">' . t(646, "Show all unselectable blocks") . '</a></div>
                    </div>
                    <h3><i class="fa fa-fw fa-cubes"></i> ' . t(543, 'Block type') . '</h3>
                    <div>
                    ' . implode("\n", array_map(function ($b) use($allowed_types) {
            $classes = 'block_group_block ui-state-default';
            if (!empty($allowed_types) && !in_array($b['id'], $allowed_types)) {
                $classes .= ' ui-state-disabled';
            }
            $html = '<div class="' . $classes . '" data-block-id="' . $b['id'] . '" data-block-type="block_type">' . '<div class="actions">
                                        <a href="#" data-block-group="' . $b['block_group'] . '" data-block-type-code="' . $b['code'] . '" data-block-type-title="(span)" onclick="navigate_blocks_block_type_title(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/text_horizontalrule.png" /><span class="hidden">' . $b['block_type_title'] . '</span></a>
                                        <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                                    </div>' . '<div class="title">' . $b['title'] . '</div>' . '<div class="subcomment">
                                        <span style="float: right;">' . $b['count'] . ' ' . ($b['count'] == 1 ? t(437, "Block") : t(23, "Blocks")) . '</span>
                                        <img src="img/icons/silk/brick_link.png" /> ID ' . $b['id'] . '</div>' . '</div>';
            return $html;
        }, $block_types)) . '
                    </div>
                    <h3><i class="fa fa-fw fa-plus-square-o"></i> ' . t(556, 'Block from group') . ' [' . $theme->t($item->code) . ']</h3>
                    <div>                    
                        ' . implode("\n", array_map(function ($b) use($item) {
            global $theme;
            $html = '<div class="block_group_block ui-state-default" data-block-id="' . $b->id . '" data-block-type="block_group_block" title="' . $theme->t(@$b->description) . '">' . '<div class="actions">
                                                    ' . (empty($b->properties) ? '' : '<a href="#" data-block-group="' . $item->code . '" data-block-group-block="' . $b->id . '" data-block-group-action="settings" onclick="navigate_blocks_group_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . '
                                                    <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                                                </div>' . '<div class="title">' . $theme->t($b->title) . '</div>' . '<div class="subcomment">
                                                    <span style="float: right;">ID ' . $b->id . '</span>
                                                    <img src="img/icons/silk/bricks.png" />' . '</div>' . '</div>';
            return $html;
        }, $block_group_blocks)) . '
                    </div>
                    <h3><i class="fa fa-fw fa-puzzle-piece"></i> ' . t(327, 'Extensions') . '</h3>
                    <div>
                        ' . implode("\n", array_map(function ($b) use($allowed_types, $item) {
            $classes = 'block_group_block ui-state-default';
            $extension = new extension();
            $extension->load($b->_extension);
            $html = '<div class="' . $classes . '" data-block-id="' . $b->id . '" data-block-type="extension" data-block-extension="' . $b->_extension . '">' . '<div class="actions">
                                            ' . (empty($b->properties) ? '' : '<a href="#" data-block-group="' . $item->code . '" data-block-group-block="' . $b->id . '" data-block-group-action="settings" onclick="navigate_block_group_extension_block_settings(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cog.png" /></a>') . '
                                            <a href="#" onclick="navigate_blocks_selection_remove(this);"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" /></a>
                                        </div>' . '<div class="title">' . $extension->t($b->title) . '</div>' . '<div class="subcomment"><span style="float: right;">ID ' . $b->id . '</span><img src="img/icons/silk/plugin.png" /> ' . $extension->title . '</div>' . '</div>';
            return $html;
        }, $extensions_blocks)) . '
                    </div>
                </div>
                <div class="subcomment">
                    <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(638, "Disabled blocks are not compatible with the current block group type") . '
                </div>
            </div>');
        $block_group_block_types_form = "";
        foreach ($website->languages_list as $lang) {
            $block_group_block_types_form .= ' 
                <div data-lang="' . $lang . '" class="navigate-form-row">
                    <label style="width: 48px; "><span title="' . language::name_by_code($lang) . '" class="navigate-form-row-language-info"><img align="absmiddle" src="img/icons/silk/comment.png">' . $lang . '</span></label>
                    <input type="text" style=" width: 340px;" name="block_type_title_value[' . $lang . ']" value="">
                </div>
            ';
        }
        $navibars->add_tab_content('
            <div id="navigate-block-groups-block-type-title" class="hidden">
                ' . $block_group_block_types_form . '
                <div class="subcomment" style="margin-left: 0;"><img src="img/icons/silk/information.png" /> ' . t(641, "It will only be shown if the template supports it") . '</div>
            </div>
        ');
        $layout->add_script('                       
            function navigate_blocks_block_type_title(el)
            {
                var title = $(el).find("span").text();
                
                try 
                {
                   title = jQuery.parseJSON(title);
                } 
                catch(e) 
                {
                    // not json; do nothing                    
                }                    
                
                $("#navigate-block-groups-block-type-title").find("input[type=text]").each(function()
                {                     
                    if(typeof(title)=="object")
                        $(this).val(title[$(this).parent().data("lang")]);
                    else
                        $(this).val(title);
                });
                
                $("#navigate-block-groups-block-type-title").removeClass("hidden");
                $("#navigate-block-groups-block-type-title").dialog({
                    title: navigate_t(67, "Title"),
                    modal: true,
                    width: 428,
                    buttons: [
                        {
                            text: navigate_t(190, "Ok"),
                            icons: {
                                primary: "ui-icon-check"
                            },
                            click: function()
                            {
                                var new_value = {};
                                
                                $("#navigate-block-groups-block-type-title")
                                    .find(\'input[type="text"]\').each(
                                        function()
                                        {
                                            new_value[$(this).parent().data("lang")] = $(this).val(); 
                                        }
                                    );
                                
                                $(el).find("span").text(JSON.stringify(new_value));
                                                            
                                blocks_selection_update();
                                
                                $( this ).dialog( "close" );
                            }
                        },
                        {
                            text: navigate_t(58, "Cancel"),
                            icons: {
                                primary: "ui-icon-close"
                            },
                            click: function()
                            {
                                $( this ).dialog( "close" );
                            }
                        }
                    ]
                });
            }
        ');
    }
    $navibars->add_tab(t(457, "Information"));
    $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)));
    $blgroups = array();
    for ($blg = 0; $blg < count($theme->block_groups); $blg++) {
        $blgroups[$theme->block_groups[$blg]->id] = '';
        if (!empty($theme->block_groups[$blg]->description)) {
            $blgroups[$theme->block_groups[$blg]->id] = $theme->t($theme->block_groups[$blg]->description);
        }
    }
    if (!in_array($item->code, $blgroups)) {
        $blgroups[$item->code] = $item->code;
    }
    $navibars->add_tab_content_row(array('<label>' . t(237, 'Code') . '</label>', $naviforms->selectfield('code', array_keys($blgroups), array_keys($blgroups), $item->code, NULL, NULL, array_values($blgroups), "", true, true)));
    // DEPRECATED field, will be removed. Please use the Notes feature
    if (!empty($item->notes)) {
        $navibars->add_tab_content_row(array('<label>' . t(168, 'Notes') . '</label>', $naviforms->textarea('notes', $item->notes)));
    }
    if (!empty($item->id)) {
        $layout->navigate_notes_dialog('block_group', $item->id);
    }
    $layout->add_script('
        $.getScript("lib/packages/blocks/blocks.js?r=' . $current_version->revision . '", 
            function()
            {
                block_groups_onload();
            });
    ');
    return $navibars->generate();
}
示例#5
0
function items_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $theme;
    global $events;
    global $current_version;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we can use media browser in this function
    $extra_actions = array();
    if (empty($item->id)) {
        $navibars->title(t(22, 'Items') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(22, 'Items') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+M">
				<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($user->permission('items.create') == 'true' ? '<a href="#" onclick="navigate_items_tabform_submit(1);" title="Ctrl+S">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '
				</a>' : ""));
    } else {
        $navibars->add_actions(array($user->permission('items.edit') == 'true' || $item->author == $user->id ? '<a href="#" onclick="navigate_items_tabform_submit(1);" title="Ctrl+S">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '
				</a>' : "", $user->permission("items.delete") == 'true' ? '<a href="#" onclick="navigate_delete_dialog();">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '
				</a>' : ""));
        $extra_actions[] = '<a href="#" onclick="navigate_items_preview();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/monitor.png"> ' . t(274, 'Preview') . '</a>';
        if ($user->permission("items.create") != 'false') {
            $extra_actions[] = '<a href="?fid=items&act=duplicate&id=' . $item->id . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/page_copy.png"> ' . t(477, 'Duplicate') . '</a>';
        }
        $layout->add_script('
            function navigate_delete_dialog()
            {
                navigate_confirmation_dialog(
                    function() { window.location.href = "?fid=items&act=delete&id=' . $item->id . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
    }
    if (!empty($item->id)) {
        $notes = grid_notes::comments('item', $item->id);
        $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_display_notes_dialog();">
					<span class="navigate_grid_notes_span" style=" width: 20px; line-height: 16px; ">' . count($notes) . '</span>
					<img src="img/skins/badge.png" width="20px" height="18px" style="margin-top: -2px;" class="grid_note_edit" align="absmiddle" /> ' . t(168, 'Notes') . '
				</a>'));
    }
    if (!empty($item->id)) {
        // we attach an event to "items" which will be fired by navibars to put an extra button
        $events->add_actions('items', array('item' => &$item, 'navibars' => &$navibars), $extra_actions);
    }
    if (!empty($item->id)) {
        $layout->navigate_notes_dialog('item', $item->id);
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=items&act=edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=items&act=list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form'));
    // languages
    $ws_languages = $website->languages();
    $navibars->form('', 'fid=items&act=edit&id=' . $item->id);
    $layout->add_script("\r\n        \$(document).on('keydown.ctrl_s', function (evt) { navigate_items_tabform_submit(1); return false; } );\r\n        \$(document).on('keydown.ctrl_m', function (evt) { navigate_media_browser(); return false; } );\r\n    ");
    $layout->add_script('
		var template_sections = [];	
	');
    $navibars->add_tab(t(43, "Main"));
    // tab #0
    $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>'));
    if (empty($item->id)) {
        $item->date_to_display = core_time();
    }
    $navibars->add_tab_content_row(array('<label>' . t(551, 'Date to display') . '</label>', $naviforms->datefield('date_to_display', $item->date_to_display, true)));
    $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 . ');
    ');
    $permission_options = array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden'));
    if ($user->permission("items.publish") == 'false') {
        if (!isset($item->permission)) {
            $item->permission = 1;
        }
        $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $permission_options[$item->permission], $naviforms->hidden("permission", $item->permission)));
    } else {
        $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array_keys($permission_options), array_values($permission_options), $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'))), '<span id="status_info" class="ui-icon ui-icon-alert"
                       data-message="' . t(618, 'Change the status to Published to see the item on the future publication date currently assigned', false, true) . '"
					   style="display: none; float: none; vertical-align: middle; "></span>'));
    }
    if (empty($item->id)) {
        $item->author = $user->id;
    }
    $author_webuser = $DB->query_single('username', 'nv_users', ' id = ' . $item->author);
    $navibars->add_tab_content($naviforms->hidden('item-author', $item->author));
    $navibars->add_tab_content_row(array('<label>' . t(266, 'Author') . '</label>', $naviforms->textfield('item-author-text', $author_webuser)));
    // script#1
    if ($item->date_modified > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(227, 'Date modified') . '</label>', core_ts2date($item->date_modified, true)));
    }
    if ($item->date_created > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(226, 'Date created') . '</label>', core_ts2date($item->date_created, true)));
    }
    $navibars->add_tab_content_row(array('<label>' . t(280, 'Page views') . '</label>', $item->views), "div_page_views");
    $navibars->add_tab(t(87, "Association"));
    // tab #1
    $navibars->add_tab_content_row(array('<label>' . t(87, "Association") . '</label>', $naviforms->buttonset('association', array('free' => t(100, 'Free'), 'category' => t(78, 'Category')), empty($item->id) ? 'category' : $item->association, "navigate_change_association(this);")));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->category);
    if (empty($categories_list)) {
        $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>';
    }
    $navibars->add_tab_content_row(array('<label>' . t(78, 'Category') . '</label>', $naviforms->dropdown_tree('category', $categories_list, $item->category, 'navigate_item_category_change')), 'div_category_tree');
    $layout->add_script('
        function navigate_item_category_change(id)
        {
            $.ajax(
            {
                url: NAVIGATE_APP + "?fid=" + navigate_query_parameter("fid") + "&act=96&id=" + id,
                dataType: "json",
                data: {},
                success: function(data, textStatus, xhr)
                {
                    item_category_path = data;
                }
            });
        }
    ');
    $navibars->add_tab_content_row(array('<label>' . t(162, 'Embedding') . '</label>', $naviforms->buttonset('embedding', array('1' => t(163, 'Embedded'), '0' => t(164, 'Own path')), empty($item->id) ? '1' : intval($item->embedding), "navigate_change_association();"), '<span id="embedding_info" class="ui-icon ui-icon-info"
			        data-message-title-1="' . t(163, 'Embedded', false, true) . '"
					data-message-content-1="' . t(165, 'Full content is shown on category page. Ex. "Who we are?"', false, true) . '"
					data-message-title-2="' . t(164, 'Own path', false, true) . '"
					data-message-content-2="' . t(166, 'The content is accessed through its own url. Ex. "News"', false, true) . '" 
					style="float: left; margin-left: -4px;">
			</span>'), 'div_category_embedded');
    $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . '</label>', '<button style="float: left;">' . t(171, 'Order') . '</button>', '<span id="order_info" class="ui-icon ui-icon-info"
 				   data-message="' . t(425, 'Order elements of a category (unless the template forces other sorting)', false, true) . '"
				   style="float: left; margin-left: 2px;">				   
			</span>', '<div id="items_order_window" style="display: none;"></div>'), 'div_category_order');
    $layout->add_script('
	    $("#div_category_order button").button(
	    {
	        icons:
	        {
                primary: "ui-icon-arrowthick-2-n-s"
            }
	    }).on("click", function(e)
	    {
	        e.stopPropagation();
	        e.preventDefault();
	        navigate_status(navigate_t(6, "Loading") + "...", "loader");

	        $("#items_order_window").load("?fid=items&act=items_order&category=" + $("#category").val() + "&_bogus=" + new Date().getTime(), function()
	        {
	            navigate_status(navigate_t(42, "Ready"), "ready");
                $("#items_order_window").dialog({
                    modal: true,
                    title: "' . t(171, 'Order') . '",
                    width: 600,
                    height: 500,
                    buttons:
                    {
                        "' . t(58, 'Cancel') . '": function()
                        {
                            $(this).dialog("destroy");
                        },
                        "' . t(190, 'Ok') . '": function()
                        {
                            var dialog = this;
                            // save
                            $.post(
                                "?fid=items&act=items_order&category=" + $("#category").val() + "&_bogus=" + new Date().getTime(),
                                {
                                    "items-order": $("#items-order").val()
                                },
                                function(response)
                                {
                                    if(response=="true")
                                    {
                                        $(dialog).dialog("destroy");
                                    }
                                    else
                                    {
                                        $("<div>"+response+"</div>").dialog({
                                            modal: true,
                                            title: "' . t(56, "Unexpected error") . '"
                                        });
                                    }
                                }
                            );
                        }
                    }
                });
            });
	    });
	');
    $templates = template::elements('element');
    $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, '<span id="template_info" class="ui-icon ui-icon-alert"
 				   data-message="' . t(619, "Template changed, please Save now to see the changes in the next tabs", false, true) . '"
				   style="display: none; float: none; vertical-align: middle; "></span>'), 'div_template_select');
    $layout->add_script('
		var last_check = [];
		var active_languages = ["' . implode('", "', array_keys($ws_languages)) . '"];
		$("#div_template_select").hide();
	');
    // script#3
    if (!empty($item->id)) {
        $navibars->add_tab(t(9, "Content"));
        // tab #2
        $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $ws_languages, $website->languages_list[0], "navigate_items_select_language(this);")));
        $template = $item->load_template();
        $translate_extensions = extension::list_installed('translate', false);
        foreach ($website->languages_list as $lang) {
            $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; ">');
            $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title'])));
            $open_live_site = '';
            if (!empty($item->paths[$lang])) {
                $open_live_site = ' <a target="_blank" href="' . $website->absolute_path(true) . $item->paths[$lang] . '"><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, @$item->paths[$lang], NULL, 'navigate_items_path_check(this, event);'), '<span>&nbsp;</span>'), 'div_path_' . $lang);
            if (!isset($template->sections)) {
                $template->sections[] = array(0 => array('id' => 'main', 'name' => '#main#', 'editor' => 'tinymce', 'width' => '960px'));
            }
            if (!is_array($template->sections)) {
                $template->sections = array();
            }
            // compatibility fix: auto-correct template sections with missing ID (only "code" provided)
            for ($s = 0; $s < count($template->sections); $s++) {
                if (!isset($template->sections[$s]['id'])) {
                    $template->sections[$s]['id'] = $template->sections[$s]['code'];
                }
            }
            foreach ($template->sections as $section) {
                if (is_object($section)) {
                    $section = (array) $section;
                }
                // ignore empty sections
                if (empty($section)) {
                    continue;
                }
                if ($section['editor'] == 'tinymce') {
                    $translate_menu = '';
                    if (!empty($translate_extensions)) {
                        $translate_extensions_titles = array();
                        $translate_extensions_actions = array();
                        foreach ($translate_extensions as $te) {
                            if ($te['enabled'] == '0') {
                                continue;
                            }
                            $translate_extensions_titles[] = $te['title'];
                            $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $lang . '\');';
                        }
                        if (!empty($translate_extensions_actions)) {
                            $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                        }
                    }
                    $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '<span class="editor_selector" for="section-' . $section['id'] . '-' . $lang . '">' . '<i class="fa fa-border fa-fw fa-lg fa-file-text-o active" data-action="tinymce" title="' . t(614, "Edit with TinyMCE") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-code" data-action="html" title="' . t(615, "Edit as source code") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-eraser" data-action="clear" title="' . t(208, "Remove all content") . '"></i>' . '</span>' . '</label>', $naviforms->editorfield('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], $section['width'] + 48 . 'px', $lang), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label>&nbsp;</label>', $translate_menu, '<button onclick="navigate_items_copy_from_dialog(\'section-' . $section['id'] . '-' . $lang . '\'); return false;"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"> ' . t(189, 'Copy from') . '...</button> ', '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"');
                } else {
                    if ($section['editor'] == 'html') {
                        $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '</label>', $naviforms->scriptarea('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], 'html', ' width: ' . $section['width'] . 'px'), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label>&nbsp;</label>', '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"');
                    } else {
                        $translate_menu = '';
                        if (!empty($translate_extensions)) {
                            $translate_extensions_titles = array();
                            $translate_extensions_actions = array();
                            foreach ($translate_extensions as $te) {
                                if ($te['enabled'] == '0') {
                                    continue;
                                }
                                $translate_extensions_titles[] = $te['title'];
                                $translate_extensions_actions[] = 'javascript: navigate_textarea_translate_' . $te['code'] . '(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $lang . '\');';
                            }
                            if (!empty($translate_extensions_actions)) {
                                $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                            }
                        }
                        $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '</label>', $naviforms->textarea('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], 8, 48, ' width: ' . $section['width'] . 'px'), '<div style="clear:both; margin-top:5px; margin-bottom: 10px; ">', '<label>&nbsp;</label>', $translate_menu, '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>'), '', 'lang="' . $lang . '"');
                    }
                }
            }
            if ($template->tags == 1 || $template->tags == 'true') {
                $tags_copy_select = '';
                $tags_copy_select_pre = '';
                $tags_copy_select_after = '';
                // allow copying tags between languages?
                if (count($website->languages_list) > 1) {
                    $tags_copy_select = $naviforms->selectfield('', array_keys($ws_languages), array_values($ws_languages), '', '', false, '', ' width: auto; position: absolute; margin-top: 1px; ', false);
                    $tags_copy_select = '
						<div style=" position: relative; margin-left: 600px; margin-top: -57px; width: 200px; height: 68px; ">
							<a href="#" class="uibutton" title="' . t(189, "Copy from") . '…"
							   onclick=" navigate_items_tags_copy_from_language($(this).next().val(), \'' . $lang . '\'); return false; ">
								<img src="img/icons/silk/page_white_copy.png" width="16" height="16" align="absmiddle" style=" cursor: pointer; " />
							</a>&nbsp;' . $tags_copy_select . '
						</div>
					';
                }
                $tags_top_list = '
					<div style=" position: relative; margin-left: 600px; margin-top: -93px; width: 200px; height: 92px; ">
						<a href="#" class="uibutton" onclick=" navigate_items_tags_ranking(\'' . $lang . '\', this); return false; ">
							<img src="img/icons/silk/award_star_gold_3.png" width="16" height="16" align="absmiddle" style=" cursor: pointer; " />
							' . t(613, "Most used") . '
						</a>
					</div>
				';
                $navibars->add_tab_content_row(array('<label>' . t(265, 'Tags') . '</label>', $naviforms->textfield('tags-' . $lang, @$item->dictionary[$lang]['tags']), $tags_top_list, $tags_copy_select));
            }
            $layout->add_script('			                
                $("#tags-' . $lang . '").tagit({
                    removeConfirmation: true,
                    allowSpaces: true,
                    singleField: true,
                    singleFieldDelimiter: ",",
                    placeholderText: "+",
                    autocomplete: 
                    {
                        delay: 0, 
                        minLength: 1,
                        source: "?fid=items&act=json_tags_search&lang=' . $lang . '"
                    },
                    afterTagAdded: function(event, ui)
                    {
                        var tags = $(this).tagit("assignedTags");
                        if(tags.length > 0)
                            tags = tags.join(",");
                        else
                            tags = "";
                            
                        $("#tags-' . $lang . '")
                            .val(tags)
                            .trigger("change");
                    },
                    afterTagRemoved: function(event, ui)
                    {                    
                        var tags = $(this).tagit("assignedTags");
                        if(tags.length > 0)
                            tags = tags.join(",");
                        else
                            tags = "";
                            
                        $("#tags-' . $lang . '")
                            .val(tags)
                            .trigger("change");
                    }
                });
                
                $("#tags-' . $lang . '").next().sortable({
                    items: ">li:not(.tagit-new)",
                    update: function(ui, event)
                    {
                        var tags = [];
                        
                        $("#tags-' . $lang . '").next().find("span.tagit-label").each(function()
                        {
                            if($(this).text() != "")
                                tags.push($(this).text());
                        });
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";
                                                    
                        $("#tags-' . $lang . '").val(tags);
                        $("#tags-' . $lang . '").trigger("change");                                                
                    }
                });                
			');
            // script#4
            $navibars->add_tab_content('</div>');
        }
        // translate content_samples titles
        if (is_array($theme->content_samples)) {
            for ($i = 0; $i < count($theme->content_samples); $i++) {
                $theme->content_samples[$i]->title = $theme->t($theme->content_samples[$i]->title);
            }
        }
        $layout->add_script('
			var template_sections = ' . json_encode($template->sections) . ';
		    var theme_content_samples = ' . json_encode($theme->content_samples) . ';
		    var website_theme = "' . $website->theme . '";
		');
        $category = new structure();
        $category->paths = array();
        if (!empty($item->category)) {
            $category->load($item->category);
        }
        $layout->add_script('
			var item_category_path = ' . json_encode($category->paths) . ';
			var item_id = "' . $item->id . '";
		');
        // script#5
        // select the first language of the website as the default origin when copying content
        $default_language = array_keys($ws_languages);
        $default_language = $default_language[0];
        $layout->add_content('
			<div id="navigate_items_copy_from" style=" display: none; ">
				<div class="navigate-form-row">
					<label>' . t(191, 'Source') . '</label>
					' . $naviforms->buttonset('navigate_items_copy_from_type', array('language' => t(46, 'Language'), 'item' => t(180, 'Item')), '0', "navigate_items_copy_from_change_origin(this);") . '
				</div>
				<div class="navigate-form-row" style=" display: none; ">
					<label>' . t(46, 'Language') . '</label>
					' . $naviforms->selectfield('navigate_items_copy_from_language_selector', array_keys($ws_languages), array_values($ws_languages), $default_language) . '
				</div>
				<div class="navigate-form-row" style=" display: none; ">
					<label>' . t(79, 'Template') . '</label>
					' . $naviforms->select_from_object_array('navigate_items_copy_from_template', $templates, 'id', 'title', '', '') . '
				</div>			
				<div class="navigate-form-row" style=" display: none; ">		
					<label>' . t(67, 'Title') . '</label>			
					' . $naviforms->textfield('navigate_items_copy_from_title') . '
					' . $naviforms->hidden('navigate_items_copy_from_item_id', '') . '
				</div>
				<div class="navigate-form-row" style=" display: none; ">
					<label>' . t(239, 'Section') . '</label>
					' . $naviforms->select_from_object_array('navigate_items_copy_from_section', array(), 'id', 'name', '') . '
				</div>			
			</div>
			
			<div id="navigate_items_copy_from_history" style=" display: none; ">
				<div class="navigate-form-row">
					<label>' . t(196, 'Date & time') . '</label>
					<select id="navigate_items_copy_from_history_options" 
							name="navigate_items_copy_from_history_options" 
							onchange="navigate_items_copy_from_history_preview(this.value, $(this).attr(\'type\'));">
					</select>
					<a href="#" onclick="navigate_items_copy_from_history_remove();"><img src="img/icons/silk/cancel.png" align="absmiddle"></a>
				</div>			
				<div class="navigate-form-row">
					<!--<div id="navigate_items_copy_from_history_text"
						 name="navigate_items_copy_from_history_text"
						 style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;">
					</div>
					-->
					<textarea style="display: none;" id="navigate_items_copy_from_history_stylesheets">' . $website->content_stylesheets('link_tag') . '</textarea>
					<iframe id="navigate_items_copy_from_history_text"
						 name="navigate_items_copy_from_history_text"
						 src="about:blank"
						 style="border: 1px solid #CCCCCC; float: left; height: 300px; min-height: 20px; overflow: auto; width: 97%; padding: 3px; ">
					</iframe>
					<div id="navigate_items_copy_from_history_text_raw" style=" display: none; "></div>
				</div>			
			</div>

			<div id="navigate_items_copy_from_theme_samples" style=" display: none; ">
				<div class="navigate-form-row">
					<label>' . t(79, 'Template') . '</label>
					<select id="navigate_items_copy_from_theme_samples_options"
							name="navigate_items_copy_from_theme_samples_options"
							onchange="navigate_items_copy_from_theme_samples_preview(this.value, $(this).attr(\'type\'), $(this).find(\'option:selected\').attr(\'source\'));">
					</select>
				</div>
				<div class="navigate-form-row">
					<div id="navigate_items_copy_from_theme_samples_text"
						 name="navigate_items_copy_from_theme_samples_text"
						 style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;">
					</div>
					<div id="navigate_items_copy_from_theme_samples_text_raw" style=" display: none; "></div>
				</div>
			</div>
		');
        // script will be bound to onload event at the end of this php function (after getScript is done)
        $onload_language = $_REQUEST['tab_language'];
        if (empty($onload_language)) {
            $onload_language = $website->languages_list[0];
        }
        $layout->add_script('
			function navigate_items_onload()
			{
				navigate_items_select_language("' . $onload_language . '");
				navigate_change_association("' . (empty($item->id) ? 'category' : $item->association) . '");
				setTimeout(function()
				{
					$(navigate_codemirror_instances).each(function() { this.refresh(); } );
				}, 500);
			};
		');
        /* IMAGE GALLERIES */
        if ($template->gallery === 'true' || $template->gallery > 0) {
            $navibars->add_tab(t(210, "Gallery"));
            // tab #3
            $access = array(0 => '', 1 => '<img src="img/icons/silk/lock.png" align="absmiddle" title="' . t(361, 'Web users only') . '" />', 2 => '<img src="img/icons/silk/user_gray.png" align="absmiddle" title="' . t(363, 'Users who have not yet signed up or signed in') . '" />', 3 => '<img src="img/icons/silk/group_key.png" align="absmiddle" title="' . t(512, "Selected web user groups") . '" />');
            $permissions = array(0 => '', 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" title="' . t(70, 'Private') . '" />', 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" title="' . t(81, 'Hidden') . '" />');
            if (!is_array($item->galleries[0])) {
                $item->galleries[0] = array();
            }
            $gallery_elements_order = implode('#', array_keys($item->galleries[0]));
            $navibars->add_tab_content($naviforms->hidden('items-gallery-elements-order', $gallery_elements_order));
            $gallery = '<ul id="items-gallery-elements" class="items-gallery">';
            $ids = array_keys($item->galleries[0]);
            //$default_img = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent pixel
            $default_img = 'img/icons/ricebowl/mimetypes/image.png';
            for ($g = 0; $g < count($ids); $g++) {
                $f = new file();
                $f->load($ids[$g]);
                $gallery .= '
				    <li>
                        <div id="items-gallery-item-' . $ids[$g] . '-droppable" class="navigate-droppable ui-corner-all" data-file-id="' . $f->id . '">
                            <div class="file-access-icons">' . $access[$f->access] . $permissions[$f->permission] . '</div>
                            <img title="' . $ids[$g] . '" src="' . $default_img . '" data-src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $ids[$g] . '&amp;disposition=inline&amp;width=75&amp;height=75" width="75" height="75" />
                        </div>
                        <div class="navigate-droppable-cancel" style="display: block;"><img src="img/icons/silk/cancel.png" /></div>
                    </li>
                ';
            }
            // empty element
            $gallery .= '
                <li class="gallery-item-empty-droppable">
                    <div id="items-gallery-item-empty-droppable" class="navigate-droppable ui-corner-all">
                        <img src="img/icons/misc/dropbox.png" vspace="18" />
                    </div>
                </li>
            ';
            $gallery .= '</ul>';
            // now the image captions
            foreach ($item->galleries[0] as $image_id => $image_dictionary) {
                if (!is_array($image_dictionary)) {
                    $image_dictionary = array();
                }
                foreach ($website->languages_list as $lang) {
                    $gallery .= $naviforms->hidden('items-gallery-item-' . $image_id . '-dictionary-' . $lang, $image_dictionary[$lang]);
                }
            }
            $navibars->add_tab_content_row(array('<label>' . t(210, 'Gallery') . '</label>', '<div>' . $gallery . '</div>'));
            $layout->add_content('
				<ul id="contextmenu-gallery-items" style="display: none" class="ui-corner-all">
	                <li id="contextmenu-gallery-items-properties"><a href="#"><span class="ui-icon ui-icon-contact"></span>' . t(213, "Image caption") . '</a></li>
	                <li id="contextmenu-gallery-items-permissions"><a href="#"><span class="ui-icon ui-icon-key"></span>' . t(17, "Permissions") . '</a></li>
	                <li id="contextmenu-gallery-items-focalpoint"><a href="#"><span class="ui-icon ui-icon-image"></span>' . t(540, "Focal point") . '</a></li>
	                <li id="contextmenu-gallery-items-description"><a href="#"><span class="ui-icon ui-icon-comment"></span>' . t(334, 'Description') . '</a></li>
	                <li><!--divider--></li>
	                <li id="contextmenu-gallery-items-remove"><a href="#"><span class="ui-icon ui-icon-minus"></span>' . t(627, 'Remove') . '</a></li>
	                <li id="contextmenu-gallery-items-move-beginning"><a href="#"><span class="ui-icon ui-icon-arrowthickstop-1-n"></span>' . t(628, 'Move to the beginning') . '</a></li>
	                <li id="contextmenu-gallery-items-move-end"><a href="#"><span class="ui-icon ui-icon-arrowthickstop-1-s"></span>' . t(629, 'Move to the end') . '</a></li>
	            </ul>
			');
            // script#6
            $layout->add_script('
				$(window).on("load", function()
				{
					new LazyLoad({
					    threshold: 200,
					    container: $("#items-gallery-elements-order").parent()[0],
					    elements_selector: "#items-gallery-elements img",
					    throttle: 40,
					    data_src: "src",
					    show_while_loading: true
					});
				});
			');
            $captions_form = '
				<div id="navigate_items_gallery_captions_form" style=" display: none; ">
					<div class="navigate-form-row">
						<label>' . t(157, 'Image') . '</label>
						' . $naviforms->dropbox('navigate_items_gallery_captions_form_image', '', 'image', true) . '
					</div>
			';
            $caption_langs = array_values($website->languages_list);
            foreach ($caption_langs as $caption_language) {
                $captions_form .= '
					<div class="navigate-form-row">
						<label>' . language::name_by_code($caption_language) . '</label>
						' . $naviforms->textfield('navigate_items_gallery_captions_form_image_' . $caption_language, '') . '
					</div>
				';
            }
            $captions_form .= '
				</div>
			';
            $layout->add_content($captions_form);
        }
        // Properties TAB (only if needed)
        $properties_html = '';
        if ($item->association == 'free' && !empty($item->template) && $item->template != '0') {
            // we already know the properties to show: template is set on item
            $properties_html = navigate_property_layout_form('item', $item->template, 'item', $item->id);
        } else {
            if ($item->association == 'category' && $item->embedding == 0 && !empty($item->template)) {
                // we already know the properties to show: template is set on item
                $properties_html = navigate_property_layout_form('item', $item->template, 'item', $item->id);
            } else {
                if ($item->association == 'category' && $item->category > 0) {
                    // we have to get the template set in the category of the item
                    $template_id = $DB->query_single('template', 'nv_structure', ' id = ' . protect($item->category) . ' AND website = ' . $website->id);
                    $properties_html = navigate_property_layout_form('item', $template_id, 'item', $item->id);
                }
            }
        }
        if (!empty($properties_html)) {
            $navibars->add_tab(t(77, "Properties"));
            // tab #4
            $navibars->add_tab_content($properties_html);
        }
        if ($template->comments > 0 || $template->comments == 'true' || $template->comments === true || is_object($template->comments)) {
            $navibars->add_tab(t(250, "Comments"));
            // tab #5
            $navibars->add_tab_content_row(array('<label>' . t(252, 'Comments enabled to') . '</label>', $naviforms->selectfield('item-comments_enabled_to', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(253, 'Nobody'), 1 => t(24, 'Registered users'), 2 => t(254, 'Everyone')), $item->comments_enabled_to)));
            $moderator_id = '';
            if (!empty($item->comments_moderator)) {
                $moderator_username = $DB->query_single('username', 'nv_users', ' id = ' . $item->comments_moderator);
                if (!empty($moderator_username)) {
                    $moderator_username = array($moderator_username);
                    $moderator_id = array($item->comments_moderator);
                }
            }
            $navibars->add_tab_content_row(array('<label>' . t(255, 'Moderator') . '</label>', $naviforms->selectfield('item-comments_moderator', $moderator_id, $moderator_username, $item->comments_moderator, null, false, null, null, false), '<span style="display: none;" id="item-comments_moderator-helper">' . t(535, "Find user by name") . '</span>', '<div class="subcomment"><img align="absmiddle" src="' . NAVIGATE_URL . '/img/icons/silk/information.png" /> ' . t(256, 'Leave blank to accept all comments') . '</div>'));
            // script#7
            // comments list
            // removed filter: AND nvwu.website = nvc.website ... reason: the webuser could be from another website if sharing webusers is enabled
            // TODO: retrieve comments by AJAX call to avoid memory issues. right now we just retrieve the first 500 comments
            $DB->query('SELECT nvc.*, nvwu.username, nvwu.avatar
						  FROM nv_comments nvc
						 LEFT OUTER JOIN nv_webusers nvwu 
						 			  ON nvwu.id = nvc.user
						 WHERE nvc.website = ' . protect($website->id) . '
						   AND nvc.item = ' . protect($item->id) . '
						ORDER BY nvc.date_created ASC
						LIMIT 500');
            $comments = $DB->result();
            $comments_total = count($comments);
            for ($c = 0; $c < $comments_total; $c++) {
                if ($comments[$c]->status == 2) {
                    $comment_status = 'hidden';
                } else {
                    if ($comments[$c]->status == 1) {
                        $comment_status = 'private';
                    } else {
                        if ($comments[$c]->status == -1) {
                            $comment_status = 'new';
                        } else {
                            $comment_status = 'public';
                        }
                    }
                }
                $navibars->add_tab_content_row(array('<span class="items-comment-label">' . core_ts2date($comments[$c]->date_created, true) . '<br />' . '<strong>' . (empty($comments[$c]->username) ? $comments[$c]->name : $comments[$c]->username) . '</strong>' . '<br />' . $comments[$c]->ip . '</span>', '<div id="items-comment-' . $comments[$c]->id . '" class="items-comment-message items-comment-status-' . $comment_status . '">' . nl2br($comments[$c]->message) . '</div>', empty($comments[$c]->avatar) ? '' : '<img style=" margin-left: 5px; " src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $comments[$c]->avatar . '&amp;disposition=inline&amp;width=46&amp;height=46" />'));
            }
            $navibars->add_tab_content('
				<div id="items-comments-toolbar">
					<img id="items-comments-toolbar-publish" src="' . NAVIGATE_URL . '/img/icons/silk/accept.png" title="' . t(258, 'Publish') . '" />
					<img id="items-comments-toolbar-unpublish" src="' . NAVIGATE_URL . '/img/icons/silk/delete.png" title="' . t(259, 'Unpublish') . '" />
					<img id="items-comments-toolbar-delete" src="' . NAVIGATE_URL . '/img/icons/silk/decline.png" title="' . t(35, 'Delete') . '" />				
				</div>
			');
            // script#8
            // comments moderation
        }
        if ($item->votes > 0) {
            $navibars->add_tab(t(352, "Votes"));
            // tab #6
            $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").on("click", function()
				{
				    navigate_confirmation_dialog(
				        function()
                        {                         
                            $.post("?fid=items&act=votes_reset&id=' . $item->id . '", function(data)
                            {
                                $("#navigate-panel-web-summary").addClass("ui-state-disabled");
                                navigate_notification("' . t(355, 'Votes reset') . '");
                            });
                        },
                        "' . t(497, "Do you really want to erase this data?") . '",
                        null,
				        "' . t(354, 'Reset') . '"
                    );					    
				});
				
				$("#items_votes_webuser").on("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=" margin: 8px; height: 150px; width: 360px; "></div>'), 'navigate-panel-web-score', '385px', '200px');
            $votes_by_score = webuser_vote::object_votes_by_score('item', $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)]);
            }
            $navibars->add_tab_content('
                <div class="hidden" id="navigate-panel-web-data-score">' . json_encode($gdata) . '</div>
            ');
            $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=" margin: 8px; height: 150px; width: 360px; "></div>'), 'navigate-panel-web-votes', '385px', '200px');
            $votes_by_date = webuser_vote::object_votes_by_date('item', $item->id, 90);
            $navibars->add_tab_content('
                <div class="hidden" id="navigate-panel-web-data-votes_by_date">' . json_encode($votes_by_date) . '</div>
            ');
            // script#9
        }
        $nvweb_preview = NAVIGATE_PARENT . NAVIGATE_FOLDER . '/web/nvweb.php?preview=true&wid=' . $website->id . '&route=';
        $layout->add_script('
			function navigate_items_preview()
			{
				// navigate_items_disable_spellcheck(); not needed in tinymce 4?
				navigate_periodic_event_delegate(); // force saving current data in history
				var url = "' . $nvweb_preview . '";
				var active_language = $("input[name=\'language_selector[]\']:checked").val();

				if($("#template").parent().css("display")=="block")
					url = url + "node/' . $item->id . '&lang=" + active_language + "&template=" + $("#template").val();
			    else // category URL
			        url = url + item_category_path[active_language].slice(1);

				setTimeout(function() { window.open(url); }, 1000);
			}
		');
        $events->trigger('items', 'edit', array('item' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms));
    }
    $layout->add_script('
		$.getScript("lib/packages/items/items.js?r=' . $current_version->revision . '", function()
		{
			if(typeof navigate_items_onload == "function")
				navigate_items_onload();
		});
	');
    return $navibars->generate();
}
示例#6
0
function websites_form($item)
{
    global $user;
    global $DB;
    global $layout;
    global $events;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we want to use media browser in this function
    $layout->navigate_editorfield_link_dialog();
    $theme = new theme();
    if (!empty($item->theme)) {
        $theme->load($item->theme);
    }
    if (empty($item->id)) {
        $navibars->title(t(241, 'Websites') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(241, 'Websites') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    if ($user->permission('websites.edit') == 'true') {
        $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+m">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>'));
        $extra_actions = array();
        $extra_actions[] = '<a href="#" action="navigate_reset_statistics" onclick="javascript: navigate_reset_statistics();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/chart_line.png"> ' . t(429, 'Reset statistics') . '</a>';
        $layout->add_script('
            function navigate_reset_statistics()
            {
                navigate_confirmation_dialog(
                    function()
                    {
                        $.post(
                            "?fid=websites&act=reset_statistics&website=' . $item->id . '",
                            {},
                            function(data)
                            {
                                $("a[action=\'navigate_reset_statistics\']").parent().fadeOut();
                            }
                        );
                    }, 
                    "<div>' . t(430, 'Do you really want to remove all statistics of this website?') . '</div>" 
                );
            }
        ');
        if (!empty($item->id)) {
            $extra_actions[] = '<a href="#" action="navigate_replace_urls" onclick="javascript: navigate_replace_urls();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/database_refresh.png"> ' . t(603, 'Replace URLs') . '</a>';
            // try to find the OLD url for NAVIGATE_DOWNLOAD
            $old_url_guessed = "";
            $DB->query('
				SELECT text
				  FROM nv_webdictionary
				  WHERE node_type = "item"
				    AND website = ' . $item->id . '
				    AND text LIKE ' . protect("%navigate_download.php%") . '
			    LIMIT 1
		    ');
            $rs = $DB->result('text');
            preg_match("/<img .*?(?=src)src=\"([^\"]+)\"/si", $rs[0], $old_url_guessed);
            $old_url_guessed = @$old_url_guessed[1];
            $old_url_guessed = substr($old_url_guessed, 0, strpos($old_url_guessed, NAVIGATE_FOLDER));
            $layout->add_content('
		        <div id="navigate_replace_urls_dialog" style="display: none;">
		            <div id="" class="navigate-form-row">
						<label>' . t(604, "Old") . '</label>
						<input type="text" style=" width: 300px;" id="replace_urls_old" name="replace_urls_old" value="' . $old_url_guessed . '/" />
					</div>
					<div id="" class="navigate-form-row">
						<label>' . t(605, "New") . '</label>
						<input type="text" style=" width: 300px;" id="replace_urls_new" name="replace_urls_new" value="' . NAVIGATE_PARENT . '/" />
					</div>
					<div class="navigate-form-row">
						<div class="subcomment">' . t(523, "This action can NOT be undone.") . '</div>
					</div>
		        </div>
		    ');
            $layout->add_script('
	            function navigate_replace_urls()
	            {
	                $("#navigate_replace_urls_dialog").dialog({
	                        resizable: true,
	                        height: 180,
	                        width: 520,
	                        modal: true,
	                        title: "' . t(603, 'Replace URLs') . '",
	                        buttons: {
	                            "' . t(190, 'Ok') . '": function()
	                            {
	                                $.post(
	                                    "?fid=websites&act=replace_urls",
	                                    {
	                                        old: $("#replace_urls_old").val(),
	                                        new: $("#replace_urls_new").val(),
	                                        website: ' . $item->id . '
	                                    },
	                                    function(data)
	                                    {
	                                        if(data!="true")
					                            navigate_notification("' . t(56, "Unexpected error.") . '");
					                        else
					                        {
					                            navigate_notification("' . t(53, "Data saved successfully") . '", false, "fa fa-check");
	                                            $("#navigate_replace_urls_dialog").dialog("close");
	                                        }
	                                    }
	                                );
	                            },
	                            "' . t(58, 'Cancel') . '": function()
	                            {
	                                $("#navigate_replace_urls_dialog").dialog("close");
	                            }
	                        }
	                });
	            }
	        ');
            $extra_actions[] = '<a href="#" action="navigate_remove_website_data" onclick="javascript: navigate_remove_website_data();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cross.png"> ' . t(208, 'Remove all content') . '</a>';
            $layout->add_script('
            function navigate_remove_website_data()
            {
                var confirmation = "<div>";
                confirmation += "<br /><div><strong>' . t(497, 'Do you really want to erase this data?') . '</strong> (' . t(16, "Structure") . ', ' . t(22, "Elements") . ', ' . t(23, "Blocks") . ', ' . t(250, "Comments") . '...)</div><br />";
                confirmation += "<form action=\\"?\\" onSubmit=\\"return false;\\"><div class=\\"navigate-form-row\\"><label>' . t(2, "Password") . '</label></div><input type=\\"password\\" id=\\"navigate_remove_website_data_password\\" style=\\"width: 90%;\\" /></form></div>";
                confirmation += "</div>";

                $(confirmation).dialog({
                        resizable: true,
                        height: 250,
                        width: 400,
                        modal: true,
                        title: "' . t(59, 'Confirmation') . '",
                        buttons: {
                            "' . t(190, 'Ok') . '": function()
                            {
                                $(this).dialog("close");

                                $.post(
                                    "?fid=websites&act=remove_content",
                                    {
                                        website: $("#id").val(),
                                        password: $("#navigate_remove_website_data_password").val()
                                    },
                                    function(data)
                                    {
                                        if(data=="true")
                                        {
                                            navigate_notification("' . t(419, "Process complete") . '");
                                            $("a[action=\'navigate_remove_website_data\']").parent().fadeOut();
                                        }
                                        else
                                            navigate_notification("' . t(56, "Unexpected error.") . ' " + data, true);
                                    }
                                );
                            },
                            "' . t(58, 'Cancel') . '": function()
                            {
                                $(this).dialog("close");
                            }
                        }
                });
            }
        ');
        }
        // we attach an event to "websites" which will be fired by navibars to put an extra button
        $events->add_actions('websites', array('website' => &$item, 'navibars' => &$navibars), $extra_actions);
        if (empty($item->id)) {
            $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);" title="Ctrl+s">
						<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);" title="Ctrl+s">
						<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', $user->permission('websites.delete') == 'true' ? '<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(35, 'Delete') . '": function() {
                                        $(this).dialog("close");
                                        window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=4&id=' . $item->id . '";
                                    },
                                    "' . t(58, 'Cancel') . '": function() {
                                        $(this).dialog("close");
                                    }
                                }
                            });';
            $delete_html[] = '}';
            $delete_html[] = '</script>';
            $navibars->add_content(implode("\n", $delete_html));
        }
        $layout->add_script("\r\n            \$(document).on('keydown.ctrl_s', function (evt) { navigate_items_tabform_submit(1); return false; } );\r\n            \$(document).on('keydown.ctrl_m', function (evt) { navigate_media_browser(); return false; } );\r\n        ");
    }
    $navibars->add_actions(array($user->permission('websites.edit') == 'true' && !empty($item->id) ? '<a href="?fid=websites&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=websites&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(7, "Settings"));
    $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>' . t(67, 'Title') . '</label>', $naviforms->textfield('title', $item->name)));
    $navibars->add_tab_content_row(array('<label>' . t(287, 'Protocol') . '</label>', $naviforms->selectfield('protocol', array(0 => 'http://', 1 => 'https://'), array(0 => 'HTTP', 1 => 'HTTPS [' . t(288, 'Secured site (requires certificate)') . ']'), $item->protocol)));
    $navibars->add_tab_content_row(array('<label>' . t(228, 'Subdomain') . '</label>', $naviforms->textfield('subdomain', $item->subdomain), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' www</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(229, 'Domain') . '</label>', $naviforms->textfield('domain', $item->domain), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' naviwebs.net</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(141, 'Folder') . '</label>', $naviforms->textfield('folder', $item->folder), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' /new-website</span>'));
    $homepage_url = "";
    if (!empty($item->homepage)) {
        $homepage_url = $item->homepage_from_structure();
    }
    $navibars->add_tab_content_row(array('<label>' . t(187, 'Homepage') . '</label>', $naviforms->hidden('homepage_from_structure', is_numeric($item->homepage) ? $item->homepage : ""), $naviforms->autocomplete('homepage', $homepage_url, '?fid=' . $_REQUEST['fid'] . '&wid=' . $item->id . '&act=5'), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' /en/home</span>'));
    $navibars->add_tab_content_row(array('<div class="subcomment"><img src="img/icons/silk/house.png" align="absmiddle" /> <span id="navigate-website-home-url"></span></div>'));
    $layout->add_content('
		<div id="homepage_change_dialog" style="display: none;">
			' . t(595, "Right now the homepage is set from a structure element which allows multilanguage redirecting.") . '
			<br /><br />
			' . t(596, "Do you want to enter a fixed path for the homepage?") . '
		</div>
	');
    $layout->add_script('
		$("#homepage").on("click keydown", function(ev)
		{
			if($("#homepage_from_structure").val()!="")
			{
				$("#homepage_change_dialog").dialog({
					title: "' . t(59, "Confirmation") . '",
					modal: true,
					width: 400,
					height: 150,
					buttons: [
					    {
					      text: "' . t(190, "Ok") . '",
					      icons: {  primary: "ui-icon-check"    },
					      click: function()
					      {
					            $("#homepage_from_structure").val("");
					            $("#homepage").focus();
					            $("#homepage_change_dialog").dialog("close");
					      }
					    },
					    {
					      text: "' . t(58, "Cancel") . '",
					      icons: { primary: "ui-icon-close" },
					      click: function()
					      {
			                 setTimeout(
			                    function()
			                    {
	                                $("div.ui-widget-overlay").hide();
			                        $("#homepage").blur();
		                        }, 100
	                         );
					         $("#homepage_change_dialog").dialog("close");
					      }
					    }
					]
				});
			}
		});

		$("#subdomain,#domain,#folder,#homepage").on("keyup", navigate_website_update_home_url);
		$("#protocol").on("change", navigate_website_update_home_url);

		function navigate_website_update_home_url()
		{
			var url = $("#protocol").val();
			if($("#subdomain").val().length > 0)
				url += $("#subdomain").val() + ".";
			url += $("#domain").val();
			url += $("#folder").val();
			url += $("#homepage").val();

			$("#navigate-website-home-url").html(url);
		}

		navigate_website_update_home_url();
	');
    if (!empty($item->theme)) {
        $navibars->add_tab_content_row(array('<label>' . t(368, 'Theme') . '</label>', '<strong>
				<a href="?fid=8&act=themes">
					<img height="16" width="16" align="absmiddle" src="img/icons/silk/rainbow.png" />
				</a> ' . $theme->title . '
			</strong>'));
    }
    $navibars->add_tab_content_row(array('<label>' . t(515, 'Not found paths') . '...</label>', $naviforms->selectfield('wrong_path_action', array(0 => 'blank', 1 => 'homepage', 2 => 'theme_404', 3 => 'http_404', 4 => 'website_path'), array(0 => t(516, 'Show a blank page'), 1 => t(517, 'Redirect to home page'), 2 => t(518, 'Use the custom 404 template of a theme (if exists)'), 3 => t(519, 'Send a 404 HTTP error header'), 4 => t(642, 'Redirect to a website page')), $item->wrong_path_action, 'navigate_websites_wrong_path_action_change(this)', false), '<a class="uibutton nv_website_wrong_path_trigger hidden"><i class="fa fa-sitemap"></i></a>', '<span id="navigate-website-wrong-path-redirect" class="nv_website_wrong_path_info navigate-form-row-info">' . $item->wrong_path_redirect . '</span>', $naviforms->hidden('wrong_path_redirect', $item->wrong_path_redirect)));
    $layout->add_script('
        function navigate_websites_wrong_path_action_change(el)
        {
            $(el).parent().find(".nv_website_wrong_path_trigger").addClass("hidden");
            $(el).parent().find(".nv_website_wrong_path_info").addClass("hidden");
            
            if($(el).val()=="website_path")
            {
                $(el).parent().find(".nv_website_wrong_path_trigger").removeClass("hidden");
                $(el).parent().find(".nv_website_wrong_path_info").removeClass("hidden");                
            }
        }
                
        navigate_websites_wrong_path_action_change($("#wrong_path_action"));
    
        $(".nv_website_wrong_path_trigger").on("click", function()
        {
            var trigger = this;
        
            // hide "replace title" when calling the dialog from the block action
            // leave it enabled when calling the dialog from the Links table
            if($(this).parents("table.box-table").length == 0)
                $("#nv_link_dialog_replace_text").parent().css("visibility", "hidden");
        
            $("#nv_link_dialog").removeClass("hidden");
            $("#nv_link_dialog").dialog({
                title: $("#nv_link_dialog").attr("title"),
                modal: true,
                width: 620,
                height: 400,
                buttons: [
                    {
                        text: "Ok",
                        click: function(event, ui)
                        {
                            // check if there is any path selected
                            if(!$("#nv_link_dialog_dynamic_path").hasClass("hidden"))
                            {
                                var input_path = $("#wrong_path_redirect");
                                input_path.val($("#nv_link_dialog_dynamic_path").text());
                                $(".nv_website_wrong_path_info").html($("#nv_link_dialog_dynamic_path").text());
        
                                $("#nv_link_dialog").dialog("close");
                            }
                        }
                    },
                    {
                        text: "Cancel",
                        click: function(event, ui)
                        {
                            $("#nv_link_dialog").dialog("close");
                        }
                    }
                ],
                close: function()
                {
                    $("#nv_link_dialog_replace_text").parent().css("visibility", "visible");
                }
            });
        });    
    ');
    // when no path is given
    $navibars->add_tab_content_row(array('<label>' . t(625, 'Empty paths') . '...</label>', $naviforms->selectfield('empty_path_action', array(0 => 'homepage_redirect', 1 => 'homepage_noredirect', 2 => 'blank', 3 => 'theme_404', 4 => 'http_404'), array(0 => t(517, 'Redirect to home page'), 1 => t(626, 'Display the home page, without changing the route'), 2 => t(516, 'Show a blank page'), 3 => t(518, 'Use the custom 404 template of a theme (if exists)'), 4 => t(519, 'Send a 404 HTTP error header')), $item->empty_path_action, '', false)));
    $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(71, 'Closed')), $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')))));
    $layout->add_script('
        $("#permission").on("change", function()
        {
            if($(this).val() > 0)
                $("#redirect_to").parent().show();
            else
                $("#redirect_to").parent().hide();
        });

        $("#permission").trigger("change");
    ');
    $navibars->add_tab_content_row(array('<label>' . t(505, 'Redirect to') . '</label>', $naviforms->textfield('redirect_to', $item->redirect_to), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' /landing_page.html</span>'));
    $navibars->add_tab(t(63, "Languages"));
    // system locales
    $locales = $item->unix_locales();
    $system = PHP_OS;
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && empty($locales)) {
        $locales = $item->windows_locales();
        $system = 'MS Windows';
    }
    /* Languages selector */
    if (!is_array($item->languages_list)) {
        $item->languages_list = array();
    }
    $table = new naviorderedtable("website_languages_table");
    //$table->setWidth("600px");
    $table->setHiddenInput("languages-order");
    $navibars->add_tab_content($naviforms->hidden('languages-order', implode('#', $item->languages_list)));
    $table->addHeaderColumn(t(159, 'Name'), 160);
    $table->addHeaderColumn(t(237, 'Code'), 60);
    $table->addHeaderColumn(t(471, 'Variant') . '/' . t(473, 'Region'), 120);
    $table->addHeaderColumn(t(474, 'System locale') . ' (' . $system . ')', 150);
    $table->addHeaderColumn(t(64, 'Published'), 60);
    $table->addHeaderColumn(t(35, 'Remove'), 60);
    $DB->query('SELECT code, name FROM nv_languages');
    $languages_rs = $DB->result();
    $languages = array();
    foreach ($languages_rs as $lang) {
        $languages[$lang->name] = $lang->code;
    }
    if (empty($item->languages)) {
        // load default language settings
        $item->languages_list = array('en');
        $item->languages_published = array('en');
        $item->languages = array('en' => array('language' => 'en', 'variant' => '', 'code' => 'en', 'system_locale' => strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'ENU_USA' : 'en_US.utf8'));
    }
    if (empty($item->languages)) {
        $item->languages = array();
    }
    // add previously assigned locales if they are missing
    foreach ($item->languages as $lcode => $ldef) {
        if (!in_array($ldef['system_locale'], $locales)) {
            $locales[$ldef['system_locale']] = '? [' . $ldef['system_locale'] . ']';
        }
    }
    $p = 0;
    foreach ($item->languages as $lcode => $ldef) {
        $p++;
        $published = array_search($lcode, $item->languages_published) !== false;
        $variant = !empty($ldef['variant']);
        $select_language = $naviforms->select_from_object_array('language-id[]', $languages_rs, 'code', 'name', $ldef['language'], ' width: 150px; ');
        if (empty($locales)) {
            $select_locale = $naviforms->textfield('language-locale[]', $ldef['system_locale'], '300px');
        } else {
            $select_locale = $naviforms->selectfield('language-locale[]', array_keys($locales), array_values($locales), $ldef['system_locale'], '', false, array(), 'width: 300px;');
        }
        $uid = uniqid();
        $table->addRow($p, array(array('content' => $select_language, 'align' => 'left'), array('content' => '<div style=" white-space: nowrap; "><input type="text" name="language-code[]" value="' . $ldef['language'] . '" style="width: 30px;" /></div>', 'align' => 'left'), array('content' => '<input type="checkbox" name="language-variant[]" id="language-variant[' . $uid . ']" value="1" ' . ($variant ? 'checked="checked"' : '') . ' style="float:left;" class="raw-checkbox" /> <input type="text" name="language-variant-code[]" value="' . $ldef['variant'] . '" style="width: 75px;" />', 'align' => 'left'), array('content' => $select_locale, 'align' => 'left'), array('content' => '<input type="hidden" name="language-published[]" value="' . ($published ? '1' : '0') . '" /><input type="checkbox" id="language-published[' . $uid . ']" value="' . $lcode . '" ' . ($published ? 'checked="checked"' : '') . ' onclick=" if($(this).is(\':checked\')) { $(this).prev().val(1); } else { $(this).prev().val(0); }; " /><label for="language-published[' . $uid . ']"></label>', 'align' => 'center'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" onclick="navigate_websites_language_remove(this);" />', 'align' => 'center')));
    }
    $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</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') . '
            </div>'));
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="websites-languages-add"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(472, 'Add') . '</button>'));
    $layout->add_script('
        $("#website_languages_table tr").eq(1).find("td:last").children().hide();
        $(\'input[name="language-variant[]"]\').each(function(i, el)
        {
            if($(el).is(":checked"))
                $(el).next().removeClass("ui-state-disabled");
            else
                $(el).next().val("").addClass("ui-state-disabled");
        });

        $(\'input[name="language-variant-code[]"]\').on("click", function()
        {
            if(!$(this).prev().is(":checked"))
                $(this).prev().trigger("click");
        });

        $("#website_languages_table").on("change", \'select[name="language-id[]"]\', function()
        {
            var input = $(this).parent().next().find("input");
            $(input).val($(this).val());
            $(input).effect("highlight", {}, 2000);
        });

        $("#website_languages_table").on("change", \'input[name="language-variant[]"]\', function()
        {
            if($(this).is(":checked"))
                $(this).next().removeClass("ui-state-disabled");
            else
                $(this).next().val("").addClass("ui-state-disabled");
        });

        $("#websites-languages-add").on("click", function()
        {
            var tr = $("#website_languages_table").find("tr").eq(1).clone();            
            var tsid = new Date().getTime();
            $(tr).attr("id", tsid);
            
            $(tr).find("input,label,select").each(function()
		    {
		        if($(this).attr("id"))
		        {
		            var new_name = ($(this).attr("id").split("["))[0];
		            $(this).attr("id", new_name + "[" + tsid + "]");
		        }
		
		        if($(this).attr("for"))
		        {
		            var new_name = ($(this).attr("for").split("["))[0];
		            $(this).attr("for", new_name + "[" + tsid + "]");
		        }
		    });

            $("#website_languages_table").find("tbody:last").append(tr);
            $("#website_languages_table").tableDnD({
                onDrop: function(table, row)
                {
                    navigate_naviorderedtable_website_languages_table_reorder();
                }
            });

            navigate_naviorderedtable_website_languages_table_reorder();

            $(tr).find("td:first").find("a,div,span").remove();
            $(tr).find("td").eq(3).find("a,div,span").remove();

            navigate_selector_upgrade($(tr).find("td:first").find("select"));

            if($(tr).find("td").eq(3).find("select").length > 0)
                navigate_selector_upgrade($(tr).find("td").eq(3).find("select"));

            return false;
        });

        function navigate_websites_language_remove(el)
        {
            $(el).parent().parent().remove();
        }

        function navigate_naviorderedtable_website_languages_table_reorder()
        {
            $("#website_languages_table tr").find("td:last").not(":first").children().show();
            $("#website_languages_table tr").eq(1).find("td:last").children().hide();
        }
    ');
    $navibars->add_tab(t(485, "Aliases"));
    $table = new naviorderedtable("website_aliases_table");
    $table->addHeaderColumn(t(486, 'Alias'), 160);
    $table->addHeaderColumn('', 24);
    $table->addHeaderColumn(t(487, 'Real URL'), 60);
    $table->addHeaderColumn(t(35, 'Remove'), 60);
    $table->addRow($lang->code, array(array('content' => '<div style="width: 308px;">http://example.domain.com/demo</div>', 'align' => 'left'), array('content' => '&rarr;', 'align' => 'center'), array('content' => '<div style="width: 308px;">http://www.domain.com/example/demo</div>', 'align' => 'left'), array('content' => '', 'align' => 'left')));
    if (!is_array($item->aliases)) {
        $item->aliases = array();
    }
    foreach ($item->aliases as $alias => $realurl) {
        $table->addRow($lang->code, array(array('content' => '<input type="text" name="website-aliases-alias[]" value="' . $alias . '" style="width: 300px;" />', 'align' => 'left'), array('content' => '&rarr;', 'align' => 'center'), array('content' => '<input type="text" name="website-aliases-real[]" value="' . $realurl . '" style="width: 300px;" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" onclick="navigate_websites_aliases_remove(this);" />', 'align' => 'center')));
    }
    $navibars->add_tab_content_row(array('<label>' . t(485, 'Aliases') . '</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') . '
            </div>'));
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="websites-aliases-add"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(472, 'Add') . '</button>'));
    $layout->add_script('
        $("#websites-aliases-add").on("click", function()
        {
            var tr = $("<tr><td></td><td></td><td></td><td></td></tr>");
            $(tr).attr("id", new Date().getTime());
            $(tr).find("td").eq(0).html("<input type=\\"text\\" name=\\"website-aliases-alias[]\\" style=\\"width: 300px;\\" />");
            $(tr).find("td").attr("align", "center").eq(1).html("&rarr;");
            $(tr).find("td").eq(2).html("<input type=\\"text\\" name=\\"website-aliases-real[]\\" style=\\"width: 300px;\\" />");
            $(tr).find("td").attr("align", "center").eq(3).html("<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/cancel.png\\" onclick=\\"navigate_websites_aliases_remove(this);\\" />");

            $("#website_aliases_table").find("tbody:last").append(tr);
            $("#website_aliases_table").tableDnD();
            return false;
        });

        function navigate_websites_aliases_remove(el)
        {
            $(el).parent().parent().remove();
        }
    ');
    $navibars->add_tab(t(9, "Content"));
    // keep the default value for Navigate CMS < 2.0
    if (empty($item->word_separator)) {
        $item->word_separator = "_";
    }
    $navibars->add_tab_content_row(array('<label>' . t(633, 'Word separator in paths') . '</label>', $naviforms->selectfield('word_separator', array(0 => '-', 1 => '_'), array(0 => t(634, "Hyphen") . " /navigate-cms", 1 => t(635, "Underscore") . " /navigate_cms"), $item->word_separator), '<span class="navigate-form-row-info">' . t(636, 'Existing paths will not be modified') . '</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(50, 'Date format') . '</label>', $naviforms->selectfield('date_format', array(0 => 'd/m/Y', 1 => 'd-m-Y', 2 => 'm/d/Y', 3 => 'm-d-Y', 4 => 'Y-m-d', 5 => 'Y/m/d'), array(0 => date('d/m/Y'), 1 => date('d-m-Y'), 2 => date('m/d/Y'), 3 => date('m-d-Y'), 4 => date('Y-m-d'), 5 => date('Y/m/d')), $item->date_format)));
    $timezones = property::timezones();
    if (empty($item->default_timezone)) {
        $item->default_timezone = date_default_timezone_get();
    }
    $navibars->add_tab_content_row(array('<label>' . t(207, 'Default timezone') . '</label>', $naviforms->selectfield("default_timezone", array_keys($timezones), array_values($timezones), $item->default_timezone)));
    $navibars->add_tab_content_row(array('<label>' . t(433, 'Resize uploaded images') . '</label>', $naviforms->selectfield('resize_uploaded_images', array(0 => 0, 1 => 600, 2 => 800, 3 => 960, 4 => 1200, 5 => 1600, 6 => 2000), array(0 => t(434, 'Keep original file'), 1 => '600 px', 2 => '800 px', 3 => '960 px', 4 => '1200 px', 5 => '1600 px', 6 => '2000 px'), $item->resize_uploaded_images), '<span class="navigate-form-row-info">' . t(435, 'Maximum width or height') . '</span>'));
    // navigate cms 2.0.2: website->tinymce_css field is DEPRECATED (will be removed in a future revision)
    if (!empty($item->tinymce_css)) {
        $navibars->add_tab_content_row(array('<label>tinyMCE CSS</label>', $naviforms->textfield('tinymce_css', $item->tinymce_css), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' /css/style.content.css</span>'));
    }
    $navibars->add_tab_content_row(array('<label>' . t(328, 'Favicon') . '</label>', $naviforms->dropbox('website-favicon', $item->favicon, "image")));
    $navibars->add_tab_content_row(array('<label>' . t(597, 'Share files in media browser') . '</label>', $naviforms->checkbox('share_files_media_browser', $item->share_files_media_browser == '1'), '<span class="navigate-form-row-info">(' . t(598, 'Only between websites of the current Navigate CMS installation') . ')</span>'));
    // default comment options for elements
    $navibars->add_tab_content_row(array('<label>' . t(252, 'Comments enabled for') . '</label>', $naviforms->selectfield('comments_enabled_for', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(253, 'Nobody'), 1 => t(24, 'Registered users'), 2 => t(254, 'Everyone')), $item->comments_enabled_for)));
    $webuser_name = '';
    if ($item->comments_default_moderator == "c_author") {
        $webuser_name = t(545, 'Content author');
    } else {
        if (!empty($item->comments_default_moderator)) {
            $webuser_name = $DB->query_single('username', 'nv_users', ' id = ' . intval($item->comments_default_moderator));
        }
    }
    $moderator_id = array('c_author');
    $moderator_username = array('{' . t(545, 'Content author') . '}');
    if (!empty($item->comments_default_moderator)) {
        if ($item->comments_default_moderator != 'c_author') {
            $moderator_username[] = $DB->query_single('username', 'nv_users', ' id = ' . intval($item->comments_default_moderator));
            $moderator_id[] = $item->comments_default_moderator;
        }
    }
    $navibars->add_tab_content_row(array('<label>' . t(255, 'Moderator') . '</label>', $naviforms->selectfield('comments_default_moderator', $moderator_id, $moderator_username, $item->comments_default_moderator, null, false, null, null, false), '<span style="display: none;" id="comments_default_moderator-helper">' . t(535, "Find user by name") . '</span>', '<div class="subcomment"><img align="absmiddle" src="' . NAVIGATE_URL . '/img/icons/silk/information.png" /> ' . t(256, 'Leave blank to accept all comments') . '</div>'));
    $layout->add_script('
        // comments moderator autocomplete
        $("#comments_default_moderator").select2(
        {
            placeholder: $("#comments_default_moderator-helper").text(),
            minimumInputLength: 0,
            ajax: {
                url: "?fid=items&act=json_find_user",
                dataType: "json",
                delay: 100,
                data: function (params)
		        {
		            return {
		                username: params.term,
		                nd: new Date().getTime(),
		                page_limit: 30, // page size
		                page: params.page // page number
		            };
		        },
		        processResults: function (data, params)
		        {
		            params.page = params.page || 1;
		            data.items.unshift({id: "c_author", text: "{' . t(545, 'Content author') . '}" });
		            data.total_count++;
		            return {
						results: data.items,
						pagination: { more: (params.page * 30) < data.total_count }
					};
		        }
            },
            templateSelection: function(row)
			{
				if(row.id && row.id != "c_author")
					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
        });

        $("#comments_default_moderator-text").on("change", function(e)
        {
            $("#comments_default_moderator").val(e.val);
        });
    ');
    /* TAB EMAIL */
    $navibars->add_tab(t(44, "E-Mail"));
    $navibars->add_tab_content_row(array('<label>' . t(548, "Method") . '</label>', $naviforms->buttonset('mail_mailer', array('smtp' => 'SMTP', 'sendmail' => 'Sendmail', 'mail' => 'PHP mail'), empty($item->mail_mailer) ? 'smtp' : $item->mail_mailer, "navigate_change_mail_transport(this);")));
    $layout->add_script('
        function navigate_change_mail_transport(el)
        {
            var mail_mailer = "";
            if(el=="smtp" || el=="sendmail" || el=="mail")
                mail_mailer = el;
            else
                mail_mailer = $("input#" + $(el).attr("for")).val();

            $("#mail_server").parent().show();
            $("#mail_port").parent().show();
            $("#mail_security").parent().show();
            $("#mail_user").parent().show();
            $("#mail_password").parent().show();
            if(mail_mailer=="sendmail" || mail_mailer=="mail")
            {
                $("#mail_server").parent().hide();
                $("#mail_port").parent().hide();
                $("#mail_security").parent().hide();
                $("#mail_user").parent().hide();
                $("#mail_password").parent().hide();
            }
        }

        navigate_change_mail_transport("' . (empty($item->mail_mailer) ? 'smtp' : $item->mail_mailer) . '");
    ');
    $navibars->add_tab_content_row(array('<label>' . t(231, 'Server') . '</label>', $naviforms->textfield('mail_server', $item->mail_server), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' localhost, mail.yourdomain.com</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(232, 'Port') . '</label>', $naviforms->textfield('mail_port', $item->mail_port), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' 25</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(427, 'Security protocol') . '</label>', $naviforms->selectfield('mail_security', array(0, 1, 2), array(t(581, "None"), "SSL / TLS", "STARTTLS"), $item->mail_security)));
    $navibars->add_tab_content_row(array('<label>' . t(1, 'User') . '</label>', $naviforms->textfield('mail_user', $item->mail_user), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' web@yourdomain.com</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(233, 'Address') . '</label>', $naviforms->textfield('mail_address', $item->mail_address), '<span class="navigate-form-row-info">' . t(230, 'Ex.') . ' web@yourdomain.com</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(2, 'Password') . '</label>', '<input type="password" name="mail_password" id="mail_password" autocomplete="off"  value="" size="32" />', '<span class="navigate-form-row-info">' . t(48, "Leave blank to keep the current value") . '</span>'));
    // force removing the browser saved password
    $layout->add_script('
		setTimeout(function() {
			$("input[name=mail_password]").val("");
		}, 10);
	');
    if (empty($item->contact_emails)) {
        $item->contact_emails = array();
    }
    $navibars->add_tab_content_row(array('<label>' . t(263, 'Support E-Mails') . '</label>', $naviforms->textarea('contact_emails', implode("\n", $item->contact_emails)), '<span class="navigate-form-row-info">' . t(264, "One entry per line") . '</span>'));
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="mail_test"><img src="' . NAVIGATE_URL . '/img/icons/silk/email_go.png" align="absmiddle" /> ' . t(390, "Test") . '</button>'));
    $layout->add_script('
		$("#mail_test").on("click", function()
		{
			navigate_status("' . t(391, "Trying to send a test e-mail…") . '", "loader", true);
			$.ajax({
			  type: "POST",
			  url: "?fid=' . $_GET['fid'] . '&act=email_test",
			  data: {
				 mail_mailer: $("input[name=\\"mail_mailer[]\\"]:checked").val(),
				 mail_server: $("#mail_server").val(),
				 mail_port: $("#mail_port").val(),
				 mail_security: $("#mail_security").is(":checked"),
				 mail_user: $("#mail_user").val(),
				 mail_address: $("#mail_address").val(),
				 mail_password: $("#mail_password").val(),
				 send_to: $("#contact_emails").val()
			  },
			  success: function(data)
			  {
				  navigate_status(navigate_lang_dictionary[42], "ready"); 
				  
				  if(!data)
				  	navigate_notification("' . t(56, "Unexpected error.") . '");
				  else
				  	navigate_notification("' . t(392, "E-Mail sent") . '");
			  },
			  error: function(data)
			  {
			        navigate_status(navigate_lang_dictionary[42], "ready");
			        var error_message = (data.responseText).split("<br />")[0];
			        if(error_message!="")
			            error_message = ": " + error_message;

			        navigate_notification("' . t(56, "Unexpected error.") . '" + error_message, true);
			  },
			  dataType: "json"
			});
			return false;
		});
	');
    /* METATAGS TAB */
    if (!empty($item->id) && !empty($item->languages)) {
        $navibars->add_tab(t(513, "Metatags"));
        $website_languages_selector = $item->languages();
        $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector);
        $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('metatags_language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);")));
        foreach ($item->languages_list as $lang) {
            $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
            $navibars->add_tab_content_row(array('<label>' . t(334, 'Description') . ' ' . $language_info . '</label>', $naviforms->textfield('metatag_description-' . $lang, $item->metatag_description[$lang]), '<span class="navigate-form-row-info">150-160</span>'), '', 'lang="' . $lang . '"');
            $navibars->add_tab_content_row(array('<label>' . t(536, 'Keywords') . ' ' . $language_info . '</label>', $naviforms->textfield('metatag_keywords-' . $lang, $item->metatag_keywords[$lang])), '', 'lang="' . $lang . '"');
            $layout->add_script('               
                $("#metatag_keywords-' . $lang . '").tagit({
                    removeConfirmation: true,
                    allowSpaces: true,
                    singleField: true,
                    singleFieldDelimiter: ",",
                    placeholderText: "+",
                    autocomplete: 
                    {
                        delay: 0, 
                        minLength: 1,
                        source: "?fid=items&act=json_tags_search&lang=' . $lang . '"
                    },
                    afterTagAdded: function(event, ui)
                    {
                        var tags = $(this).tagit("assignedTags");
                        if(tags.length > 0)
                            tags = tags.join(",");
                        else
                            tags = "";
                            
                        $("#metatag_keywords-' . $lang . '").val(tags);
                    }
                });
			');
            $navibars->add_tab_content_row(array('<label>' . t(514, "Additional metatags") . ' ' . $language_info . '</label>', $naviforms->scriptarea('metatags-' . $lang, $item->metatags[$lang], 'html', ' width: 75%; height: 100px; ')), '', 'lang="' . $lang . '"');
        }
    }
    /* SERVICES TAB */
    $navibars->add_tab(t(178, "Services"));
    $navibars->add_tab_content_row(array('<label>' . t(498, 'Additional scripts') . '</label>', $naviforms->scriptarea('additional_scripts', $item->additional_scripts, 'js', ' width: 600px; height: 250px; '), '<div style="clear: both;"><label>&nbsp;</label>&lt;script type="text/javascript"&gt;...&lt;/script&gt;</div>'));
    if (!empty($item->theme)) {
        $navibars->add_tab(t(368, 'Theme') . ': ' . $theme->title);
        if (!is_array($theme->options)) {
            $theme->options = array();
        }
        // show a language selector (only if it's a multilanguage website and has properties)
        if (!empty($theme->options) && count($item->languages) > 1) {
            $website_languages_selector = $item->languages();
            $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector);
            $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);")), "navigate-form-tab-theme-language_selector");
            // hide languages selector if there isn't a multilanguage property
            $layout->add_script('
				$(document).ready(function()
			    {
					if($("#navigate-form-tab-theme-language_selector").parent().find(".navigate-form-row[lang]").length < 1)
					{
						$("#navigate-form-tab-theme-language_selector").css("display", "none");
					}
			    });
		    ');
        }
        // common property: style
        // 1: get available style IDs
        $styles_values = array_keys((array) $theme->styles);
        if (!is_array($styles_values)) {
            $styles_values = array();
        }
        // 2: prepare array of style ID => style name
        $styles = array();
        foreach ($styles_values as $sv) {
            $styles[$sv] = $theme->styles->{$sv}->name;
            if (empty($styles[$sv])) {
                $styles[$sv] = $sv;
            }
            $styles[$sv] = $theme->t($styles[$sv]);
        }
        $property = new property();
        $property->id = 'style';
        $property->name = t(431, 'Style');
        $property->type = 'option';
        $property->options = serialize($styles);
        $property->value = $item->theme_options->style;
        $navibars->add_tab_content(navigate_property_layout_field($property));
        foreach ($theme->options as $theme_option) {
            $property = new property();
            $property->load_from_theme($theme_option, $item->theme_options->{$theme_option->id});
            $navibars->add_tab_content(navigate_property_layout_field($property, "", $item->id));
        }
        navigate_property_layout_scripts($item->id);
    }
    $events->trigger('websites', 'edit', array('item' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms));
    return $navibars->generate();
}
function navigate_property_layout_field($property, $object = "", $website_id = "")
{
    global $website;
    global $layout;
    global $theme;
    global $user;
    global $DB;
    $ws = $website;
    $ws_theme = $theme;
    if (!empty($website_id) && $website_id != $website->id) {
        $ws = new website();
        $ws->load($website_id);
        $ws_theme = new theme();
        $ws_theme->load($ws->theme);
    }
    // object used for translations (theme or extension)
    if (empty($object)) {
        $object = $ws_theme;
    }
    $naviforms = new naviforms();
    $langs = $ws->languages_list;
    $field = array();
    if (!isset($property->value)) {
        $property->value = $property->dvalue;
    }
    if (!isset($property->multilanguage)) {
        $property->multilanguage = 'false';
    }
    $property_name = $property->name;
    if (!empty($object)) {
        $property_name = $object->t($property_name);
    }
    if (in_array($property->type, array("text", "textarea", "rich_textarea", "link")) || $property->multilanguage == 'true') {
        if (!isset($property->multilanguage) || $property->multilanguage !== false || $property->multilanguage == "false") {
            $property->multilanguage = 'true';
        } else {
            $property->multilanguage = 'false';
        }
        if (is_object($property->value)) {
            $property->value = (array) $property->value;
        }
        if (!is_array($property->value)) {
            $property->value = array();
        }
        foreach ($langs as $lang) {
            if (!isset($property->value[$lang]) && isset($property->dvalue)) {
                $property->value[$lang] = $property->dvalue;
            }
        }
    }
    // auto show/hide properties by other properties values --> "conditional": [ { "source_property_id" : [value1,"value2"] } ]
    if (!empty($property->conditional)) {
        foreach ($property->conditional as $conditional) {
            foreach ($conditional as $conditional_property => $conditional_values) {
                if (!is_array($conditional_values)) {
                    $conditional_values = array($conditional_values);
                }
                $conditional_values = '["' . implode('", "', $conditional_values) . '"]';
                $layout->add_script('
                    navigate_tabform_conditional_property("' . $property->id . '", "' . $conditional_property . '", ' . $conditional_values . ');
                ');
            }
        }
    }
    switch ($property->type) {
        case 'value':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->textfield("property-" . $property->id, $property->value);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'decimal':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->decimalfield("property-" . $property->id, $property->value, $property->precision, $user->decimal_separator, $user->thousands_separator, @$property->prefix, @$property->suffix);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'rating':
            $default = explode('#', $property->dvalue);
            $stars = $default[1];
            if (empty($stars)) {
                $stars = 5;
            }
            $inputs = $stars * 2;
            // half stars ALWAYS enabled
            if ($property->value == $property->dvalue) {
                $property->value = intval($default[0]) * 2;
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" style=" height: 18px; ">';
            $field[] = '<label>' . $property_name . '</label>';
            for ($i = 1; $i <= $inputs; $i++) {
                $checked = '';
                if ($property->value == $i) {
                    $checked = ' checked="checked" ';
                }
                $field[] = '<input type="radio" name="property-' . $property->id . '" class="star {split:2}" value="' . $i . '" ' . $checked . ' />';
            }
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'boolean':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->checkbox("property-" . $property->id, $property->value == '1');
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'option':
            $options = $property->options;
            if (is_string($options)) {
                $options = mb_unserialize($options);
            } else {
                if (is_object($options)) {
                    $options = (array) $options;
                }
            }
            // translate each option text
            if (!empty($object) && !empty($options)) {
                foreach ($options as $value => $text) {
                    $options[$value] = $object->t($text);
                }
            }
            if (!isset($property->option_html)) {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->selectfield("property-" . $property->id, array_keys($options), array_values($options), $property->value);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                // each option formatted in a specific html fragment
                if (isset($property->stylesheet)) {
                    $custom_stylesheet = $property->stylesheet;
                    if (strpos($custom_stylesheet, 'http') === false) {
                        $custom_stylesheet = NAVIGATE_URL . '/themes/' . $ws->theme . '/' . $custom_stylesheet . '?bogus=' . time();
                    }
                    $layout->add_style_tag($custom_stylesheet, false);
                    if (empty($options)) {
                        $custom_stylesheet_contents = file_get_contents(NAVIGATE_PATH . '/themes/' . $ws->theme . '/' . $property->stylesheet);
                        $custom_stylesheet_contents = stylesheet_parse($custom_stylesheet_contents);
                        $options = array();
                        if (is_array($custom_stylesheet_contents)) {
                            foreach ($custom_stylesheet_contents as $rule => $rule_content) {
                                if (in_array(substr($rule, 0, 1), array('.', '#'))) {
                                    $rule = str_replace(array('.', '#', ':before', ':after', ':focus', ':visited'), '', $rule);
                                    $options[$rule] = $rule;
                                    if (!empty($object)) {
                                        $options[$rule] = $object->t($rule);
                                    }
                                }
                            }
                        }
                    }
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->selectfield("property-" . $property->id, array_keys($options), array_values($options), $property->value, NULL, false, NULL, NULL, false, false);
                $layout->add_script('
					$("#property-' . $property->id . '").select2(
				        {
				            selectOnBlur: true,
				            minimumResultsForSearch: 6,
							escapeMarkup: function (markup)
					        {
					            return markup; // let our custom formatter work
					        },
					        templateSelection: function(row)
					        {					        
					            var option_html = "' . str_replace('"', '\\"', $property->option_html) . '";
					            option_html = option_html.replace(/{{VALUE}}/g, row.id);
					            option_html = option_html.replace(/{{TEXT}}/g, row.text);
					        
					            if(row.id)
					                return option_html;
					            else
					                return "("  + navigate_t(581, "None") + ")";
					        },
					        templateResult: function(data)
					        {
					            var option_html = "' . str_replace('"', '\\"', $property->option_html) . '";
					            option_html = option_html.replace(/{{VALUE}}/g, data.id);
					            option_html = option_html.replace(/{{TEXT}}/g, data.text);
					        
					            if(data.id)
					                return option_html;
					            else
					                return "("  + navigate_t(581, "None") + ")";
					        }
				        }
				    );
			    ');
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            }
            break;
        case 'moption':
            $options = $property->options;
            if (is_string($options)) {
                $options = mb_unserialize($options);
            } else {
                if (is_object($options)) {
                    $options = (array) $options;
                }
            }
            // translate each option text
            if (!empty($object)) {
                foreach ($options as $value => $text) {
                    $options[$value] = $object->t($text);
                }
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->selectfield("property-" . $property->id, array_keys($options), array_values($options), explode(',', $property->value), "", true);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'country':
            $options = property::countries();
            $country_codes = array_keys($options);
            $country_names = array_values($options);
            // include "country not defined" item
            array_unshift($country_codes, '');
            array_unshift($country_names, '(' . t(307, "Unspecified") . ')');
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->selectfield("property-" . $property->id, $country_codes, $country_names, strtoupper($property->value));
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'coordinates':
            $coordinates = explode('#', $property->value);
            $latitude = @$coordinates[0];
            $longitude = @$coordinates[1];
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->textfield("property-" . $property->id . '-latitude', $latitude, '182px');
            $field[] = $naviforms->textfield("property-" . $property->id . '-longitude', $longitude, '182px');
            $field[] = '<img src="img/icons/silk/map_magnify.png" align="absmiddle" hspace="3px" id="property-' . $property->id . '-show" />';
            $field[] = '<div id="property-' . $property->id . '-map-container" style=" display: none; ">';
            $field[] = '	<div class="navigate-form-row" id="property-' . $property->id . '-search" style=" width: 278px; height: 24px; margin-top: 9px; margin-left: 40px; position: absolute; z-index: 1000; opacity: 0.95; ">';
            $field[] = '		<input type="text" name="property-' . $property->id . '-search-text" style=" width: 240px; " /> ';
            $field[] = '		<img class="ui-widget ui-button ui-state-default ui-corner-all" sprite="false" style=" cursor: pointer; padding: 3px; " src="' . NAVIGATE_URL . '/img/icons/silk/zoom.png" align="right" />';
            $field[] = '	</div>';
            $field[] = '	<div id="property-' . $property->id . '-map" style=" width: 400px; height: 200px; "></div>';
            $field[] = '</div>';
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $layout->add_script('
                // auto parse standard Google Maps URLs when pasting them in the latitude field
                $("#property-' . $property->id . '-latitude").on("keyup", function()
                {
                    var value = $(this).val();                                        
                    if(value.indexOf("https://www.google")==0)
                    {                    
                        // locate the @ symbol
                        value = value.substr(value.indexOf("@")+1);
                        value = value.substr(0, value.indexOf("z"));
                        value = value.split(",");
                                                                        
                        if(value.length == 3) // parsed values seem fine
                        {
                            $("#property-' . $property->id . '-latitude").val(value[0]);                            
                            $("#property-' . $property->id . '-longitude").val(value[1]);                            
                        }
                    }
                });
            ');
            $layout->add_script('
				var property_' . $property->id . '_lmap = null;
			    var marker = null;
			    
			    L.Icon.Default.imagePath = "' . NAVIGATE_URL . '/lib/external/leaflet/images";
			    
			    // initialize leaflet map
                property_' . $property->id . '_lmap = L.map(
                    "property-' . $property->id . '-map",
                    {
                        doubleClickZoom: false
                    }
                );					    
                
                // create the tile layer with correct attribution
                var osmUrl = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
                var osmAttrib = "Map data © <a href=\\"http://openstreetmap.org\\">OpenStreetMap</a> contributors";
                var osm = new L.TileLayer(osmUrl, {minZoom: 0, maxZoom: 19, attribution: osmAttrib });
                
                property_' . $property->id . '_lmap.addLayer(osm);
							
				$("#property-' . $property->id . '-search input").on("keyup", function(e)
				{	if(e.keyCode == 13)	property' . $property->id . 'search();	});
				
				$("#property-' . $property->id . '-search img").on("click", property' . $property->id . 'search);
				
				$("#property-' . $property->id . '-show").on("click", function()
				{
					var myLatlng = new L.LatLng(
					    $("#property-' . $property->id . '-latitude").val(),
					    $("#property-' . $property->id . '-longitude").val()
					);																
												
                    property_' . $property->id . '_lmap.setView(myLatlng, 17);
	                
	                marker = L.marker(myLatlng).addTo(property_' . $property->id . '_lmap);
	                
	                property_' . $property->id . '_lmap.on("dblclick", function(e)
	                {	                    
                        $("#property-' . $property->id . '-latitude").val(e.latlng.lat);
						$("#property-' . $property->id . '-longitude").val(e.latlng.lng)
	                    
	                    marker.remove();
	                    marker = L.marker(e.latlng).addTo(property_' . $property->id . '_lmap);                        
	                });
					                    
					$("#property-' . $property->id . '-map-container").dialog(
					{
						width: 600,
						height: 400,
						title: "' . t(300, 'Map') . ': ' . t(301, 'Double click a place to set the coordinates') . '",
						resize: property' . $property->id . 'resize,
						open: function()
						{
						    $(this).css("padding", 0);
						    property_' . $property->id . '_lmap.invalidateSize();
                        }
                    }).dialogExtend(
					{
						maximizable: true,
						"maximize" : property' . $property->id . 'resize,
						"restore" : property' . $property->id . 'resize
					});
					
					property' . $property->id . 'resize();

				}).css("cursor", "pointer");	
				
				function property' . $property->id . 'resize()
				{
					$("#property-' . $property->id . '-map").width($("#property-' . $property->id . '-map-container").width()); 
					$("#property-' . $property->id . '-map").height($("#property-' . $property->id . '-map-container").height());	
					property_' . $property->id . '_lmap.invalidateSize();
				}
				
				function property' . $property->id . 'search()
				{				
					var address = $("#property-' . $property->id . '-search input").val();

                    $.getJSON("http://services.gisgraphy.com/geocoding/geocode?format=json&callback=?&address="+address, function(data)
                    {                                    
                        if(!data.result || data.result.length < 1)
                            alert("Geocode was not successful for the following reason: " + status);
                        else
                        {
                            property_' . $property->id . '_lmap.setView([data.result[0].lat, data.result[0].lng], 19);
                        }
                    });						        

					return false;
				}		
                
			');
            break;
        case 'text':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->textfield("property-" . $property->id . "-" . $lang, $property->value[$lang]);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            }
            break;
        case 'textarea':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $style = "";
                if (!empty($property->width)) {
                    $style = ' width: ' . $property->width . 'px; ';
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                if ($property->multilanguage == 'false') {
                    $language_info = '';
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->textarea("property-" . $property->id . "-" . $lang, $property->value[$lang], 4, 48, $style);
                $field[] = '<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from" title="' . t(189, 'Copy from') . '…"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"></button>';
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
                if ($property->multilanguage == 'false') {
                    break;
                }
            }
            break;
        case 'rich_textarea':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                if ($property->multilanguage == 'false') {
                    $language_info = '';
                }
                $width = NULL;
                if (!empty($property->width)) {
                    $width = $property->width . 'px';
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->editorfield("property-" . $property->id . "-" . $lang, $property->value[$lang], $width, NULL, $website_id);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                // additional control buttons
                $translate_menu = '';
                if (!empty($translate_extensions)) {
                    $translate_extensions_titles = array();
                    $translate_extensions_actions = array();
                    foreach ($translate_extensions as $te) {
                        if ($te['enabled'] == '0') {
                            continue;
                        }
                        $translate_extensions_titles[] = $te['title'];
                        $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'property-' . $property->id . '-' . $lang . '\', \'' . $lang . '\');';
                    }
                    if (!empty($translate_extensions_actions)) {
                        $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                    }
                }
                $field[] = '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">';
                $field[] = '<label>&nbsp;</label>';
                $field[] = $translate_menu;
                $field[] = '<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from"><img src="img/icons/silk/page_white_copy.png" align="absmiddle">' . t(189, 'Copy from') . '...</button> ';
                $field[] = !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'property-' . $property->id . '-' . $lang . '\', \'' . $property->id . '\', \'' . $lang . '\', \'tinymce\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '';
                $field[] = '</div>';
                $field[] = '</div>';
                // divformrow
                if ($property->multilanguage == 'false') {
                    break;
                }
            }
            break;
        case 'color':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->colorfield("property-" . $property->id, $property->value, @$property->options);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'date':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->datefield("property-" . $property->id, $property->value, false);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'datetime':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->datefield("property-" . $property->id, $property->value, true);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'source_code':
            if ($property->multilanguage != 'true' && $property->multilanguage != '1') {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->scriptarea("property-" . $property->id, $property->value);
                $field[] = '&nbsp;<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from" title="' . t(189, 'Copy from') . '…"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"></button>';
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                foreach ($langs as $lang) {
                    if (!is_array($property->value)) {
                        $ovalue = $property->value;
                        $property->value = array();
                        foreach ($langs as $lang_value) {
                            $property->value[$lang_value] = $ovalue;
                        }
                    }
                    $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                    $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                    $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                    $field[] = $naviforms->scriptarea("property-" . $property->id . "-" . $lang, $property->value[$lang]);
                    $field[] = '&nbsp;<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from" title="' . t(189, 'Copy from') . '…"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"></button>';
                    if (!empty($property->helper)) {
                        $helper_text = $property->helper;
                        if (!empty($object)) {
                            $helper_text = $object->t($helper_text);
                        }
                        $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                    }
                    $field[] = '</div>';
                }
            }
            break;
        case 'link':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $link = explode('##', $property->value[$lang]);
                if (is_array($link)) {
                    $target = @$link[2];
                    $title = @$link[1];
                    $link = $link[0];
                    if (empty($title)) {
                        $title = $link;
                    }
                } else {
                    $title = $property->value[$lang];
                    $link = $property->value[$lang];
                    $target = '_self';
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                if ($property->multilanguage == 'false') {
                    $language_info = '';
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '" style="margin-bottom: 0px;">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->textfield("property-" . $property->id . "-" . $lang . "-title", $title);
                $field[] = '<span class="navigate-form-row-info">' . t(67, 'Title') . '</span>';
                $field[] = '</div>';
                $field[] = '<div class="navigate-form-row" lang="' . $lang . '" style="margin-bottom: 0px;" nv_property="' . $property->id . '" >';
                $field[] = '<label>&nbsp;</label>';
                $field[] = $naviforms->textfield("property-" . $property->id . "-" . $lang . "-link", $link);
                $field[] = '<span class="navigate-form-row-info">' . t(197, 'Link') . '</span>';
                $field[] = '</div>';
                $field[] = '<div class="navigate-form-row" lang="' . $lang . '" nv_property="' . $property->id . '" >';
                $field[] = '<label>&nbsp;</label>';
                $field[] = $naviforms->selectfield("property-" . $property->id . "-" . $lang . "-target", array('_self', '_blank'), array(t(173, "Follow URL"), t(174, "Open URL (new window)")), $target);
                $field[] = '<span class="navigate-form-row-info">' . t(172, 'Action') . '</span>';
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
                if ($property->multilanguage == 'false') {
                    break;
                }
            }
            break;
        case 'image':
            if ($property->multilanguage != 'true' && $property->multilanguage != '1') {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->dropbox("property-" . $property->id, $property->value, "image", false, @$property->dvalue, @$property->options, $website_id);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                foreach ($langs as $lang) {
                    if (!is_array($property->value)) {
                        $ovalue = $property->value;
                        $property->value = array();
                        foreach ($langs as $lang_value) {
                            $property->value[$lang_value] = $ovalue;
                        }
                    }
                    $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                    $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                    $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                    $field[] = $naviforms->dropbox("property-" . $property->id . "-" . $lang, $property->value[$lang], "image", false, @$property->dvalue, $website_id);
                    if (!empty($property->helper)) {
                        $helper_text = $property->helper;
                        if (!empty($object)) {
                            $helper_text = $object->t($helper_text);
                        }
                        $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                    }
                    $field[] = '</div>';
                }
            }
            break;
        case 'video':
            if ($property->multilanguage != 'true' && $property->multilanguage != '1') {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->dropbox("property-" . $property->id, $property->value, "video", false, $property->dvalue, $website_id);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                foreach ($langs as $lang) {
                    if (!is_array($property->value)) {
                        $ovalue = $property->value;
                        $property->value = array();
                        foreach ($langs as $lang_value) {
                            $property->value[$lang_value] = $ovalue;
                        }
                    }
                    $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                    $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                    $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                    $field[] = $naviforms->dropbox("property-" . $property->id . "-" . $lang, $property->value[$lang], "video", false, $property->dvalue, $website_id);
                    if (!empty($property->helper)) {
                        $helper_text = $property->helper;
                        if (!empty($object)) {
                            $helper_text = $object->t($helper_text);
                        }
                        $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                    }
                    $field[] = '</div>';
                }
            }
            break;
        case 'file':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->dropbox("property-" . $property->id, $property->value, NULL, NULL, NULL, NULL, $website_id);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'comment':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $comment_text = $property->value;
            if (!empty($object)) {
                $comment_text = $object->t($property->value);
            }
            $field[] = '<div class="subcomment" style="clear: none;">' . $comment_text . '</div>';
            $field[] = '</div>';
            break;
        case 'category':
            $hierarchy = structure::hierarchy(0, $website_id);
            $categories_list = structure::hierarchyList($hierarchy, $property->value);
            if (empty($categories_list)) {
                $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>';
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->dropdown_tree("property-" . $property->id, $categories_list, $property->value);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'categories':
            $hierarchy = structure::hierarchy(0, $website_id);
            $selected = explode(',', $property->value);
            if (!is_array($selected)) {
                $selected = array($property->value);
            }
            $categories_list = structure::hierarchyList($hierarchy, $selected);
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = '<div class="category_tree" id="categories-tree-property-' . $property->id . '">
                            <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $ws->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>';
            $field[] = $naviforms->hidden('property-' . $property->id, $property->value);
            $field[] = '<label>&nbsp;</label>';
            $field[] = '<button id="categories_tree_select_all_categories-property-' . $property->id . '">' . t(481, 'Select all') . '</button>';
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $layout->add_script('              
                $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree({
                    plugins: ["changed", "types", "checkbox"],
                    "types" :
                    {
                        "default":  {   "icon": "img/icons/silk/folder.png"    },
                        "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
                    },
                    "checkbox":
                    {
                        three_state: false,
                        cascade: "undetermined"
                    },
                    "core":
                    {
                        dblclick_toggle: false
                    }
                })
                .on("dblclick.jstree", function(e)
                {
                    e.preventDefault();
                    e.stopPropagation();
                
                    var li = $(e.target).closest("li");
                    $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree("open_node", "#" + li[0].id);
                
                    var children_nodes = new Array();
                    children_nodes.push(li);
                    $(li).find("li").each(function() {
                        children_nodes.push("#" + $(this)[0].id);
                    });
                
                    $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree("select_node", children_nodes);
                
                    return false;
                })
                .on("changed.jstree", function(e, data)
                {
                    var i, j, r = [];
                    var categories = new Array();
                    $("#property-' . $property->id . '").val("");       
                
                    for(i = 0, j = data.selected.length; i < j; i++)
                    {
                        var id = data.instance.get_node(data.selected[i]).data.nodeId;
                        categories.push(id);
                    }
                    
                    if(categories.length > 0)
                        $("#property-' . $property->id . '").val(categories);                                                                
                });

                $("#categories_tree_select_all_categories-property-' . $property->id . '").on("click", function(e)
                {
                    e.stopPropagation();
                    e.preventDefault();
                    $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree("select_all");
                    return false;
                });                                
            ');
            break;
        case 'element':
        case 'item':
            $property_item_title = '';
            $property_item_id = '';
            if (!empty($property->value)) {
                $property_item_title = $DB->query_single('text', 'nv_webdictionary', '   node_type = "item" AND
                        website = "' . $ws->id . '" AND
                        node_id = "' . $property->value . '" AND
                        subtype = "title" AND
                        lang = "' . $ws->languages_published[0] . '"');
                $property_item_title = array($property_item_title);
                $property_item_id = array($property->value);
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->selectfield("property-" . $property->id, $property_item_id, $property_item_title, $property->value, null, false, null, null, false);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $template_filter = @$property->element_template;
            if (empty($template_filter)) {
                $template_filter = $property->item_template;
            }
            $layout->add_script('
                $("#property-' . $property->id . '").select2(
                {
                    placeholder: "' . t(533, "Find element by title") . '",
                    minimumInputLength: 1,
                    ajax: {
                        url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item",
                        dataType: "json",
                        delay: 100,
                        data: function(params)
                        {
	                        return {
				                title: params.term,
				                template: "' . $template_filter . '",
				                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
                });
            ');
            break;
        case 'elements':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->textfield("property-" . $property->id);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $template_filter = @$property->element_template;
            if (empty($template_filter)) {
                $template_filter = $property->item_template;
            }
            $layout->add_script('			                
                $("#property-' . $property->id . '").tagit({
                    removeConfirmation: true,
                    allowSpaces: true,
                    singleField: true,
                    singleFieldDelimiter: ",",
                    placeholderText: "+",
                    autocompleteOnly: true,
                    autocomplete: {
                        delay: 0, 
                        minLength: 1,
                        source: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item&format=tagit&page_limit=10&template=' . $template_filter . '"
                    },
                    afterTagAdded: function(event, ui)
                    {                           
                        var tags = $(this).tagit("assignedValues");
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";
                            
                        $("#property-' . $property->id . '").val(tags).trigger("change");
                    },
                    afterTagRemoved: function(event, ui)
                    {
                        var tags = $(this).tagit("assignedValues");
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";

                        $("#property-' . $property->id . '").val(tags).trigger("change");
                    }
                });
                                
                $("#property-' . $property->id . '").next().sortable(
                {
                    items: ">li:not(.tagit-new)",
                    update: function(ui, event)
                    {
                        var tags = $("#property-' . $property->id . '").tagit("assignedValues");
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";

                        $("#property-' . $property->id . '").val(tags).trigger("change");
                    }
                });    
			');
            if (!empty($property->value)) {
                $values = explode(",", $property->value);
                $values = array_filter($values);
                foreach ($values as $cid) {
                    $content_title = $DB->query_single('text', 'nv_webdictionary', '   node_type = "item" AND
                        website = "' . $ws->id . '" AND
                        node_id = ' . protect($cid) . ' AND
                        subtype = "title" AND
                        lang = "' . $ws->languages_published[0] . '"');
                    $layout->add_script('
                        $("#property-' . $property->id . '").tagit("createTag", "' . $content_title . '", "", "", "' . $cid . '");                
                    ');
                }
                $layout->add_script('
                    $("#property-' . $property->id . '").trigger("change");
                ');
            }
            break;
        case 'webuser_groups':
            $webuser_groups = webuser_group::all_in_array();
            // to get the array of groups first we remove the "g" character
            $property->value = str_replace('g', '', $property->value);
            $property->value = explode(',', $property->value);
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->multiselect('property-' . $property->id, array_keys($webuser_groups), array_values($webuser_groups), $property->value);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'product':
            // TO DO (when navigate has products!)
            break;
        default:
    }
    return implode("\n", $field);
}
示例#8
0
function feeds_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    $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(326, 'Feeds') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(326, 'Feeds') . ' / ' . 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));
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=feeds&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=feeds&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(331, 'Format') . '</label>', $naviforms->selectfield('format', array(0 => 'RSS2.0', 1 => 'RSS0.91', 2 => 'ATOM', 3 => 'ATOM0.3', 4 => 'OPML', 5 => 'MBOX', 6 => 'HTML'), array(0 => 'RSS 2.0 (' . t(333, 'Recommended') . ')', 1 => 'RSS 0.91', 2 => 'ATOM', 3 => 'ATOM 0.3', 4 => 'OPML', 5 => 'mBox', 6 => 'HTML'), $item->format)));
    $navibars->add_tab_content_row(array('<label>' . t(335, 'Entries') . '</label>', $naviforms->selectfield('entries', array(0 => 10, 1 => 15, 2 => 20, 3 => 25, 4 => 50), array(0 => 10, 1 => 15, 2 => 20, 3 => 25, 4 => 50), $item->entries)));
    $navibars->add_tab_content_row(array('<label>' . t(336, 'Display') . '</label>', $naviforms->selectfield('content', array(0 => 'title', 1 => 'resume', 2 => 'content'), array(0 => t(67, 'Title'), 1 => t(337, 'Summary'), 2 => t(9, 'Content')), $item->content)));
    $navibars->add_tab_content_row(array('<label>' . t(157, 'Image') . '</label>', $naviforms->dropbox('image', $item->image, 'image')));
    $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(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled)));
    $navibars->add_tab_content_row(array('<label>' . t(332, 'Views') . '</label>', intval($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_feeds_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_feeds_path_check(this);'), '<span>&nbsp;</span>'));
        $navibars->add_tab_content_row(array('<div class="subcomment"><span class="ui-icon ui-icon-info" style=" float: left; margin-left: -3px; "></span>
				' . t(83, 'Leave blank to disable this item') . '</div>'));
        $navibars->add_tab_content_row(array('<label>' . t(334, 'Description') . '</label>', $naviforms->textarea('description-' . $lang_code, @$item->dictionary[$lang_code]['description'])));
        $navibars->add_tab_content('</div>');
    }
    $layout->add_script('
		function navigate_feeds_select_language(code)
		{
			$(".language_fields").css("display", "none");
			$("#language_fields_" + code).css("display", "block");			
		}
		
		var active_languages = ["' . implode('", "', $website->languages_list) . '"];
		var last_check = [];
		
		function navigate_feeds_path_generate(el)
		{
			var language = $(el).attr("id").substr(5);
			var surl = "";
			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_feeds_path_check(el);
		}		
		
		function navigate_feeds_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;

			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=path_check",
			  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 != "feed" )
					 {
						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)
		}
		
		$(window).bind("load", function()
		{
			for(al in active_languages)
			{
				navigate_feeds_path_check($("#path-" + active_languages[al]));
				
				$("#path-" + active_languages[al]).bind("focus", function()
				{
					if($(this).val() == "")
						navigate_feeds_path_generate($(this));
				});
			}

		});
				
	');
    $layout->add_script('navigate_feeds_select_language("' . $website->languages_list[0] . '")');
    $navibars->add_tab(t(330, "Categories"));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->categories);
    $navibars->add_tab_content_row(array('<label>' . t(330, 'Categories') . '</label>', '<div class="category_tree" id="category-tree-parent"><img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>'));
    if (!is_array($item->categories)) {
        $item->categories = array();
    }
    $navibars->add_tab_content($naviforms->hidden('categories', implode(',', $item->categories)));
    $layout->add_script('		
		$("#category-tree-parent .tree_ul").jstree({
            plugins: ["changed", "types", "checkbox"],
            "types" :
            {
                "default":  {   "icon": "img/icons/silk/folder.png"    },
                "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
            },
            "checkbox":
            {
                three_state: false,
                cascade: "undetermined"
            },
            "core":
            {
                dblclick_toggle: false
            }
        })
        .on("dblclick.jstree", function(e)
        {
            e.preventDefault();
            e.stopPropagation();
        
            var li = $(e.target).closest("li");
            $("#category-tree-parent .tree_ul").jstree("open_node", "#" + li[0].id);
        
            var children_nodes = new Array();
            children_nodes.push(li);
            $(li).find("li").each(function() {
                children_nodes.push("#" + $(this)[0].id);
            });
        
            $("#category-tree-parent .tree_ul").jstree("select_node", children_nodes);
        
            return false;
        })
        .on("changed.jstree", function(e, data)
        {
            var i, j, r = [];
            var categories = new Array();
            $("#categories").val("");
        
            for(i = 0, j = data.selected.length; i < j; i++)
            {
                var id = data.instance.get_node(data.selected[i]).data.nodeId;
                categories.push(id);
            }
            if(categories.length > 0)
                $("#categories").val(categories);
        });		
	');
    return $navibars->generate();
}
示例#9
0
function files_item_properties($item)
{
    global $user;
    global $website;
    global $layout;
    global $user;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $navibars->title(t(89, 'Files'));
    $layout->navigate_media_browser();
    // we can use media browser in this function
    //$navibars->add_actions(	array(	'<a href="?fid='.$_REQUEST['fid'].'&act=0&parent='.$item->parent.'"><img height="16" align="absmiddle" width="16" src="img/icons/silk/clipboard.png"> NaviM+</a>'));
    $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>', $user->permission("files.delete") == "true" ? '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>' : ''));
    $navibars->add_actions(array('<a href="?fid=' . $_REQUEST['fid'] . '&act=0&parent=' . $item->parent . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/folder_up.png"> ' . t(139, 'Back') . '</a>', 'search_form'));
    $delete_html = array();
    $delete_html[] = '<script language="javascript" type="text/javascript">';
    $delete_html[] = 'function navigate_delete_dialog()';
    $delete_html[] = '{';
    $delete_html[] = '$("<div id=\\"navigate-delete-dialog\\" class=\\"hidden\\">' . t(57, 'Do you really want to delete this item?') . '</div>").dialog(
					  {
							resizable: true,
							height: 150,
							width: 300,
							modal: true,
							title: "' . t(59, 'Confirmation') . '",
							buttons: 
							{
								"' . t(35, 'Delete') . '": function()
								{
									$.ajax(
									{
										async: false,
										url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=json&op=delete&id=' . $item->id . '",
										success: function(data)
										{
											if(data=="true" || data=="1")
												window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=0&parent=' . $item->parent . '";
											else
												navigate_notification(data);
										}
									});
									$(this).dialog("close");		
                                    $("#navigate-delete-dialog").remove();
								},
								"' . t(58, 'Cancel') . '": function()
								{
									$(this).dialog("close");
									$("#navigate-delete-dialog").remove();
								}
							}
						});
					}';
    $delete_html[] = '</script>';
    $navibars->add_content(implode("\n", $delete_html));
    $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>' . $item->id . '</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(144, 'Filename') . '</label>', $naviforms->textfield('name', $item->name)));
    $navibars->add_tab_content_row(array('<label>' . t(145, 'Size') . '</label>', '<span>' . core_bytes($item->size) . '</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(160, 'Type') . '</label>', $naviforms->selectfield('type', array(0 => 'image', 1 => 'video', 2 => 'audio', 3 => 'document', 4 => 'flash', 5 => 'file'), array(0 => t(157, 'Image'), 1 => t(272, 'Video'), 2 => t(31, 'Audio'), 3 => t(539, 'Document'), 4 => 'Flash', 5 => t(82, 'File')), $item->type, false)));
    // retrieve a full list of mimetypes by extension
    $mimetypes = array_values(file::mimetypes());
    // remove duplicate entries
    $mimetypes = array_unique($mimetypes);
    sort($mimetypes);
    $mimetypes = array_filter($mimetypes);
    $navibars->add_tab_content_row(array('<label>MIME</label>', $naviforms->selectfield('mime', $mimetypes, $mimetypes, $item->mime, false)));
    $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(80, 'Permission') . '</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)));
    $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled)));
    /*										
    	$navibars->add_tab_content_row(array(	'<label>'.t(153, 'Embed link').'</label>',
    											'<a href="'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=inline" target="_blank">'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=inline</a>'));
    
    	$navibars->add_tab_content_row(array(	'<label>'.t(154, 'Download link').'</label>',
    											'<a href="'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=attachment">'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=attachment</a>'));
    */
    $website_root = $website->absolute_path(true) . '/object';
    if (empty($website_root)) {
        $website_root = NVWEB_OBJECT;
    }
    $navibars->add_tab_content_row(array('<label>' . t(153, 'Embed link') . '</label>', '<a href="' . $website_root . '?id=' . $item->id . '&disposition=inline" target="_blank">' . $website_root . '?id=' . $item->id . '&disposition=inline</a>'));
    $navibars->add_tab_content_row(array('<label>' . t(154, 'Download link') . '</label>', '<a href="' . $website_root . '?id=' . $item->id . '&disposition=attachment">' . $website_root . '?id=' . $item->id . '&disposition=attachment</a>'));
    if ($item->type == 'image') {
        $navibars->add_tab(t(157, "Image"));
        $navibars->add_tab_content_row(array('<label>' . t(155, 'Width') . ' / ' . t(156, 'Height') . '</label>', $naviforms->textfield('width', $item->width, '50px'), 'x', $naviforms->textfield('height', $item->height, '50px'), 'px'));
        $navibars->add_tab_content_row(array('<label>' . t(170, 'Edit') . '</label>', '
			<script language="javascript" type="text/javascript">
				function navigate_pixlr_edit()
				{
					pixlr.overlay.show({
						service: "editor",
						loc: "' . $user->language . '",
						image:"' . NAVIGATE_DOWNLOAD . '?id=' . $item->id . '&disposition=inline&sid=' . session_id() . '&seed=" + new Date().getTime(),
						title: "' . $item->name . '",
						target: "' . NAVIGATE_URL . '/navigate_upload.php?wid=' . $website->id . '&engine=pixlr&id=' . $item->id . '&session_id=' . session_id() . '&seed=" + + new Date().getTime(),
						exit: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=pixlr_exit&id=' . $item->id . '&ts=" + + new Date().getTime(),
						credentials: true,
						method: "GET",
						referrer: "Navigate CMS",
						icon: "' . NAVIGATE_URL . '/img/navigate-isotype-16x16.png",
						locktitle: true,
						locktype: "png",
						redirect: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=pixlr_exit&id=' . $item->id . '&ts=" + + new Date().getTime()
					});

					// add a close button
					var close_button = $(\'<a href="#"><span class="fa-stack"><i class="fa fa-circle fa-stack-2x"></i><i class="fa fa-close fa-stack-1x fa-inverse"></i></span></a>\');
					close_button.css({
					    "position": "absolute",
					    "right": "-20px",
					    "top": "-20px",
					    "font-size": "20px",
					    "color": "#222"
					});
					close_button.on("click", function()
					{
				        pixlr.overlay.hide();
				        $("#image-preview").attr("src", $("#image-preview").attr("src") + "&refresh=" + new Date().getTime());
					});
					$("div:last").prepend(close_button);
				}
			</script>
			<a href="#" class="button" onclick="navigate_pixlr_edit();"><img src="' . NAVIGATE_URL . '/img/logos/pixlr.png" width="100px" height="42px" /></a>
		'));
        $navibars->add_tab_content_row(array('<label>' . t(274, 'Preview') . '</label>', '<div><img id="image-preview" src="' . $website_root . '?id=' . $item->id . '&disposition=inline&seed=' . core_time() . '" width="400px" /></div>'));
        $navibars->add_tab_content_row(array('<label>&nbsp;</label>' . '<button onclick="navigate_media_browser_focalpoint(' . $item->id . '); return false;"><img src="img/icons/silk/picture-measurement.png" align="absmiddle"> ' . t(540, 'Focal point') . '</button>'));
        $navibars->add_tab(t(334, 'Description'));
        $website_languages_selector = $website->languages();
        $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector);
        $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('files_description_language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);")));
        foreach ($website->languages_list as $lang) {
            $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
            $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . ' ' . $language_info . '</label>', $naviforms->textfield('title-' . $lang, @$item->title[$lang])), '', 'lang="' . $lang . '"');
            $navibars->add_tab_content_row(array('<label>' . t(334, 'Description') . ' ' . $language_info . '</label>', $naviforms->textfield('description-' . $lang, @$item->description[$lang])), '', 'lang="' . $lang . '"');
        }
    } else {
        if ($item->type == 'video') {
            $navibars->add_tab(t(272, "Video"));
            /*
            $navibars->add_tab_content_row(array(	'<label>'.t(272, 'Video').'</label>',
            										'<div id="video_'.$item->id.'" style="display:block;width:640px;height:360px;float:left;" class="video">',
            										'<video controls="controls">',
            										'	<source src="'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=inline" type="'.$item->mime.'" />',
            										'</video>',
            										'</div>'
                                                        ));	
            																				
            $layout->add_script('         
            	$("#video_'.$item->id.' video").mediaelementplayer(
            	{
            		pluginPath: "'.NAVIGATE_URL.'/lib/external/mediaelement/"
            	});
            ');				
            */
            $navibars->add_tab_content_row(array('<label>' . t(272, 'Video') . '</label>', '<div id="video_' . $item->id . '" style="display:block;width:640px;height:360px;float:left;" class="video">
													<a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>
												</div>', '<script language="javascript" type="text/javascript" src="http://bitcast-b.bitgravity.com/player/6/functions.js"></script>'));
            $layout->add_script('         
			var flashvars = {};
			flashvars.AutoPlay = "false";
			flashvars.File = "' . urlencode(NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $item->id . '&disposition=inline') . '";
			flashvars.Mode = "ondemand";
			var params = {};
			params.allowFullScreen = "true";
			params.allowScriptAccess = "always";
			var attributes = {};
			attributes.id = "bitgravity_player_6";
			swfobject.embedSWF(stablerelease, "video_' . $item->id . '", "640", "360", "9.0.115", "http://bitcast-b.bitgravity.com/player/expressInstall.swf", flashvars, params, attributes);	
		');
        } else {
            if ($item->type == 'audio') {
                $navibars->add_tab(t(31, "Audio"));
                $navibars->add_tab_content_row(array('<label>' . t(31, 'Audio') . '</label>', '<div id="audio_' . $item->id . '" style="display:block;float:left;" class="audio">', '<audio controls="controls">', '	<source src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $item->id . '&disposition=inline" type="' . $item->mime . '" />', '</audio>', '</div>'));
                $layout->add_script('         
			$("#audio_' . $item->id . ' audio").mediaelementplayer(
			{
				pluginPath: "' . NAVIGATE_URL . '/lib/external/mediaelement/"
			});

			$("#audio_' . $item->id . '").addClass("ui-state-default");
		');
            }
        }
    }
    return $navibars->generate();
}
示例#10
0
    public function navigate_media_browser()
    {
        global $DB;
        global $website;
        global $events;
        global $user;
        global $current_version;
        if (in_array('media_browser', $this->parts_added)) {
            return;
        }
        array_push($this->parts_added, 'media_browser');
        $naviforms = new naviforms();
        $DB->query('
			SELECT *
			  FROM nv_websites
			 WHERE id = ' . $website->id . '
			    OR (share_files_media_browser = 1 AND id <> ' . $website->id . ')
			 ORDER BY name ASC
		');
        $websites = $DB->result();
        $html = array();
        $html[] = '<div id="navigate-media-browser">';
        $html[] = '	<form action="#"> ';
        // website selector
        $html[] = '		<input id="media_browser_website" type="hidden" />';
        $html[] = '		<a href="#" id="navigate_media_browser_website" class="uibutton"><img src="img/icons/silk/world.png" sprite="true" align="left" /> <span class="ui-icon ui-icon-triangle-1-s"></span></a>';
        $html[] = '		<div id="navigate_media_browser_website_list" class="ui-dialog ui-widget ui-corner-all">
		                    <div id="navigate_media_browser_website_list_wrapper">';
        foreach ($websites as $ws) {
            $html[] = '		    <div website_id="' . $ws->id . '" class="uibutton" title="' . htmlspecialchars($ws->name) . '">' . $ws->name . '</div>';
        }
        $html[] = '		    </div>
		                </div>';
        if ($user->permission("files.upload") == "true") {
            $html[] = ' 	<div id="navigate_media_browser_upload_button" class="uibutton"><img src="img/icons/silk/page_white_get.png" width="16" height="16" /></div>';
        }
        // resource type selector
        $html[] = ' 	<div id="navigate_media_browser_buttons" >';
        $html[] = '         <select id="media_browser_type" name="media_browser_type">';
        $html[] = '             <option value="image" selected="selected" data-class="ui-icon-image" id="nvmb-image">' . t(29, 'Images') . '</option>';
        $html[] = '             <option value="audio" data-class="ui-icon-volume-off" id="nvmb-audio">' . t(31, 'Audio') . '</option>';
        $html[] = '             <option value="video" data-class="ui-icon-video" id="nvmb-film">' . t(30, 'Video') . '</option>';
        $html[] = '             <option value="flash" data-class="ui-icon-script" id="nvmb-flash">' . t(186, 'Adobe Flash') . '</option>';
        $html[] = '             <option value="document" data-class="ui-icon-document" id="nvmb-doc">' . t(32, 'Documents') . '</option>';
        $html[] = '             <option value="folder" data-class="ui-icon-folder-collapsed" id="nvmb-folder" prefix="' . t(75, 'Path') . '">' . t(75, 'Path') . '</option>';
        //        $html[] = '             <option value="youtube" data-class="fa fa-youtube fa-align-center" id="nvmb-youtube">Youtube</option>';
        $html[] = '         </select>';
        $html[] = '         <select id="media_browser_order" name="media_browser_order">';
        $html[] = '             <option value="date_added_DESC" selected="selected" data-class="silk-sprite silk-time_go" id="nvmb-date_added_DESC">' . t(86, 'Date') . '</option>';
        $html[] = '             <option value="date_added_ASC" selected="selected" data-class="silk-sprite silk-time_go_inv" id="nvmb-date_added_ASC">' . t(86, 'Date') . '</option>';
        $html[] = '             <option value="name_ASC" data-class="silk-sprite silk-sort_ascending" id="nvmb-name_ASC">' . t(159, 'Name') . '</option>';
        $html[] = '             <option value="name_DESC" data-class="silk-sprite silk-sort_descending" id="nvmb-name_DESC">' . t(159, 'Name') . '</option>';
        $html[] = '         </select>';
        // search box
        $html[] = '		    <div id="media_browser_search"><input type="text" value="" placeholder="' . t(41, 'Search') . '…" name="media_browser_search" id="media_browser_search" style="width: 100px;"><img src="img/icons/silk/zoom.png" align="right" sprite="false" class="ui-corner-tr ui-corner-br" /></div>';
        $html[] = '</div>';
        $html[] = '		<div id="navigate_media_browser_items"></div>';
        $html[] = '		<input type="hidden" id="navigate_media_browser_folder_id" value="0" />';
        $html[] = '	</form>';
        $html[] = '</div>';
        $this->add_content(implode("", $html));
        $this->add_script('
			$.getScript("js/navigate_media_browser.js?r=' . $current_version->revision . '");
			$("#navigate_media_browser_upload_button").on("click", navigate_media_browser_files_uploader);
		');
        // extensions: add new contextmenu functions
        $extra_contextmenu_actions = array();
        $events->trigger("media_browser", "contextmenu", array('actions' => &$extra_contextmenu_actions));
        if (!empty($extra_contextmenu_actions)) {
            array_unshift($extra_contextmenu_actions, '<hr />');
        }
        $this->add_content('
            <ul id="contextmenu-files" style="display: none" class="ui-corner-all">
                <li id="contextmenu-files-download_link"><a href="#"><span class="ui-icon ui-icon-clipboard"></span>' . t(154, "Download link") . '</a></li>
                <li id="contextmenu-files-permissions"><a href="#"><span class="ui-icon ui-icon-key"></span>' . t(17, "Permissions") . '</a></li>
                <li id="contextmenu-files-duplicate"><a href="#"><span class="ui-icon ui-icon-copy"></span>' . t(477, "Duplicate") . '</a></li>
                <li id="contextmenu-files-focalpoint"><a href="#"><span class="ui-icon ui-icon-image"></span>' . t(540, "Focal point") . '</a></li>
                <li id="contextmenu-files-rename"><a href="#"><span class="ui-icon ui-icon-pencil"></span>' . t(500, 'Rename') . '</a></li>
                <li id="contextmenu-files-description"><a href="#"><span class="ui-icon ui-icon-comment"></span>' . t(334, 'Description') . '</a></li>
                ' . ($user->permission("files.delete") == "true" ? '<li id="contextmenu-files-delete"><a href="#"><span class="ui-icon ui-icon-trash"></span>' . t(35, 'Delete') . '</a></li>' : '') . '
                ' . implode("\n", $extra_contextmenu_actions) . '                
            </ul>
            <ul id="contextmenu-mediabrowser-folders" style="display: none;">
	            <li id="contextmenu-mediabrowser-folders-open" action="open"><a href="#"><span class="ui-icon ui-icon-arrowreturnthick-1-e"></span>' . t(499, "Open") . '</a></li>
	            <li id="contextmenu-mediabrowser-folders-rename" action="rename"><a href="#"><span class="ui-icon ui-icon-pencil"></span>' . t(500, "Rename") . '</a></li>
	            ' . ($user->permission("files.delete") == "true" ? '<li id="contextmenu-mediabrowser-folders-delete" action="delete"><a href="#"><span class="ui-icon ui-icon-trash"></span>' . t(35, 'Delete') . '</a></li>' : '') . '
            </ul>
            <ul id="contextmenu-mediabrowser"  style="display: none" class="ui-corner-all">
                <li id="contextmenu-mediabrowser-create_folder"><a href="#"><span class="ui-icon ui-icon-folder-collapsed"></span>' . t(561, "Create a new folder") . '</a></li>
            </ul>
            <div id="navigate-edit-folder" style=" display: none; ">
                <form action="#" onsubmit="return false;">
                    <input type="submit" value="" style=" display: none; " />
                    <div class="navigate-form-row">
                        <label>' . t(159, 'Name') . '</label>
                        ' . $naviforms->textfield('folder-name', '') . '
                    </div>
                    <div class="navigate-form-row">
                        <label>' . t(160, 'Type') . '</label>
                        ' . $naviforms->selectfield('folder-mime', array(0 => 'folder/generic', 1 => 'folder/images', 2 => 'folder/audio', 3 => 'folder/video', 4 => 'folder/flash', 5 => 'folder/documents'), array(0 => t(161, 'Generic'), 1 => t(29, 'Images'), 2 => t(31, 'Audio'), 3 => t(30, 'Video'), 4 => t(186, 'Adobe Flash'), 5 => t(32, 'Documents')), 'folder/generic') . '
                    </div>
                </form>
            </div>
			<div id="navigate-edit-file" style=" display: none; ">
	            <form action="#" onsubmit="return false;">
	                <input type="submit" value="" style=" display: none; " />
	                <div class="navigate-form-row">
	                    <label>' . t(159, 'Name') . '</label>
	                    ' . $naviforms->textfield('file-name', '') . '
	                </div>
	            </form>
			</div>
        ');
        // permissions dialog
        $permissions_dialog = array();
        $permissions_dialog[] = '<div class="navigate-form-row">';
        $permissions_dialog[] = '<label>' . t(364, 'Access') . '</label>';
        $permissions_dialog[] = $naviforms->selectfield('contextmenu-permissions-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')), 0, 'navigate_permissions_dialog_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in')));
        $permissions_dialog[] = '</div>';
        $webuser_groups = webuser_group::all_in_array();
        $permissions_dialog[] = '<div class="navigate-form-row" id="permissions-dialog-webuser-groups-field">';
        $permissions_dialog[] = '<label>' . t(506, "Groups") . '</label>';
        $permissions_dialog[] = $naviforms->multiselect('contextmenu-permissions-groups', array_keys($webuser_groups), array_values($webuser_groups), 0);
        $permissions_dialog[] = '<div style="clear: both; padding-bottom: 16px;"></div>';
        $permissions_dialog[] = '</div>';
        $this->add_script('
            function navigate_permissions_dialog_webuser_groups_visibility(access_value)
            {
                if(access_value==3)
                {
                    $("#permissions-dialog-webuser-groups-field").show();
                    if($("#contextmenu-permissions-dialog").is(":visible"))
                    {
                        $("#contextmenu-permissions-dialog").dialog("option", "width", "970");
                        $("#contextmenu-permissions-dialog").dialog("option", "height", "424");
                    }
                }
                else
                {
                    $("#permissions-dialog-webuser-groups-field").hide();
                    if($("#contextmenu-permissions-dialog").is(":visible"))
                    {
                        $("#contextmenu-permissions-dialog").dialog("option", "width", "620");
                        $("#contextmenu-permissions-dialog").dialog("option", "height", "200");
                    }
                }
            }

            navigate_permissions_dialog_webuser_groups_visibility(0);
        ');
        $permissions_dialog[] = '<div class="navigate-form-row">';
        $permissions_dialog[] = '<label>' . t(80, 'Permission') . '</label>';
        $permissions_dialog[] = $naviforms->selectfield('contextmenu-permissions-permission', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')), 0);
        $permissions_dialog[] = '</div>';
        $permissions_dialog[] = '<div class="navigate-form-row">';
        $permissions_dialog[] = '<label>' . t(65, 'Enabled') . '</label>';
        $permissions_dialog[] = $naviforms->checkbox('contextmenu-permissions-enabled', false);
        $permissions_dialog[] = '</div>';
        $this->add_content('
            <div id="contextmenu-permissions-dialog" style="display: none;">
                ' . implode("\n", $permissions_dialog) . '
            </div>
        ');
        // title/description(alt) dialog
        $description_dialog = array();
        $website_languages_selector = $website->languages();
        $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector);
        $description_dialog[] = '<div class="navigate-form-row">';
        $description_dialog[] = '<label>' . t(63, 'Languages') . '</label>';
        $description_dialog[] = $naviforms->buttonset('files_texts_language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);");
        $description_dialog[] = '</div>';
        foreach ($website->languages_list as $lang) {
            $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
            $description_dialog[] = '<div class="navigate-form-row" lang="' . $lang . '">';
            $description_dialog[] = '<label>' . t(67, 'Title') . ' ' . $language_info . '</label>';
            $description_dialog[] = $naviforms->textfield('contextmenu-description-dialog-title-' . $lang, "");
            $description_dialog[] = '</div>';
            $description_dialog[] = '<div class="navigate-form-row" lang="' . $lang . '">';
            $description_dialog[] = '<label>' . t(334, 'Description') . ' ' . $language_info . '</label>';
            $description_dialog[] = $naviforms->textfield('contextmenu-description-dialog-description-' . $lang, "");
            $description_dialog[] = '</div>';
        }
        $this->add_content('
            <div id="contextmenu-description-dialog" style="display: none;">
                ' . implode("\n", $description_dialog) . '
            </div>
        ');
        // plupload
        $this->add_content('<div id="navigate-media-browser-files-uploader"></div>');
        $this->add_script('
            plupload.addI18n(
            {
                "Select files" : "' . t(142, 'Select files') . '",
                "Add files to the upload queue and click the start button." : "' . t(143, 'Add files to the upload queue and click the start button.') . '",
                "Filename" : "' . t(144, 'Filename') . '",
                "Status" : "' . t(68, 'Status') . '",
                "Size" : "' . t(145, 'Size') . '",
                "Add files" : "' . t(146, 'Select files') . '",
                "Start upload":"' . t(147, 'Start upload') . '",
                "Stop current upload" : "' . t(148, 'Stop current upload') . '",
                "Start uploading queue" : "' . t(149, 'Start uploading queue') . '",
                "Drag files here." : "' . t(150, 'Drag files here.') . '",
                "Uploaded %d/%d files": "' . t(338, 'Uploaded %d/%d files') . '",
                "N/A": "' . t(339, 'N/A') . '",
                "File extension error.": "' . t(340, 'File extension error') . '",
                "File size error.": "' . t(341, 'File size error') . '",
                "Init error.": "' . t(342, 'Init error') . '",
                "HTTP Error.": "' . t(343, 'HTTP Error') . '",
                "Security error.": "' . t(344, 'Security error') . '",
                "Generic error.": "' . t(345, 'Generic error') . '",
                "IO error.": "' . t(346, 'IO error') . '",
                "Stop Upload": "' . t(347, 'Stop upload') . '",
                "Add Files": "' . t(348, 'Add files') . '",
                "Start Upload": "' . t(349, 'Start upload') . '",
                "%d files queued": "' . t(350, '%d files queued') . '"
            });
        ');
        $this->add_script('
            function navigate_media_browser_files_uploader()
            {
                var plupload_instance = $("#navigate-media-browser-files-uploader").plupload(
                {
                    // General settings
                    runtimes : "html5,flash,silverlight",
                    url : "' . NAVIGATE_URL . '/navigate_upload.php?session_id=' . session_id() . '",
                    max_file_size : "' . NAVIGATE_UPLOAD_MAX_SIZE . 'mb",
                    chunk_size : "384kb",
                    unique_names: false,
                    sortable: false,
                    rename: true,
                    preinit: attachCallbacks,
                    flash_swf_url: "' . NAVIGATE_URL . '/lib/external/plupload/js/Moxie.swf",
                    silverlight_xap_url: "' . NAVIGATE_URL . '/lib/external/plupload/js/Moxie.xap"
                });

                function attachCallbacks(Uploader)
                {
                    Uploader.bind("FileUploaded", function(Up, File, Response)
                    {
                        var media = $("select[name=media_browser_type]").val();
                        var parent = 0;
                        if(media=="folder")
                            parent = navigate_media_browser_parent;

                        $.ajax(
                        {
                            async: true,
                            url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=files&act=json&op=upload",
                            success: function(data)
                            {

                            },
                            type: "post",
                            dataType: "json",
                            data: {
                                tmp_name: "{{BASE64}}",
                                name: File.name,
                                parent: parent
                            }
                        });
                    });
                }

                $("#navigate-media-browser-files-uploader").dialog(
                {
                    title: "' . t(142, 'Select files') . '",
                    height: 400,
                    width: 600,
                    modal: true,
                    close: function()
                    {
                       navigate_media_browser_reload();
                    }
                });

                $(".plupload_wrapper").removeClass("plupload_scroll");

                $("#navigate-media-browser-files-uploader").on("mouseenter", function()
                {
                    $("div.plupload input").css("z-index","99999");
                });
			}
        ');
    }
示例#11
0
function nvweb_liveedit($vars = array())
{
    global $website;
    global $current;
    global $DB;
    global $lang;
    global $theme;
    global $session;
    global $webuser;
    $out = array();
    $url = '';
    if (!empty($_SESSION['APP_USER#' . APP_UNIQUE])) {
        switch ($current['type']) {
            case 'item':
                $url = NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=10&act=2&id=' . $current['object']->id . '&tab=2&tab_language=' . $current['lang'] . '&quickedit=true&wid=' . $website->id;
                break;
            case 'structure':
                // load the first item
                $DB->query('	SELECT id 
								  FROM nv_items
								 WHERE category = ' . protect($current['category']) . '
								   AND permission < 2
								   AND website = ' . $website->id . '
						   ');
                $rs = $DB->first();
                $url = NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=10&act=2&id=' . $rs->id . '&tab=2&quickedit=true&wid=' . $website->id;
                break;
            default:
        }
        if (empty($lang)) {
            $lang = new language();
            $lang->load($current['lang']);
        }
        // add jQuery if has not already been loaded in the template
        $includes = array();
        if (strpos($vars['nvweb_html'], 'jquery') === false) {
            $includes[] = '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>';
        }
        $includes[] = '<script language="javascript" type="text/javascript" src="' . NAVIGATE_URL . '/js/navigate_liveedit.js"></script>';
        $includes[] = '<link rel="stylesheet" type="text/css" href="' . NAVIGATE_URL . '/css/tools/navigate_liveedit.css" />';
        nvweb_after_body('html', implode("\n", $includes) . "\n");
        $comments = comment::pending_count();
        // TODO: check user permissions before allowing "Create", "Edit" and other functions
        $out[] = '<div id="navigate_liveedit_bar" style="display: none;">';
        $out[] = '  <a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '" target="_blank"><img src="' . NAVIGATE_URL . '/img/navigatecms/navigatecms_logo_52x24_white.png" width="52" height="24" /></a>';
        $out[] = '
            <div>
                <ul class="navigate_liveedit_bar_menu">
                    <li><a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=blocks&act=create" target="_blank"><img src="' . NAVIGATE_URL . '/img/icons/silk/brick.png" /> ' . t(437, 'Block') . '</a></li>
                    <li><a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=structure&act=create" target="_blank"><img src="' . NAVIGATE_URL . '/img/icons/silk/sitemap_color.png" /> ' . t(479, 'Structure entry') . '</a></li>
                    <li><a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=create" target="_blank"><img src="' . NAVIGATE_URL . '/img/icons/silk/page.png" /> ' . t(180, 'Item') . '</a></li>
                </ul>
                <a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=create" target="_blank"><img src="' . NAVIGATE_URL . '/img/icons/silk/page_add.png" /> ' . t(38, 'Create') . '</a>
            </div>
        ';
        $out[] = '  <a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=comments" target="_blank"><img src="' . NAVIGATE_URL . '/img/icons/silk/comments.png" /> ' . $comments . '</a>';
        //$out[] = '  <div id="navigate_liveedit_bar_liveedit_button"><img src="'.NAVIGATE_URL.'/img/icons/silk/shape_square_select.png" /> '.t(458, 'Edit in place').'</div>';
        $out[] = '  <div id="navigate_liveedit_bar_hide_button" style=" float: right; " title="' . t(554, 'Hide') . '">x</div>';
        if (!empty($url)) {
            $out[] = '<a style="float: right;" href="' . $url . '" target="_blank">
                        <img src="' . NAVIGATE_URL . '/img/icons/silk/application_double.png" />
                        ' . t(456, 'Edit in Navigate CMS') . '
                      </a>';
        }
        $out[] = '  <div id="navigate_liveedit_bar_information_button" style=" float: right; "><img src="' . NAVIGATE_URL . '/img/icons/silk/information.png" /> ' . t(457, 'Information') . '</div>';
        $page_type = array('item' => t(180, 'Item'), 'structure' => t(16, 'Structure'));
        $page_type = $page_type[$current['type']];
        $out[] = '  <div id="navigate_liveedit_bar_information">';
        $out[] = '      <span>' . t(368, 'Theme') . ' <strong>' . $theme->title . '</strong></span>';
        $out[] = '      <span>' . t(79, 'Template') . ' <strong>' . $theme->template_title($current['template'], false) . '</strong></span>';
        $out[] = '      <span>' . t(160, 'Type') . ' <strong>' . $page_type . '</strong></span>';
        $out[] = '      <span>ID <strong>' . $current['id'] . '</strong></span>';
        $out[] = '      <span>' . t(46, 'Language') . ' <strong>' . language::name_by_code($session['lang']) . '</strong></span>';
        $out[] = '      <span>' . t(647, 'Webuser') . ' <strong>' . (empty($webuser->id) ? '(' . mb_strtolower(t(581, "None")) . ')' : $webuser->username . ' (' . $webuser->id . ')') . '</strong></span>';
        /* elements associated to this structure entry
                if($current['type']=='structure')
                {
                    if(empty($current['structure_elements']))
                        $current['structure_elements'] = $current['object']->elements();
        
                    $se_ids = array();
                    for($se=0; $se < count($current['structure_elements']); $se++)
                        $se_ids[] = $current['structure_elements'][$se]->id;
        
                    if(!empty($se_ids))
                        $out[] = '      <span>'.t(22, 'Elements').' <strong>'.implode(', ', $se_ids).'</strong></span>';
                }
                */
        $out[] = '  </div>';
        $out[] = '</div>';
    }
    return implode("\n", $out);
}
示例#12
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();
}