Пример #1
0
function profiles_form($item)
{
    global $layout;
    global $current_version;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item->id)) {
        $navibars->title(t(243, 'Profiles') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(243, 'Profiles') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    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>'));
        $layout->add_script('
            function navigate_delete_dialog()
            {
                navigate_confirmation_dialog(
                    function() { window.location.href = "?fid=profiles&act=delete&id=' . $item->id . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=profiles&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=profiles&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(159, 'Name') . '</label>', $naviforms->textfield('name', $item->name)));
    $navibars->add_tab_content_row(array('<label>' . t(334, 'Description') . '</label>', $naviforms->textarea('description', $item->description)));
    $menus = menu::load_all_menus();
    $sortable_profile = array();
    $sortable_unassigned = array();
    $sortable_profile[] = '<ul id="sortable_profile" class="connectedSortable">';
    $sortable_unassigned[] = '<ul id="sortable_unassigned" class="connectedSortable">';
    // already included menus on the profile
    foreach ($item->menus as $m) {
        foreach ($menus as $menu) {
            if ($menu->id == $m) {
                if ($menu->enabled == '1') {
                    $sortable_profile[] = '<li class="ui-state-highlight" value="' . $menu->id . '" title="' . $menu->notes . '"><img src="' . NAVIGATE_URL . '/' . $menu->icon . '" align="absmiddle" /> ' . t($menu->lid, $menu->lid) . '</li>';
                } else {
                    $sortable_profile[] = '<li class="ui-state-highlight ui-state-disabled" value="' . $menu->id . '" title="' . $menu->notes . '"><img src="' . NAVIGATE_URL . '/' . $menu->icon . '" align="absmiddle" /> ' . t($menu->lid, $menu->lid) . '</li>';
                }
            }
        }
    }
    // the other menus not included on the profile
    if (is_array($menus)) {
        foreach ($menus as $menu) {
            if (!in_array($menu->id, $item->menus)) {
                if ($menu->enabled == '1') {
                    $sortable_unassigned[] = '<li class="ui-state-default" value="' . $menu->id . '" title="' . $menu->notes . '"><img src="' . NAVIGATE_URL . '/' . $menu->icon . '" align="absmiddle" /> ' . t($menu->lid, $menu->lid) . '</li>';
                } else {
                    $sortable_unassigned[] = '<li class="ui-state-default ui-state-disabled" value="' . $menu->id . '" title="' . $menu->notes . '"><img src="' . NAVIGATE_URL . '/' . $menu->icon . '" align="absmiddle" /> ' . t($menu->lid, $menu->lid) . '</li>';
                }
            }
        }
    }
    $sortable_profile[] = '</ul>';
    $sortable_unassigned[] = '</ul>';
    //$navibars->add_tab_content('<pre>'.print_r($item->menus, true).'</pre>');
    $navibars->add_tab_content($naviforms->hidden("profile-menu", implode('#', $item->menus)));
    $navibars->add_tab_content_row(array('<label>' . t(244, 'Menus') . '</label>', implode("\n", $sortable_profile), implode("\n", $sortable_unassigned)));
    $layout->add_script('
		$("#sortable_profile").sortable({
				connectWith: ".connectedSortable",
				receive: function(event, ui)
				{
					$(ui.item).addClass("ui-state-highlight");
					$(ui.item).removeClass("ui-state-default");
				},
				update: function()
				{
					$("#profile-menu").val("");
					$("#sortable_profile li").each(function()
					{
						$("#profile-menu").val($("#profile-menu").val() + $(this).attr("value") + "#");					
					});
				}
			}).disableSelection();
			
		$("#sortable_unassigned").sortable({
				connectWith: ".connectedSortable",
				receive: function(event, ui)
				{
					$(ui.item).addClass("ui-state-default");
					$(ui.item).removeClass("ui-state-highlight");					
				}
			}).disableSelection();			
			
	');
    $websites = website::all();
    $navibars->add_tab(t(17, "Permissions"));
    $navibars->add_tab_content($naviforms->hidden('navigate_permissions_changes', ''));
    $scripts_after_load = array();
    $ws_tabs = '<div id="navigate-permissions-websites-tabs"><ul>';
    foreach ($websites as $ws_id => $ws_name) {
        $ws_tabs .= '<li><a href="#navigate-permissions-websites-tab-' . $ws_id . '">' . $ws_name . '</a></li>';
    }
    $ws_tabs .= '</ul>';
    foreach ($websites as $ws_id => $ws_name) {
        $rows = nvweb_permissions_rows($ws_id, 'profile', $item->id);
        $ws_tabs .= '<div id="navigate-permissions-websites-tab-' . $ws_id . '" data-website="' . $ws_id . '">';
        $ws_tabs .= '<div id="permissions_list_website_' . $ws_id . '">';
        $ws_tabs .= '<table class="treeTable ui-corner-all">';
        $ws_tabs .= '
            <thead>
                <tr class="ui-state-default ui-th-column">
                    <th width="25%">' . t(159, 'Name') . '</th>
                    <th width="13%">' . t(467, 'Scope') . '</th>
                    <th width="12%">' . t(160, 'Type') . '</th>
                    <th width="50%">' . t(193, 'Value') . '</th>
                </tr>
            </thead>
        ';
        for ($r = 0; $r < count($rows); $r++) {
            $ws_tabs .= '<tr id="' . $rows[$r][0] . '">';
            $ws_tabs .= '    <td>' . $rows[$r][1] . '</td>';
            $ws_tabs .= '    <td>' . $rows[$r][2] . '</td>';
            $ws_tabs .= '    <td>' . $rows[$r][3] . '</td>';
            $ws_tabs .= '    <td>' . $rows[$r][4] . '</td>';
            $ws_tabs .= '</tr>';
        }
        $ws_tabs .= '</table>';
        $ws_tabs .= '</div>';
        $ws_tabs .= '</div>';
        $layout->add_script('
			$("#permissions_list_website_' . $ws_id . '").data("website", ' . $ws_id . ');            
		');
        $scripts_after_load[] = 'navigate_permissions_list_callback($("#permissions_list_website_' . $ws_id . '"));';
        $navibars->add_content(navigate_permissions_structure_selector($ws_id, $ws_name));
    }
    $ws_tabs .= '</div>';
    $navibars->add_tab_content($ws_tabs);
    $layout->add_script('
		$("#navigate-permissions-websites-tabs").tabs({
			heightStyle: "fill",
			activate: function() {
				$(window).trigger("resize");
			}
		});
	');
    $layout->add_script('
		$.getScript("lib/packages/permissions/permissions.js?r=' . $current_version->revision . '", function()
		{
			navigate_window_resize();
			' . implode("\n", $scripts_after_load) . '
		});
	');
    return $navibars->generate();
}
Пример #2
0
function users_form($item)
{
    global $DB;
    global $layout;
    global $current_version;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item->id)) {
        $navibars->title(t(15, 'Users') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(15, 'Users') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    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(35, 'Delete') . '": function() {
									$(this).dialog("close");
									window.location.href = "?fid=users&act=4&id=' . $item->id . '";
								},
								"' . t(58, 'Cancel') . '": function() {
									$(this).dialog("close");
								}
							}
						});';
        $delete_html[] = '}';
        $delete_html[] = '</script>';
        $navibars->add_content(implode("\n", $delete_html));
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=users&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=users&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(1, 'User') . '</label>', $naviforms->textfield('user-username', $item->username)));
    $navibars->add_tab_content_row(array('<label>' . t(2, 'Password') . '</label>', '<input type="password" name="user-password" value="" size="32" autocomplete="off" />', '<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=user-password]").val("");
		}, 10);
	');
    $navibars->add_tab_content_row(array('<label>' . t(44, 'E-Mail') . '</label>', '<input type="text" name="user-email" value="' . $item->email . '" size="64" />'));
    // Profile selector
    $DB->query('SELECT id, name FROM nv_profiles');
    $data = $DB->result();
    $select = $naviforms->select_from_object_array('user-profile', $data, 'id', 'name', $item->profile);
    $navibars->add_tab_content_row(array('<label>' . t(45, 'Profile') . '</label>', $select));
    // Language selector
    $DB->query('SELECT code, name FROM nv_languages WHERE nv_dictionary != ""');
    $data = $DB->result();
    $select = $naviforms->select_from_object_array('user-language', $data, 'code', 'name', $item->language);
    $navibars->add_tab_content_row(array('<label>' . t(46, 'Language') . '</label>', $select));
    $timezones = property::timezones();
    if (empty($item->timezone)) {
        $item->timezone = date_default_timezone_get();
    }
    $navibars->add_tab_content_row(array('<label>' . t(97, 'Timezone') . '</label>', $naviforms->selectfield("user-timezone", array_keys($timezones), array_values($timezones), $item->timezone)));
    // Decimal separator
    $data = array(0 => json_decode('{"code": ",", "name": ", ---> 1234,25"}'), 1 => json_decode('{"code": ".", "name": ". ---> 1234.25"}'), 2 => json_decode('{"code": "\'", "name": "\' ---> 1234\'25"}'));
    $select = $naviforms->select_from_object_array('user-decimal_separator', $data, 'code', 'name', $item->decimal_separator);
    $navibars->add_tab_content_row(array('<label>' . t(49, 'Decimal separator') . '</label>', $select));
    // Thousands separator
    $data = array(0 => json_decode('{"code": "", "name": "(' . strtolower(t(581, "None")) . ') ---> 1234567"}'), 1 => json_decode('{"code": ",", "name": ", ---> 1,234,567"}'), 2 => json_decode('{"code": ".", "name": ". ---> 1.234.567"}'));
    $select = $naviforms->select_from_object_array('user-thousands_separator', $data, 'code', 'name', $item->thousands_separator);
    $navibars->add_tab_content_row(array('<label>' . t(644, 'Thousands separator') . '</label>', $select));
    // Date format
    $data = array(0 => json_decode('{"code": "Y-m-d H:i", "name": "' . date(Y) . '-12-31 23:59"}'), 1 => json_decode('{"code": "d-m-Y H:i", "name": "31-12-' . date(Y) . ' 23:59"}'), 2 => json_decode('{"code": "m-d-Y H:i", "name": "12-31-' . date(Y) . ' 23:59"}'), 3 => json_decode('{"code": "Y/m/d H:i", "name": "' . date(Y) . '/12/31 23:59"}'), 4 => json_decode('{"code": "d/m/Y H:i", "name": "31/12/' . date(Y) . ' 23:59"}'), 5 => json_decode('{"code": "m/d/Y H:i", "name": "12/31/' . date(Y) . ' 23:59"}'));
    $layout->add_script('
        $("#user-decimal_separator,#user-thousands_separator").on("change", function()
        {
            $("#user-decimal_separator").parent().find("label:first").removeClass("ui-state-error");
            $("#user-thousands_separator").parent().find("label:first").removeClass("ui-state-error");
        
            if($("#user-decimal_separator").val()==$("#user-thousands_separator").val())
            {
                $("#user-decimal_separator").parent().find("label:first").addClass("ui-state-error");
                $("#user-thousands_separator").parent().find("label:first").addClass("ui-state-error");
            }
        });
        
        $("#user-decimal_separator").trigger("change"); // force checking on load
    ');
    $select = $naviforms->select_from_object_array('user-date_format', $data, 'code', 'name', $item->date_format);
    $navibars->add_tab_content_row(array('<label>' . t(50, 'Date format') . '</label>', $select));
    $navibars->add_tab_content($naviforms->hidden('user-skin', 'cupertino'));
    $navibars->add_tab_content_row(array('<label>' . t(47, 'Blocked') . '</label>', $naviforms->checkbox('user-blocked', $item->blocked)));
    $navibars->add_tab(t(241, "Web sites"));
    $navibars->add_tab_content_row(array('<label>' . t(612, "Manages all websites") . '</label>', $naviforms->checkbox("user-all-websites", empty($item->websites))));
    $websites = website::all();
    if (empty($websites)) {
        $websites = array();
    }
    $navibars->add_tab_content_row(array('<label>' . t(405, "Selection") . '</label>', $naviforms->multiselect('user-websites', array_keys($websites), array_values($websites), $item->websites)), "user-websites-selector", 'style="display: none; padding-bottom: 16px; "');
    $layout->add_script('
		$("#user-all-websites").on("change", function()
		{
			$("#user-websites-selector").hide();
			if(!$(this).is(":checked"))
				$("#user-websites-selector").show();
		});
		$("#user-all-websites").trigger("change");
	');
    $navibars->add_tab(t(17, "Permissions"));
    $navibars->add_tab_content($naviforms->hidden('navigate_permissions_changes', ''));
    $ws_tabs = '<div id="navigate-permissions-websites-tabs"><ul>';
    foreach ($websites as $ws_id => $ws_name) {
        $ws_tabs .= '<li><a href="#navigate-permissions-websites-tab-' . $ws_id . '">' . $ws_name . '</a></li>';
    }
    $ws_tabs .= '</ul>';
    foreach ($websites as $ws_id => $ws_name) {
        $rows = nvweb_permissions_rows($ws_id, 'user', $item->id);
        $ws_tabs .= '<div id="navigate-permissions-websites-tab-' . $ws_id . '" data-website="' . $ws_id . '">';
        $ws_tabs .= '<div id="permissions_list_website_' . $ws_id . '">';
        $ws_tabs .= '<table class="treeTable ui-corner-all">';
        $ws_tabs .= '
            <thead>
                <tr class="ui-state-default ui-th-column">
                    <th width="25%">' . t(159, 'Name') . '</th>
                    <th width="13%">' . t(467, 'Scope') . '</th>
                    <th width="12%">' . t(160, 'Type') . '</th>
                    <th width="50%">' . t(193, 'Value') . '</th>
                </tr>
            </thead>
        ';
        for ($r = 0; $r < count($rows); $r++) {
            $ws_tabs .= '<tr id="' . $rows[$r][0] . '">';
            $ws_tabs .= '    <td>' . $rows[$r][1] . '</td>';
            $ws_tabs .= '    <td>' . $rows[$r][2] . '</td>';
            $ws_tabs .= '    <td>' . $rows[$r][3] . '</td>';
            $ws_tabs .= '    <td>' . $rows[$r][4] . '</td>';
            $ws_tabs .= '</tr>';
        }
        $ws_tabs .= '</table>';
        $ws_tabs .= '</div>';
        $ws_tabs .= '</div>';
        $layout->add_script('
			$("#permissions_list_website_' . $ws_id . '").data("website", ' . $ws_id . ');            
		');
        $scripts_after_load[] = 'navigate_permissions_list_callback($("#permissions_list_website_' . $ws_id . '"));';
        $navibars->add_content(navigate_permissions_structure_selector($ws_id, $ws_name));
    }
    $ws_tabs .= '</div>';
    $navibars->add_tab_content($ws_tabs);
    $layout->add_script('
		$("#navigate-permissions-websites-tabs").tabs({
			heightStyle: "fill",
			activate: function() {
				$(window).trigger("resize");
			}
		});
	');
    $layout->add_script('
		$.getScript("lib/packages/permissions/permissions.js?r=' . $current_version->revision . '", function()
		{
		    navigate_window_resize();
			' . implode("\n", $scripts_after_load) . '
		});
	');
    return $navibars->generate();
}