public function load_from_post()
 {
     global $theme;
     global $user;
     $ws_theme = $theme;
     if ($this->theme != $theme->name) {
         $ws_theme = new theme();
         $ws_theme->load($this->theme);
     }
     $this->name = $_REQUEST['title'];
     $this->protocol = $_REQUEST['protocol'];
     $this->subdomain = $_REQUEST['subdomain'];
     $this->domain = $_REQUEST['domain'];
     $this->folder = $_REQUEST['folder'];
     $this->word_separator = $_REQUEST['word_separator'];
     $this->redirect_to = $_REQUEST['redirect_to'];
     $this->wrong_path_action = $_REQUEST['wrong_path_action'];
     $this->wrong_path_redirect = $_REQUEST['wrong_path_redirect'];
     $this->empty_path_action = $_REQUEST['empty_path_action'];
     $this->date_format = $_REQUEST['date_format'];
     $this->tinymce_css = $_REQUEST['tinymce_css'];
     $this->resize_uploaded_images = intval($_REQUEST['resize_uploaded_images']);
     $this->comments_enabled_for = intval($_REQUEST['comments_enabled_for']);
     $this->comments_default_moderator = $_REQUEST['comments_default_moderator'];
     $this->share_files_media_browser = intval($_REQUEST['share_files_media_browser']);
     $this->additional_scripts = $_REQUEST['additional_scripts'];
     if (empty($_REQUEST['homepage_from_structure'])) {
         $this->homepage = $_REQUEST['homepage'];
     }
     $this->permission = intval($_REQUEST['permission']);
     $this->default_timezone = $_REQUEST['default_timezone'];
     $this->mail_mailer = $_REQUEST['mail_mailer'][0];
     $this->mail_server = $_REQUEST['mail_server'];
     $this->mail_port = intval($_REQUEST['mail_port']);
     $this->mail_security = intval($_REQUEST['mail_security']);
     $this->mail_user = $_REQUEST['mail_user'];
     $this->mail_address = $_REQUEST['mail_address'];
     if (!empty($_REQUEST['mail_password'])) {
         $this->mail_password = $_REQUEST['mail_password'];
     }
     $ce = explode("\n", $_REQUEST['contact_emails']);
     $this->contact_emails = array();
     foreach ($ce as $cemail) {
         $cemail = trim($cemail);
         if (empty($cemail)) {
             continue;
         }
         $this->contact_emails[] = $cemail;
     }
     $this->favicon = intval($_REQUEST['website-favicon']);
     // languages and locales
     $this->languages = array();
     $this->languages_published = array();
     for ($li = 0; $li < count($_REQUEST['language-id']); $li++) {
         $variant = trim($_REQUEST['language-variant-code'][$li]);
         $code = $_REQUEST['language-id'][$li];
         if (!empty($variant)) {
             $code .= '_' . $variant;
         }
         $this->languages[$code] = array('language' => $_REQUEST['language-id'][$li], 'variant' => $variant, 'code' => $code, 'system_locale' => $_REQUEST['language-locale'][$li]);
         $this->languages_published[] = $_REQUEST['language-published'][$li] == '1' ? $code : '';
     }
     // Website metatags
     $this->metatag_description = array();
     $this->metatag_keywords = array();
     $this->metatags = array();
     foreach ($this->languages as $language) {
         $lcode = $language['code'];
         $this->metatag_description[$lcode] = $_REQUEST['metatag_description-' . $lcode];
         $this->metatag_keywords[$lcode] = $_REQUEST['metatag_keywords-' . $lcode];
         $this->metatags[$lcode] = $_REQUEST['metatags-' . $lcode];
     }
     // website aliases
     $this->aliases = array();
     if (empty($_POST['website-aliases-alias'])) {
         $_POST['website-aliases-alias'] = array();
     }
     foreach ($_POST['website-aliases-alias'] as $key => $value) {
         $value = trim($value);
         if (!empty($value)) {
             $value_real = trim($_POST['website-aliases-real'][$key]);
             if (!empty($value_real)) {
                 $this->aliases[$value] = $value_real;
             }
         }
     }
     $this->theme_options = array();
     // Theme style (common property)
     $this->theme_options['style'] = $_REQUEST['property-style'];
     if (!empty($ws_theme->options)) {
         foreach ($ws_theme->options as $theme_option) {
             // get property info
             $property = new property();
             $property->load_from_theme($theme_option, NULL, NULL, NULL, $this->id);
             $value = '';
             switch ($property->type) {
                 case 'text':
                 case 'textarea':
                 case 'rich_textarea':
                     // multilang
                     $value = array();
                     if (!is_array($this->languages_list)) {
                         $this->languages_list = array();
                     }
                     foreach ($this->languages_list as $lang) {
                         $value[$lang] = $_REQUEST['property-' . $theme_option->id . '-' . $lang];
                     }
                     break;
                 case 'link':
                     // multilang and title+link
                     $value = array();
                     foreach ($this->languages_list as $lang) {
                         $value[$lang] = $_REQUEST['property-' . $theme_option->id . '-' . $lang . '-link'] . '##' . $_REQUEST['property-' . $theme_option->id . '-' . $lang . '-title'];
                     }
                     break;
                 case 'date':
                 case 'datetime':
                     $value = core_date2ts($_REQUEST['property-' . $theme_option->id]);
                     break;
                 case 'moption':
                     $value = implode(',', $_REQUEST['property-' . $theme_option->id]);
                     break;
                 case 'coordinates':
                     $value = $_REQUEST['property-' . $theme_option->id . '-latitude'] . '#' . $_REQUEST['property-' . $theme_option->id . '-longitude'];
                     break;
                 case 'decimal':
                     $value = $_REQUEST['property-' . $theme_option->id];
                     $value = core_string2decimal($value);
                     break;
                 default:
                     // direct value
                     $value = $_REQUEST['property-' . $theme_option->id];
             }
             $this->theme_options[$theme_option->id] = $value;
         }
     }
 }
Beispiel #2
0
function run()
{
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new block();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    // translation of request search & order fields
                    switch ($_REQUEST['searchField']) {
                        case 'id':
                            $_REQUEST['searchField'] = 'b.id';
                            break;
                        case 'type':
                            $_REQUEST['searchField'] = 'b.type';
                            break;
                        case 'title':
                            $_REQUEST['searchField'] = 'd.text';
                            break;
                        case 'category':
                            $_REQUEST['searchField'] = 'b.category';
                            break;
                        case 'dates':
                            $_REQUEST['searchField'] = 'b.date_published';
                            break;
                        case 'enabled':
                            $_REQUEST['searchField'] = 'b.enabled';
                            break;
                        case 'date_modified':
                        default:
                            $_REQUEST['searchField'] = 'b.date_modified';
                    }
                    if ($_REQUEST['sidx'] == 'dates') {
                        $_REQUEST['sidx'] = 'b.date_published';
                    }
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = " 1=1 ";
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $where .= navitable::jqgridsearch($_REQUEST['filters']);
                                // special case
                                if (strpos($where, 'title LIKE') !== false) {
                                    $where = substr_replace($where, 'd.text', strpos($where, 'title LIKE'), 5);
                                }
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $sql = ' SELECT SQL_CALC_FOUND_ROWS b.*, 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 ' . $where . '
							    AND b.website = ' . $website->id . ' 
						   ORDER BY ' . $orderby . ' 
							  LIMIT ' . $max . '
							 OFFSET ' . $offset;
                    if (!$DB->query($sql, 'array')) {
                        throw new Exception($DB->get_last_error());
                    }
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    $block_types = block::types();
                    $block_types_list = array();
                    for ($i = 0; $i < count($block_types); $i++) {
                        if (is_numeric($block_types[$i]['id'])) {
                            $block_types_list[$block_types[$i]['code']] = $block_types[$i]['title'];
                        } else {
                            $block_types_list[$block_types[$i]['id']] = $block_types[$i]['title'];
                        }
                    }
                    $dataset = grid_notes::summary($dataset, 'block', 'id');
                    // we need to format the values and retrieve the needed strings from the dictionary
                    $out = array();
                    for ($i = 0; $i < count($dataset); $i++) {
                        if (empty($dataset[$i])) {
                            continue;
                        }
                        $access = array(0 => '<img src="img/icons/silk/page_white_go.png" align="absmiddle" title="' . t(254, 'Everybody') . '" />', 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") . '" />');
                        if (empty($dataset[$i]['date_published'])) {
                            $dataset[$i]['date_published'] = '&infin;';
                        } else {
                            $dataset[$i]['date_published'] = core_ts2date($dataset[$i]['date_published'], false);
                        }
                        if (empty($dataset[$i]['date_unpublish'])) {
                            $dataset[$i]['date_unpublish'] = '&infin;';
                        } else {
                            $dataset[$i]['date_unpublish'] = core_ts2date($dataset[$i]['date_unpublish'], false);
                        }
                        if ($dataset[$i]['category'] > 0) {
                            $dataset[$i]['category'] = $DB->query_single('text', 'nv_webdictionary', ' 	node_type = "structure" AND
                                    node_id = "' . $dataset[$i]['category'] . '" AND
                                    subtype = "title" AND
                                    lang = "' . $website->languages_list[0] . '"
                                ');
                        }
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $block_types_list[$dataset[$i]['type']], 2 => '<div class="list-row" data-enabled="' . $dataset[$i]['enabled'] . '">' . $dataset[$i]['title'] . '</div>', 3 => $dataset[$i]['date_published'] . ' - ' . $dataset[$i]['date_unpublish'], 4 => $access[$dataset[$i]['access']], 5 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />', 6 => $dataset[$i]['_grid_notes_html']);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            session_write_close();
            exit;
            break;
        case 'load':
        case 'edit':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('block', $item->id);
                    $id = $item->id;
                    // set block order
                    if (!empty($item->type) && !empty($_REQUEST['blocks-order'])) {
                        block::reorder($item->type, $_REQUEST['blocks-order'], $_REQUEST['blocks-order-fixed']);
                    }
                    unset($item);
                    $item = new block();
                    $item->load($id);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST));
            } else {
                users_log::action($_REQUEST['fid'], $item->id, 'load', $item->dictionary[$website->languages_list[0]]['title']);
            }
            $out = blocks_form($item);
            break;
        case 'delete':
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = blocks_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = blocks_form($item);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->dictionary[$website->languages_list[0]]['title']);
            }
            break;
        case 'path':
        case 5:
            // search an existing path
            $DB->query('SELECT path as id, path as label, path as value
						  FROM nv_paths
						 WHERE path LIKE ' . protect('%' . $_REQUEST['term'] . '%') . ' 
						   AND website = ' . $website->id . '
				      ORDER BY path ASC
					     LIMIT 10', 'array');
            echo json_encode($DB->result());
            core_terminate();
            break;
        case 'block_groups_list':
            $out = block_groups_list();
            break;
        case 'block_groups_json':
            // block groups: json data retrieval
            $page = intval($_REQUEST['page']);
            $max = intval($_REQUEST['rows']);
            $offset = ($page - 1) * $max;
            list($rs, $total) = block_group::paginated_list($offset, $max, $_REQUEST['sidx'], $_REQUEST['sord']);
            $rs = grid_notes::summary($rs, 'block_group', 'id');
            // translate $rs to an array of ordered fields
            foreach ($rs as $row) {
                if (substr($row['blocks'], 0, 2) == 'a:') {
                    // nv < 2.1
                    $row['blocks'] = mb_unserialize($row['blocks']);
                } else {
                    // nv >= 2.1
                    $row['blocks'] = json_decode($row['blocks'], true);
                }
                $dataset[] = array('id' => $row['id'], 'code' => $row['code'], 'title' => $row['title'], 'blocks' => count($row['blocks']), 'notes' => $row['_grid_notes_html']);
            }
            navitable::jqgridJson($dataset, $page, $offset, $max, $total, 'id');
            session_write_close();
            exit;
            break;
        case 'block_group_edit':
            $item = new block_group();
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->title, json_encode($_REQUEST));
            } else {
                if (!empty($_REQUEST['id'])) {
                    users_log::action($_REQUEST['fid'], $item->id, 'edit', $item->title);
                }
            }
            $out = block_group_form($item);
            break;
        case 'block_group_delete':
            $item = new block_group();
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = block_groups_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = block_group_form($item);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->title);
            }
            break;
        case 'block_types_list':
            $out = blocks_types_list();
            break;
        case 'block_types_json':
            // block types: json data retrieval
            $page = intval($_REQUEST['page']);
            $max = intval($_REQUEST['rows']);
            $offset = ($page - 1) * $max;
            $rs = block::types($_REQUEST['sidx'], $_REQUEST['sord']);
            $block_modes = block::modes();
            // translate $rs to an array of ordered fields
            foreach ($rs as $row) {
                $dataset[] = array('id' => $row['id'], 'type' => $block_modes[$row['type']], 'code' => $row['code'], 'title' => $row['title'], 'width' => $row['width'], 'height' => $row['height']);
            }
            $total = count($dataset);
            navitable::jqgridJson($dataset, $page, $offset, $max, $total, 'id');
            session_write_close();
            exit;
            break;
        case 'block_type_edit':
        case 82:
            // edit/create block type
            $item = NULL;
            $position = NULL;
            $max_id = 0;
            $dataset = block::custom_types();
            for ($i = 0; $i < count($dataset); $i++) {
                if ($dataset[$i]['id'] > $max_id) {
                    $max_id = $dataset[$i]['id'];
                }
                if ($dataset[$i]['id'] == $_REQUEST['id']) {
                    $item = $dataset[$i];
                    $position = $i;
                }
            }
            if (empty($item)) {
                $layout->navigate_notification(t(599, "Sorry, can't display a theme block type info."));
                $out = blocks_types_list();
            } else {
                if (isset($_REQUEST['form-sent'])) {
                    if (empty($item)) {
                        $item = array('id' => $max_id + 1);
                    }
                    $item['type'] = $_REQUEST['type'];
                    $item['title'] = $_REQUEST['title'];
                    $item['code'] = $_REQUEST['code'];
                    $item['width'] = $_REQUEST['width'];
                    $item['height'] = $_REQUEST['height'];
                    $item['order'] = $_REQUEST['order'];
                    $item['maximum'] = $_REQUEST['maximum'];
                    $item['notes'] = pquotes($_REQUEST['notes']);
                    if (!is_null($position)) {
                        $dataset[$position] = $item;
                    } else {
                        $dataset[] = $item;
                    }
                    try {
                        // save
                        $ok = block::types_update($dataset);
                        $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                    } catch (Exception $e) {
                        $layout->navigate_notification($e->getMessage(), true, true);
                    }
                }
                $out = blocks_type_form($item);
            }
            break;
        case 'block_type_delete':
        case 84:
            // remove block type
            $dataset = block::custom_types();
            $item = NULL;
            for ($i = 0; $i < count($dataset); $i++) {
                if ($dataset[$i]['id'] == $_REQUEST['id']) {
                    unset($dataset[$i]);
                    break;
                }
            }
            try {
                block::types_update($dataset);
                $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                $out = blocks_types_list();
            } catch (Exception $e) {
                $out = $layout->navigate_message("error", t(23, 'Blocks'), t(56, 'Unexpected error.'));
            }
            break;
        case 'block_property_load':
            $property = new property();
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $property->load(intval($_REQUEST['id']));
                } else {
                    $property->load_from_theme($_REQUEST['id'], null, 'block', $_REQUEST['block']);
                }
            }
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'block_property_save':
            // save property details
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->load_from_post();
            $property->save();
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'block_property_remove':
            // remove property
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->delete();
            session_write_close();
            exit;
            break;
        case 'block_group_block_options':
            $status = null;
            $block_group = $_REQUEST['block_group'];
            $block_code = $_REQUEST['code'];
            $block_uid = $_REQUEST['block_uid'];
            if (isset($_REQUEST['form-sent'])) {
                $status = property::save_properties_from_post('block_group_block', $block_code, $block_group, $block_code, $block_uid);
            }
            $out = block_group_block_options($block_group, $block_code, $block_uid, $status);
            echo $out;
            core_terminate();
            break;
        case 'block_group_extension_block_options':
            $status = null;
            $block_group = $_REQUEST['block_group'];
            // block_group type
            $block_id = $_REQUEST['block_id'];
            // extension block id (type)
            $block_uid = $_REQUEST['block_uid'];
            // extension block unique id
            $block_extension = $_REQUEST['block_extension'];
            // extension name
            if (isset($_REQUEST['form-sent'])) {
                $status = property::save_properties_from_post('extension_block', $block_group, $block_id, null, $block_uid);
            }
            $out = block_group_extension_block_options($block_group, $block_extension, $block_id, $block_uid, $status);
            echo $out;
            core_terminate();
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = blocks_list();
            break;
    }
    return $out;
}
function nvweb_properties($vars = array())
{
    global $website;
    global $DB;
    global $current;
    global $cache;
    global $properties;
    global $webuser;
    $out = '';
    switch (@$vars['mode']) {
        case 'website':
            $wproperty = new property();
            $wproperty->load_from_theme($vars['property']);
            if (!empty($wproperty)) {
                $out = nvweb_properties_render($wproperty, $vars);
            }
            break;
        case 'webuser':
            $wuproperty = new property();
            $wuproperty->load_from_webuser($vars['property']);
            if (!empty($wuproperty)) {
                $out = nvweb_properties_render($wuproperty, $vars);
            }
            break;
        case 'element':
        case 'item':
            // deprecated, may be removed in a future version
            // if item ID is not given and the current object an element or a structure category?
            if (empty($vars['id']) && $current['type'] == 'structure') {
                // find the first embedded element for the current category
                // (because the template code has requested specifically to return the property from an element!)
                $itm = nvweb_content_items($current['object']->id, true, 1, true, 'priority');
                if (!empty($itm) && isset($itm[0])) {
                    $vars['id'] = $itm[0]->id;
                } else {
                    $vars['id'] = 0;
                }
            }
            if (!isset($properties['item-' . $vars['id']]) && !empty($vars['id'])) {
                // load item template
                if (empty($vars['template'])) {
                    $vars['template'] = $DB->query_single('template', 'nv_items', ' id = ' . protect($vars['id']));
                }
                // if template is not defined (embedded element), take its category template
                if (empty($vars['template'])) {
                    $vars['template'] = $DB->query_single('template', 'nv_structure', ' id = (
                            SELECT category
                            FROM nv_items
                            WHERE id = ' . intval($vars['id']) . '
                        )');
                }
                $properties['item-' . $vars['id']] = property::load_properties("item", $vars['template'], 'item', $vars['id']);
            } else {
                if (empty($vars['id'])) {
                    $vars['type'] = $current['object']->template;
                    if ($current['type'] == "item") {
                        $vars['id'] = $current['object']->id;
                    } else {
                        if ($current['type'] == "structure") {
                            // find the first embedded content associated with this structure entry
                            // (because the template code has requested specifically to return the property from an element!)
                            $itm = nvweb_content_items($current['object']->id, true, 1, true, 'priority');
                            if (!empty($itm) && isset($itm[0])) {
                                $vars['id'] = $itm[0]->id;
                            } else {
                                $vars['id'] = 0;
                            }
                        }
                    }
                    if (!isset($properties['item-' . $vars['id']])) {
                        $properties['item-' . $current['object']->id] = property::load_properties("item", $vars['type'], 'item', $vars['id']);
                    }
                }
            }
            $current_properties = $properties['item-' . $vars['id']];
            // now we find the property requested
            if (!is_array($current_properties)) {
                $current_properties = array();
            }
            foreach ($current_properties as $property) {
                if ($property->id == $vars['property'] || $property->name == $vars['property']) {
                    $out = nvweb_properties_render($property, $vars);
                    break;
                }
            }
            break;
        case 'block':
            if (!isset($properties['block-' . $vars['id']])) {
                // load item type
                if (empty($vars['type'])) {
                    $vars['type'] = $DB->query_single('type', 'nv_blocks', ' id = ' . protect($vars['id']));
                    if (empty($cache['block_types'])) {
                        $cache['block_types'] = block::types();
                    }
                    // we need to know if the block is defined in the active theme or in the database (numeric ID)
                    foreach ($cache['block_types'] as $bt) {
                        if ($bt['code'] == $vars['type']) {
                            $vars['type'] = $bt['id'];
                            break;
                        }
                    }
                }
                $properties['block-' . $vars['id']] = property::load_properties("block", $vars['type'], 'block', $vars['id']);
            }
            $current_properties = $properties['block-' . $vars['id']];
            // now we find the property requested
            if (!is_array($current_properties)) {
                $current_properties = array();
            }
            foreach ($current_properties as $property) {
                if ($property->id == $vars['property'] || $property->name == $vars['property']) {
                    $out = nvweb_properties_render($property, $vars);
                    break;
                }
            }
            break;
        case 'block_group_block':
            // find block_group block definition
            $block_group = null;
            // unknown
            $block_code = $vars['id'];
            $block_uid = $vars['uid'];
            if (empty($block_code)) {
                $block = block::block_group_block_by_property($vars['property']);
                $block_code = $block->type;
            } else {
                // find the block group block by its type
                $block = block::block_group_block($block_group, $block_code);
            }
            $properties = $block->properties;
            $current_properties = property::load_properties($block_code, $block->_block_group_id, 'block_group_block', $block_code, $block_uid);
            // now we find the property requested
            if (!is_array($current_properties)) {
                $current_properties = array();
            }
            foreach ($current_properties as $property) {
                if ($property->id == $vars['property'] || $property->name == $vars['property']) {
                    $out = nvweb_properties_render($property, $vars);
                    break;
                }
            }
            break;
        case 'structure':
            if (empty($vars['id'])) {
                if ($current['type'] == 'structure') {
                    $vars['id'] = $current['id'];
                } else {
                    $vars['id'] = $current['object']->category;
                }
            }
            if (!isset($properties['structure-' . $vars['id']])) {
                // load category template
                $category_template = $DB->query_single('template', 'nv_structure', ' id = ' . protect($vars['id']));
                if (!empty($category_template)) {
                    $properties['structure-' . $vars['id']] = property::load_properties("structure", $category_template, 'structure', $vars['id']);
                }
            }
            $current_properties = $properties['structure-' . $vars['id']];
            // now we find the property requested
            if (!is_array($current_properties)) {
                $current_properties = array();
            }
            foreach ($current_properties as $property) {
                if ($property->id == $vars['property'] || $property->name == $vars['property']) {
                    if ($vars['return'] == 'object') {
                        $out = $property;
                    } else {
                        $out = nvweb_properties_render($property, $vars);
                    }
                    break;
                }
            }
            break;
        case 'comment':
            if (!isset($properties['comment-' . $vars['id']])) {
                $properties['comment-' . $vars['id']] = property::load_properties("comment", $vars['template'], 'comment', $vars['id']);
            }
            $current_properties = $properties['comment-' . $vars['id']];
            // now we find the property requested
            if (!is_array($current_properties)) {
                $current_properties = array();
            }
            foreach ($current_properties as $property) {
                if ($property->id == $vars['property'] || $property->name == $vars['property']) {
                    if ($vars['return'] == 'object') {
                        $out = $property;
                    } else {
                        $out = nvweb_properties_render($property, $vars);
                    }
                    break;
                }
            }
            break;
        default:
            // find the property source by its name
            $current_properties = array();
            // get website theme property
            $current_properties[] = new property();
            $current_properties[0]->load_from_theme($vars['property']);
            if ($current['type'] == 'item') {
                if (!isset($properties['item-' . $current['object']->id])) {
                    $properties['item-' . $current['object']->id] = property::load_properties("item", $current['object']->template, 'item', $current['object']->id);
                }
                $current_properties = array_merge($current_properties, $properties['item-' . $current['object']->id]);
            } else {
                if ($current['type'] == 'structure') {
                    if (!isset($properties['structure-' . $current['object']->id])) {
                        $properties['structure-' . $current['object']->id] = property::load_properties("structure", $current['object']->template, 'structure', $current['object']->id);
                    }
                    $current_properties = array_merge($current_properties, $properties['structure-' . $current['object']->id]);
                    // the property could also be in the first item associated to this structure element
                    $structure_items = nvweb_content_items($current['object']->id, true, 1);
                    if (!empty($structure_items)) {
                        if (empty($structure_items[0]->template)) {
                            $structure_items[0]->template = $current['template'];
                        }
                        $properties['item-' . $structure_items[0]->id] = property::load_properties("item", $structure_items[0]->template, 'item', $structure_items[0]->id);
                    }
                    if (!empty($properties['item-' . $structure_items[0]->id])) {
                        $current_properties = array_merge($current_properties, $properties['item-' . $structure_items[0]->id]);
                    }
                } else {
                    if ($current['type'] == 'article') {
                        // TO DO
                    } else {
                        // unknown object type, maybe is an object managed by an extension?
                        if (!isset($properties[$current['type'] . '-' . $current['object']->id])) {
                            $properties[$current['type'] . '-' . $current['object']->id] = property::load_properties($current['type'], $current['object']->template, $current['type'], $current['object']->id);
                        }
                        $current_properties = array_merge($current_properties, $properties[$current['type'] . '-' . $current['object']->id]);
                    }
                }
            }
            // now we find the property requested
            if (!is_array($current_properties)) {
                $current_properties = array();
            }
            foreach ($current_properties as $property) {
                if ($property->id == $vars['property'] || $property->name == $vars['property']) {
                    $out = nvweb_properties_render($property, $vars);
                    break;
                }
            }
            break;
    }
    return $out;
}
Beispiel #4
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();
}
Beispiel #5
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new template();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    // we have to merge the theme templates with the custom private templates (which are defined in the DB)
                    // as we don't expect a lot of templates, we will always return the whole dataset
                    // for this reason, paginate is useless
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    if (isset($_REQUEST['quicksearch'])) {
                        $dataset = template::search($orderby, array('quicksearch' => $_REQUEST['quicksearch']));
                    } else {
                        $dataset = template::search($orderby);
                    }
                    $total = count($dataset);
                    $out = array();
                    $permissions = array(0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden'));
                    if (empty($dataset)) {
                        $rows = 0;
                    } else {
                        $rows = count($dataset);
                    }
                    for ($i = 0; $i < $rows; $i++) {
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['title'], 2 => $dataset[$i]['theme'], 3 => $permissions[$dataset[$i]['permission']], 4 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />');
                    }
                    navitable::jqgridJson($out, 1, 0, PHP_INT_MAX, $total);
                    break;
            }
            core_terminate();
            break;
        case 'load':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $item->load(intval($_REQUEST['id']));
                } else {
                    $item->load_from_theme($_REQUEST['id']);
                }
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    if (!empty($_REQUEST['property-enabled'])) {
                        $enableds = array_values($_REQUEST['property-enabled']);
                    } else {
                        $enableds = array();
                    }
                    property::reorder("template", $item->id, $_REQUEST['template-properties-order'], $enableds);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->title, json_encode($_REQUEST));
            } else {
                users_log::action($_REQUEST['fid'], $item->id, 'load', $item->title);
            }
            $out = templates_form($item);
            break;
        case 'save_template_file':
            // save template html
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            $data = $_REQUEST['templates-file-edit-area'];
            $data = str_replace("\r\n", "\r", $data);
            $x = file_put_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $item->file, $data);
            echo json_encode($x > 0);
            session_write_close();
            exit;
            break;
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = templates_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = webdictionary_list();
                }
                users_log::action($_REQUEST['fid'], $item->id, $item->title, 'remove');
            }
            break;
        case 'template_property_load':
            $property = new property();
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $property->load(intval($_REQUEST['id']));
                } else {
                    $property->load_from_theme($_REQUEST['id'], null, 'template', $_REQUEST['template']);
                }
            }
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'template_property_save':
            // save property details
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->load_from_post();
            $property->save();
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'template_property_remove':
            // remove property
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->delete();
            session_write_close();
            exit;
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = templates_list();
            break;
    }
    return $out;
}