function run() { global $user; global $layout; global $DB; global $website; $out = ''; $wtext = new webdictionary(); switch ($_REQUEST['act']) { case 'json': // json data retrieval & operations switch ($_REQUEST['oper']) { case 'del': // remove rows $ids = $_REQUEST['ids']; foreach ($ids as $id) { $wtext->load($id); $wtext->delete(); } echo json_encode(true); break; default: // list or search $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = ' website = ' . $website->id; if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) { if (isset($_REQUEST['quicksearch'])) { $where .= $wtext->quicksearch($_REQUEST['quicksearch']); } else { if (isset($_REQUEST['filters'])) { $where .= navitable::jqgridsearch($_REQUEST['filters']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } list($dataset, $total) = webdictionary_search($where, $orderby, $offset, $max); for ($i = 0; $i < count($dataset); $i++) { $origin = ""; if (!empty($dataset[$i]['theme'])) { $origin = '<i class="fa fa-fw fa-paint-brush ui-text-light" title="' . t(368, "Theme") . '"></i> ' . $dataset[$i]['theme']; } else { if (!empty($dataset[$i]['extension'])) { $origin = '<i class="fa fa-fw fa-puzzle-piece ui-text-light" title="' . t(617, "Extension") . '"></i> ' . $dataset[$i]['extension']; } } if (empty($dataset[$i])) { continue; } $out[$i] = array(0 => $dataset[$i]['theme'] . $dataset[$i]['extension'] . '.' . $dataset[$i]['id'], 1 => $dataset[$i]['node_id'], 2 => $origin, 3 => language::name_by_code($dataset[$i]['lang']), 4 => $dataset[$i]['text'], 5 => $dataset[$i]['source']); } navitable::jqgridJson($out, $page, $offset, $max, $total, 0); // 0 is the index of the ghost ID column break; } session_write_close(); exit; break; case 'edit': // edit/new form if (!empty($_REQUEST['path']) && !is_numeric($_REQUEST['id'])) { $wtext->load($_REQUEST['path']); } else { if (!empty($_REQUEST['id'])) { $wtext->load($_REQUEST['id']); } } if (isset($_REQUEST['form-sent'])) { $wtext->load_from_post(); try { $wtext->save(); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } $out = webdictionary_form($wtext); break; case 'remove': // remove if (!empty($_REQUEST['id'])) { $wtext->load($_REQUEST['id']); if ($wtext->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = webdictionary_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = webdictionary_form($wtext); } } break; case 'edit_language': if ($_REQUEST['form-sent'] == 'true') { $status = webdictionary::save_translations_post($_REQUEST['code']); if ($status == 'true') { $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } else { $layout->navigate_notification(implode('<br />', $status), true, true); } } $out = webdictionary_edit_language_form($_REQUEST['code']); break; case 0: // list / search result // list / search result default: $out = webdictionary_list(); break; } return $out; }
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'] = '∞'; } else { $dataset[$i]['date_published'] = core_ts2date($dataset[$i]['date_published'], false); } if (empty($dataset[$i]['date_unpublish'])) { $dataset[$i]['date_unpublish'] = '∞'; } 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 run() { global $layout; global $DB; global $website; global $theme; global $user; $out = ''; $item = new item(); 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'] = 'i.id'; break; case 'title': $_REQUEST['searchField'] = 'd.text'; break; case 'language': $_REQUEST['searchField'] = 'd.lang'; break; case 'category': $_REQUEST['searchField'] = 'i.category'; break; case 'dates': $_REQUEST['searchField'] = 'i.date_published'; break; case 'permission': $_REQUEST['searchField'] = 'i.permission'; break; default: } if ($_REQUEST['sidx'] == 'dates') { $_REQUEST['sidx'] = 'i.date_published'; } $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = ' i.website = ' . $website->id; if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) { if (isset($_REQUEST['quicksearch'])) { $where .= $item->quicksearch($_REQUEST['quicksearch']); } else { if (isset($_REQUEST['filters'])) { if (is_array($_REQUEST['filters'])) { $filters = json_decode(json_encode($_REQUEST['filters']), FALSE); } else { $filters = json_decode($_REQUEST['filters']); } for ($r = 0; $r < count($filters->rules); $r++) { switch ($filters->rules[$r]->field) { case 'id': $filters->rules[$r]->field = 'i.id'; break; case 'title': $filters->rules[$r]->field = 'd.text'; break; case 'language': $filters->rules[$r]->field = 'd.lang'; break; case 'category': $filters->rules[$r]->field = 'i.category'; break; case 'dates': $filters->rules[$r]->field = 'i.date_published'; break; case 'permission': $filters->rules[$r]->field = 'i.permission'; break; default: } } $where .= navitable::jqgridsearch(json_encode($filters)); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $sql = ' SELECT SQL_CALC_FOUND_ROWS i.*, d.text as title, d.lang as language, u.username as author_username, ( SELECT COUNT(*) FROM nv_comments cm WHERE cm.item = i.id AND cm.website = ' . $website->id . ' ) as comments FROM nv_items i LEFT JOIN nv_webdictionary d ON i.id = d.node_id AND d.node_type = "item" AND d.subtype = "title" AND d.lang = "' . $website->languages_list[0] . '" AND d.website = ' . $website->id . ' LEFT JOIN nv_users u ON u.id = i.author WHERE ' . $where . ' GROUP BY i.id, d.text, d.lang, u.username 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(); $dataset = grid_notes::summary($dataset, 'item', 'id'); $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") . '" />'); $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')); $hierarchy = structure::hierarchy(0); // 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; } if (empty($dataset[$i]['date_published'])) { $dataset[$i]['date_published'] = '∞'; } else { $dataset[$i]['date_published'] = core_ts2date($dataset[$i]['date_published'], false); } if (empty($dataset[$i]['date_unpublish'])) { $dataset[$i]['date_unpublish'] = '∞'; } else { $dataset[$i]['date_unpublish'] = core_ts2date($dataset[$i]['date_unpublish'], false); } if (empty($dataset[$i]['date_to_display'])) { $dataset[$i]['date_to_display'] = ''; } else { $dataset[$i]['date_to_display'] = core_ts2date($dataset[$i]['date_to_display'], false); } if ($dataset[$i]['category'] > 0) { $category_path = structure::hierarchyPath($hierarchy, $dataset[$i]['category']); if (is_array($category_path)) { $dataset[$i]['category_path'] = implode(' › ', $category_path); } else { $dataset[$i]['category_path'] = $category_path; } } $category_text = ''; if ($dataset[$i]['association'] == 'free') { $category_text = '[ ' . strtolower(t(100, 'Free')) . ' ]'; } else { $category_text = $dataset[$i]['category_path']; } $item_views = $dataset[$i]['views']; if ($item_views > 1000) { $item_views = round($item_views / 1000) . "K"; } $item_comments = $dataset[$i]['comments']; if ($item_comments > 1000) { $item_comments = round($item_comments / 1000) . "K"; } //$social_rating = '<img src="img/icons/silk/star.png" align="absmiddle" width="12px" height="12px" /> '. // '<span style="font-size: 90%;">'.$dataset[$i]['score'].' ('.$dataset[$i]['votes'].')</span>'; //$social_rating = '<i class="fa fa-fw fa-eye" /> <span style="font-size: 90%;">'.$dataset[$i]['views'].'</span>'; $social_rating = '<img src="img/icons/silk/eye.png" align="absmiddle" width="12px" height="12px" /> ' . '<span style="font-size: 90%;">' . $item_views . '</span>'; //$social_comments = '<i class="fa fa-fw fa-comments-o" /> <span style="font-size: 90%;">'.$dataset[$i]['comments'].'</span>'; $social_comments = '<img src="img/icons/silk/comments.png" align="absmiddle" width="12px" height="12px" /> ' . '<span style="font-size: 90%;">' . $item_comments . '</span>'; if (empty($dataset[$i]['title'])) { // if title is empty for the default language, // try to load the title in another language $DB->query(' SELECT lang, text FROM nv_webdictionary WHERE website = ' . $website->id . ' AND node_type = "item" AND subtype="title" AND node_id = ' . $dataset[$i]['id'] . ' AND text != "" ORDER BY id ASC'); $titles = $DB->result(); if (!empty($titles)) { $dataset[$i]['title'] = '<img src="img/icons/silk/comment.png" align="absmiddle" />'; $dataset[$i]['title'] .= '<small>' . $titles[0]->lang . '</small> '; $dataset[$i]['title'] .= $titles[0]->text; } } $out[$i] = array(0 => $dataset[$i]['id'], 1 => '<div class="list-row" data-permission="' . $dataset[$i]['permission'] . '">' . $dataset[$i]['title'] . '</div>', 2 => $social_rating . ' ' . $social_comments, 3 => $category_text, 4 => $dataset[$i]['date_to_display'], 5 => $dataset[$i]['date_published'] . ' - ' . $dataset[$i]['date_unpublish'], 6 => $access[$dataset[$i]['access']] . ' ' . $permissions[$dataset[$i]['permission']], 7 => $dataset[$i]['_grid_notes_html']); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } core_terminate(); break; case 'load': case 'create': case 'edit': case 2: // edit/new form if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($user->permission("items.edit") == "false" && $item->author != $user->id) { $layout->navigate_notification(t(610, "Sorry, you are not allowed to execute the requested function"), true); $_REQUEST['act'] = 'list'; return run(); } // check if the current user can edit this item if ($item->association == 'category' && !empty($item->category)) { if (!structure::category_allowed($item->category)) { $layout->navigate_notification(t(610, "Sorry, you are not allowed to execute the requested function"), true); $_REQUEST['act'] = 'list'; return run(); } } } if (isset($_REQUEST['form-sent'])) { $item->load_from_post(); try { $item->save(); property::save_properties_from_post('item', $item->id); if (!empty($_REQUEST['items-order'])) { item::reorder($_REQUEST['items-order']); } $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); $item->load($item->id); users_log::action($_REQUEST['fid'], $item->id, 'save', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST)); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } else { users_log::action($_REQUEST['fid'], $item->id, 'load', $item->dictionary[$website->languages_list[0]]['title']); } $out = items_form($item); break; case 'delete': case 4: // remove if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); try { if (!empty($item->id)) { $deleted = $item->delete() > 0; if ($deleted) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = items_list(); users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST)); } } if (!$deleted) { $layout->navigate_notification(t(56, 'Unexpected error.'), false); if (!empty($item->id)) { $out = items_form($item); } else { $out = items_list(); } } } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true); if (!empty($item->id)) { $out = items_form($item); } } } break; case 'duplicate': if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->association == 'category' && $item->embedding == 1) { // get structure template $category = new structure(); $category->load($item->category); $properties = property::load_properties_associative('structure', $category->template, 'item', $item->id); } else { $properties = property::load_properties_associative('item', $item->template, 'item', $item->id); } // try to duplicate $item->id = 0; $ok = $item->insert(); if ($ok) { // duplicate item properties too (but don't duplicate comments) if ($item->association == 'category' && $item->embedding == 1) { $ok = property::save_properties_from_array('item', $item->id, $category->template, $properties); } else { $ok = property::save_properties_from_array('item', $item->id, $item->template, $properties); } } if ($ok) { $layout->navigate_notification(t(478, 'Item duplicated successfully.'), false, false, 'fa fa-check'); $out = items_form($item); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $item = new item(); $item->load(intval($_REQUEST['id'])); $out = items_form($item); } users_log::action($_REQUEST['fid'], $item->id, 'duplicate', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST)); } break; case 89: if (!empty($_REQUEST['id'])) { $DB->execute('DELETE FROM nv_webdictionary_history WHERE id = ' . intval($_REQUEST['id']) . ' LIMIT 1'); echo 'true'; } else { echo 'false'; } core_terminate(); break; case 90: $DB->query('SELECT id, date_created, autosave FROM nv_webdictionary_history WHERE node_type = "item" AND subtype = ' . protect('section-' . $_REQUEST['section']) . ' AND lang = ' . protect($_GET['lang']) . ' AND node_id = ' . protect($_REQUEST['id']) . ' AND website = ' . $website->id . ' ORDER BY date_created DESC', 'array'); $result = $DB->result(); if (!is_array($result)) { $result = array(); } for ($i = 0; $i < count($result); $i++) { $result[$i]['date'] = core_ts2date($result[$i]['date_created'], true); if ($result[$i]['autosave'] == 1) { $result[$i]['date'] .= ' (' . t(273, 'Autosave') . ')'; } } echo json_encode($result); core_terminate(); break; case "search_by_title": case 91: // json search title request (for "copy from" dialog) $DB->query(' SELECT node_id as id, text as label, text as value FROM nv_webdictionary WHERE node_type = "item" AND subtype = "title" AND lang = ' . protect($_REQUEST['lang']) . ' AND website = ' . $website->id . ' AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . ' ORDER BY text ASC LIMIT 20', 'array'); echo json_encode($DB->result()); core_terminate(); break; case "raw_zone_content": // return raw item contents if (empty($_REQUEST['section'])) { $_REQUEST['section'] = 'main'; } if ($_REQUEST['history'] == 'true') { $DB->query('SELECT text FROM nv_webdictionary_history WHERE node_type = "item" AND website = ' . $website->id . ' AND id = ' . protect($_REQUEST['id']), 'array'); $data = $DB->first(); echo $data['text']; } else { if ($_REQUEST['zone'] == 'section') { $DB->query('SELECT text FROM nv_webdictionary WHERE node_type = "item" AND subtype = ' . protect('section-' . $_REQUEST['section']) . ' AND lang = ' . protect($_REQUEST['lang']) . ' AND website = ' . $website->id . ' AND node_id = ' . protect($_REQUEST['node_id']), 'array'); $data = $DB->first(); echo $data['text']; } else { if ($_REQUEST['zone'] == 'property') { $DB->query('SELECT text FROM nv_webdictionary WHERE node_type = "property-item" AND subtype = ' . protect('property-' . $_REQUEST['section'] . '-' . $_REQUEST['lang']) . ' AND lang = ' . protect($_REQUEST['lang']) . ' AND website = ' . $website->id . ' AND node_id = ' . protect($_REQUEST['node_id']), 'array'); $data = $DB->first(); echo $data['text']; } } } core_terminate(); break; // return raw template content // return raw template content case 93: $DB->query('SELECT file FROM nv_templates WHERE enabled = 1 AND id = ' . protect($_REQUEST['id']) . ' AND website = ' . $website->id, 'array'); $data = $DB->first(); echo @file_get_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $data['file']); core_terminate(); break; case "copy_from_template_zones": // return template sections and (textarea) properties for a content id $item = new item(); $item->load(intval($_REQUEST['id'])); $template = $item->load_template(); $zones = array(); for ($ts = 0; $ts < count($template->sections); $ts++) { $title = $template->sections[$ts]['name']; if (!empty($theme)) { $title = $theme->t($title); } if ($title == '#main#') { $title = t(238, 'Main content'); } $zones[] = array('type' => 'section', 'id' => $template->sections[$ts]['id'], 'title' => $title); } for ($ps = 0; $ps < count($template->properties); $ps++) { // ignore structure properties if (isset($template->properties[$ps]->element) && $template->properties[$ps]->element != 'item') { continue; } // ignore non-textual properties if (!in_array($template->properties[$ps]->type, array("text", "textarea", "rich_textarea"))) { continue; } $title = $template->properties[$ps]->name; if (!empty($theme)) { $title = $theme->t($title); } $zones[] = array('type' => 'property', 'id' => $template->properties[$ps]->id, 'title' => $title); } echo json_encode($zones); core_terminate(); break; case 95: // free path checking $path = $_REQUEST['path']; $id = $_REQUEST['id']; $DB->query('SELECT type, object_id, lang FROM nv_paths WHERE path = ' . protect($path) . ' AND website = ' . $website->id); $rs = $DB->result(); echo json_encode($rs); core_terminate(); break; case 96: // return category paths echo json_encode(path::loadElementPaths('structure', intval($_REQUEST['id']))); core_terminate(); break; case 'json_find_user': // json find user by name request (for "moderator" autocomplete) $DB->query(' SELECT id, username as text FROM nv_users WHERE username LIKE ' . protect('%' . $_REQUEST['username'] . '%') . ' ORDER BY username ASC LIMIT 30', 'array '); $rows = $DB->result(); $total = $DB->foundRows(); echo json_encode(array('items' => $rows, 'total_count' => $total)); core_terminate(); break; case 'json_find_item': // find items by its title // any language $template_filter = ''; if (!empty($_REQUEST['template'])) { $template_filter = ' AND nvi.template = ' . protect($_REQUEST['template']) . ' '; } if (!empty($_REQUEST['association'])) { $template_filter = ' AND nvi.association = ' . protect($_REQUEST['association']) . ' '; } if (isset($_REQUEST['embedding'])) { $template_filter = ' AND nvi.embedding = ' . protect($_REQUEST['embedding']) . ' '; } $text = $_REQUEST['title']; if (!empty($_REQUEST['term'])) { // tagit request $text = $_REQUEST['term']; } $DB->query(' SELECT SQL_CALC_FOUND_ROWS DISTINCT nvw.node_id as id, nvw.text as text FROM nv_webdictionary nvw, nv_items nvi WHERE nvw.node_type = "item" AND nvw.node_id = nvi.id ' . $template_filter . ' AND nvw.subtype = "title" AND nvw.website = ' . $website->id . ' AND nvw.website = nvi.website AND nvw.text LIKE ' . protect('%' . $text . '%') . ' GROUP BY nvw.node_id, nvw.text ORDER BY nvw.text ASC LIMIT ' . intval($_REQUEST['page_limit']) . ' OFFSET ' . max(0, intval($_REQUEST['page_limit']) * (intval($_REQUEST['page']) - 1)), 'array'); $rows = $DB->result(); $total = $DB->foundRows(); if ($_REQUEST['association'] == 'free') { for ($i = 0; $i < count($rows); $i++) { $rows[$i]['path'] = $DB->query_single('path', 'nv_paths', ' website = ' . protect($website->id) . ' AND type="item" AND object_id="' . $rows[$i]['id'] . '" AND lang="' . $website->languages_list[0] . '" '); if (empty($rows[$i]['path'])) { $rows[$i]['path'] = '/node/' . $rows[$i]['id']; } } } if (empty($_REQUEST['format']) || $_REQUEST['format'] == 'select2') { echo json_encode(array('items' => $rows, 'totalCount' => $total)); } else { if ($_REQUEST['format'] == 'tagit') { $tags_json = array(); foreach ($rows as $row) { $tags_json[] = json_decode('{ "id": "' . $row['id'] . '", "label": "' . $row['text'] . '", "value": "' . $row['text'] . '" }'); } echo json_encode($tags_json); } } core_terminate(); break; case 98: // change comment status if (empty($_REQUEST['id'])) { echo "false"; core_terminate(); } switch ($_REQUEST['opt']) { case 'publish': $DB->execute(' UPDATE nv_comments SET status = 0 WHERE website = ' . $website->id . ' AND id = ' . $_REQUEST['id']); break; case 'unpublish': $DB->execute(' UPDATE nv_comments SET status = 1 WHERE website = ' . $website->id . ' AND id = ' . $_REQUEST['id']); break; case 'delete': $DB->execute(' DELETE FROM nv_comments WHERE website = ' . $website->id . ' AND id = ' . $_REQUEST['id']); break; } $error = $DB->get_last_error(); if (empty($error)) { echo 'true'; } else { echo 'false'; } core_terminate(); break; case 'autosave': if (!empty($_REQUEST['id'])) { $iDictionary = array(); foreach ($_REQUEST as $key => $value) { if (strpos($key, 'section-') === 0) { $lang = substr($key, -2, 2); $kname = substr($key, 0, strlen($key) - 3); $iDictionary[$lang][$kname] = $value; } } $changed = webdictionary_history::save_element_strings('item', intval($_REQUEST['id']), $iDictionary, true); if ($changed) { echo 'changes_saved'; } else { echo 'no_changes'; } core_terminate(); } echo 'false'; core_terminate(); break; case 'votes_reset': webuser_vote::remove_object_votes('item', intval($_REQUEST['id'])); echo 'true'; core_terminate(); break; case 'votes_by_webuser': if ($_POST['oper'] == 'del') { $ids = explode(',', $_POST['id']); for ($i = 0; $i < count($ids); $i++) { if ($ids[$i] > 0) { $vote = new webuser_vote(); $vote->load($ids[$i]); $vote->delete(); } } webuser_vote::update_object_score('item', $vote->object_id); echo 'true'; core_terminate(); } $max = intval($_GET['rows']); $page = intval($_GET['page']); $offset = ($page - 1) * $max; if ($_REQUEST['_search'] == 'false') { list($dataset, $total) = webuser_vote::object_votes_by_webuser('item', intval($_REQUEST['id']), $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'], $offset, $max); } $out = array(); for ($i = 0; $i < count($dataset); $i++) { if (empty($dataset[$i])) { continue; } $out[$i] = array(0 => $dataset[$i]['id'], 1 => core_ts2date($dataset[$i]['date'], true), 2 => $dataset[$i]['username']); } navitable::jqgridJson($out, $page, $offset, $max, $total); core_terminate(); break; case 'items_order': if (!empty($_POST['items-order'])) { // save new order $response = item::reorder($_POST['items-order']); if ($response !== true) { echo $response['error']; } else { echo 'true'; } } else { // show ordered list echo items_order($_REQUEST['category']); } core_terminate(); break; case 'json_tags_search': $tags = nvweb_tags_retrieve(null, null, 'top', $_REQUEST['term'], $_REQUEST['lang']); $tags_json = array(); foreach (array_keys($tags) as $tag) { $tags_json[] = json_decode('{ "id": "' . $tag . '", "label": "' . $tag . '", "value": "' . $tag . '" }'); } echo json_encode($tags_json); core_terminate(); break; case 'json_tags_ranking': $tags = nvweb_tags_retrieve(100, null, 'top', null, $_REQUEST['lang']); $tags = array_keys($tags); echo json_encode($tags); core_terminate(); break; case 'list': case 0: // list / search result // list / search result default: $out = items_list(); break; } return $out; }
function run() { global $user; global $layout; global $DB; $out = ''; $item = new profile(); 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 $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']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $DB->queryLimit('id,name', 'nv_profiles', $where, $orderby, $offset, $max); $dataset = $DB->result(); $total = $DB->foundRows(); //echo $DB->get_last_error(); $out = array(); for ($i = 0; $i < count($dataset); $i++) { $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['name']); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } session_write_close(); exit; break; 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(); permission::update_permissions(json_decode($_REQUEST['navigate_permissions_changes'], true), $item->id, 0); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } $out = profiles_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 = profiles_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = profiles_form($item); } } break; case 'list': case 0: // list / search result // list / search result default: $out = profiles_list(); break; } return $out; }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new webuser(); switch ($_REQUEST['act']) { // json data retrieval & operations case 'json': case 1: 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 $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = ' website = ' . $website->id; if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) { if (isset($_REQUEST['quicksearch'])) { $where .= $item->quicksearch($_REQUEST['quicksearch']); } else { if (isset($_REQUEST['filters'])) { $filters = $_REQUEST['filters']; if (is_array($filters)) { $filters = json_encode($filters); } $where .= navitable::jqgridsearch($filters); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $DB->queryLimit('id,avatar,username,email,fullname,groups,joindate,access,access_begin,access_end', 'nv_webusers', $where, $orderby, $offset, $max); $dataset = $DB->result(); $total = $DB->foundRows(); $dataset = grid_notes::summary($dataset, 'webuser', 'id'); global $webusers_groups_all; $webusers_groups_all = webuser_group::all_in_array(); //echo $DB->get_last_error(); $out = array(); for ($i = 0; $i < count($dataset); $i++) { $wug = str_replace('g', '', $dataset[$i]['groups']); $wug = explode(',', $wug); $wug = array_map(function ($in) { global $webusers_groups_all; if (empty($in)) { return; } return $webusers_groups_all[$in]; }, $wug); $blocked = 1; if ($dataset[$i]['access'] == 0 || $dataset[$i]['access'] == 2 && ($dataset[$i]['access_begin'] == 0 || $dataset[$i]['access_begin'] < time()) && ($dataset[$i]['access_end'] == 0 || $dataset[$i]['access_end'] > time())) { $blocked = 0; } $out[$i] = array(0 => $dataset[$i]['id'], 1 => empty($dataset[$i]['avatar']) ? '' : '<img title="' . $dataset[$i]['username'] . '" src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . urlencode($dataset[$i]['avatar']) . '&disposition=inline&width=32&height=32" />', 2 => '<div class="list-row" data-blocked="' . $blocked . '" title="' . $dataset[$i]['email'] . '">' . $dataset[$i]['username'] . '</div>', 3 => $dataset[$i]['fullname'], 4 => implode("<br />", $wug), 5 => core_ts2date($dataset[$i]['joindate'], true), 6 => $blocked == 0 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />', 7 => $dataset[$i]['_grid_notes_html']); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } session_write_close(); exit; break; case 2: // edit/new form // edit/new form case 'create': case 'edit': 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('webuser', $item->id); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'save', $item->username, json_encode($_REQUEST)); } } else { if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'load', $item->username); } } $out = webusers_form($item); break; case 4: // remove // remove case 'remove': if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = webusers_list(); users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->username, json_encode($_REQUEST)); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = webusers_form($item); } } break; case 90: // json request: timezones by country $timezones = property::timezones($_REQUEST['country']); if (empty($timezones)) { $timezones = property::timezones(); } echo json_encode($timezones); core_terminate(); break; case 'export': // export web users list to a CSV file users_log::action($_REQUEST['fid'], 0, 'export', "all", json_encode($_REQUEST)); webuser::export(); break; case 'webuser_groups_list': $out = webuser_groups_list(); break; case 'webuser_groups_json': $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $rs = webuser_group::all($_REQUEST['sidx'], $_REQUEST['sord']); $dataset = array(); foreach ($rs as $row) { $dataset[] = array('id' => $row->id, 'code' => $row->code, 'name' => $row->name); } $total = count($dataset); navitable::jqgridJson($dataset, $page, $offset, $max, $total, 'id'); session_write_close(); exit; break; case 'webuser_group_edit': $webuser_group = new webuser_group(); if (!empty($_REQUEST['id'])) { $webuser_group->load(intval($_REQUEST['id'])); } if (isset($_REQUEST['form-sent'])) { $webuser_group->load_from_post(); try { $ok = $webuser_group->save(); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); users_log::action($_REQUEST['fid'], $webuser_group->id, 'save_webuser_group', $webuser_group->name, json_encode($_REQUEST)); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } else { users_log::action($_REQUEST['fid'], $webuser_group->id, 'load_webuser_group', $webuser_group->name, json_encode($_REQUEST)); } $out = webuser_groups_form($webuser_group); break; case 'webuser_group_delete': $webuser_group = new webuser_group(); if (!empty($_REQUEST['id'])) { $webuser_group->load(intval($_REQUEST['id'])); } try { $webuser_group->delete(); $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = webuser_groups_list(); users_log::action($_REQUEST['fid'], $webuser_group->id, 'remove_webuser_group', $webuser_group->name, json_encode($_REQUEST)); } catch (Exception $e) { $out = $layout->navigate_message("error", t(24, 'Web users') . ' / ' . t(506, 'Groups'), t(56, 'Unexpected error.')); } break; case 0: // list / search result // list / search result case 'list': default: $out = webusers_list(); break; } return $out; }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new website(); switch ($_REQUEST['act']) { case 'json': case 1: // json data retrieval & operations switch ($_REQUEST['oper']) { case 'search_links': // active website only! $text = $_REQUEST['text']; $lang = $_REQUEST['lang']; if (empty($lang)) { $lang = array_keys($website->languages)[0]; } $DB->query(' SELECT p.path, d.text FROM nv_paths p, nv_webdictionary d WHERE p.website = ' . protect($website->id) . ' AND p.lang = ' . protect($lang) . ' AND d.website = p.website AND d.node_type = p.type AND d.node_id = p.object_id AND d.lang = p.lang AND d.subtype = "title" AND ( p.path LIKE ' . protect('%' . $text . '%') . ' OR d.text LIKE ' . protect('%' . $text . '%') . ' ) ORDER BY d.id DESC LIMIT 10 '); $result = $DB->result(); echo json_encode($result); core_terminate(); break; case 'del': // remove rows if ($user->permission('websites.delete') == 'true') { $ids = $_REQUEST['ids']; foreach ($ids as $id) { $item->load($id); $item->delete(); } echo json_encode(true); } core_terminate(); break; default: // list or search $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']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $DB->queryLimit('id,name,subdomain,domain,folder,homepage,permission,favicon', 'nv_websites', $where, $orderby, $offset, $max); $dataset = $DB->result(); $total = $DB->foundRows(); //echo $DB->get_last_error(); $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')); for ($i = 0; $i < count($dataset); $i++) { $homepage = 'http://'; $homepage_relative_url = $dataset[$i]['homepage']; if (is_numeric($homepage_relative_url)) { $homepage_relative_url = path::loadElementPaths('structure', $homepage_relative_url); $homepage_relative_url = array_shift($homepage_relative_url); } if (!empty($dataset[$i]['subdomain'])) { $homepage .= $dataset[$i]['subdomain'] . '.'; } $homepage .= $dataset[$i]['domain'] . $dataset[$i]['folder'] . $homepage_relative_url; $favicon = ''; if (!empty($dataset[$i]['favicon'])) { $favicon = '<img src="' . NVWEB_OBJECT . '?type=img&id=' . $dataset[$i]['favicon'] . '&width=16&height=16" align="absmiddle" height="16" />'; } $out[$i] = array(0 => $dataset[$i]['id'], 1 => $favicon, 2 => $dataset[$i]['name'], 3 => '<a href="' . $homepage . '" target="_blank"><img align="absmiddle" src="' . NAVIGATE_URL . '/img/icons/silk/house_link.png"></a> ' . $homepage, 4 => $permissions[$dataset[$i]['permission']]); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } session_write_close(); exit; break; case 'edit': case 2: // edit/new form if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); } if (isset($_REQUEST['form-sent']) && $user->permission('websites.edit') == 'true') { $item->load_from_post(); try { $item->save(); $id = $item->id; unset($item); $item = new website(); $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); } if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'save', $item->name, json_encode($_REQUEST)); } } else { if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'load', $item->name); } } $out = websites_form($item); break; case 'remove': case 4: if (!empty($_REQUEST['id']) && $user->permission('websites.delete') == 'true') { $item->load(intval($_REQUEST['id'])); if ($item->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->name, json_encode($_REQUEST)); } // if we don't have any websites, tell user a new one will be created $test = $DB->query_single('id', 'nv_websites'); if (empty($test) || !$test) { $layout->navigate_notification(t(520, 'No website found; a default one has been created.'), false, true); $nwebsite = new website(); $nwebsite->create_default(); } $out = websites_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = websites_form($item); } } break; 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 = ' . protect($_REQUEST['wid']) . ' ORDER BY path ASC LIMIT 30', 'array'); echo json_encode($DB->result()); core_terminate(); break; case 'email_test': $website->mail_mailer = $_REQUEST['mail_mailer']; $website->mail_server = $_REQUEST['mail_server']; $website->mail_port = $_REQUEST['mail_port']; $website->mail_address = $_REQUEST['mail_address']; $website->mail_user = $_REQUEST['mail_user']; $website->mail_security = $_REQUEST['mail_security'] == "true" || $_REQUEST['mail_security'] == "1" ? "1" : "0"; if (!empty($_REQUEST['mail_password'])) { $website->mail_password = $_REQUEST['mail_password']; } $ok = navigate_send_email(APP_NAME, APP_NAME . '<br /><br />' . NAVIGATE_URL, $_REQUEST['send_to']); echo json_encode($ok); core_terminate(); break; case 'reset_statistics': if ($user->permission('websites.edit') == 'true') { $website_id = trim($_REQUEST['website']); $website_id = intval($website_id); $DB->execute('UPDATE nv_items SET views = 0 WHERE website = ' . $website_id); $DB->execute('UPDATE nv_paths SET views = 0 WHERE website = ' . $website_id); $DB->execute('UPDATE nv_structure SET views = 0 WHERE website = ' . $website_id); echo 'true'; users_log::action($_REQUEST['fid'], $website_id, 'reset_statistics', "", json_encode($_REQUEST)); } core_terminate(); break; case 'replace_urls': $old = trim($_REQUEST['old']); $new = trim($_REQUEST['new']); $website_id = trim($_REQUEST['website']); if (!empty($old) && !empty($new)) { // replace occurrences in nv_webdictionary $ok = $DB->execute(' UPDATE nv_webdictionary SET text = replace(text, :old, :new) WHERE website = :wid', array(':old' => $old, ':new' => $new, ':wid' => $website_id)); // replace occurrences in nv_blocks (triggers & actions) $ok = $DB->execute(' UPDATE nv_blocks SET `trigger` = replace(`trigger`, :old, :new), `action` = replace(`action`, :old, :new) WHERE website = :wid', array(':old' => $old, ':new' => $new, ':wid' => $website_id)); echo $ok ? 'true' : 'false'; if ($ok) { users_log::action($_REQUEST['fid'], $website_id, 'replace_urls', "", json_encode($_REQUEST)); } } else { echo 'false'; } core_terminate(); break; case 'remove_content': $website_id = trim($_REQUEST['website']); $website_id = intval($website_id); $password = trim($_REQUEST['password']); $authenticated = $user->authenticate($user->username, $password); if ($authenticated) { // remove all content except Webusers and Files @set_time_limit(0); $ok = $DB->execute(' DELETE FROM nv_blocks WHERE website = ' . $website_id . '; DELETE FROM nv_block_groups WHERE website = ' . $website_id . '; DELETE FROM nv_comments WHERE website = ' . $website_id . '; DELETE FROM nv_structure WHERE website = ' . $website_id . '; DELETE FROM nv_feeds WHERE website = ' . $website_id . '; DELETE FROM nv_items WHERE website = ' . $website_id . '; DELETE FROM nv_notes WHERE website = ' . $website_id . '; DELETE FROM nv_paths WHERE website = ' . $website_id . '; DELETE FROM nv_properties WHERE website = ' . $website_id . '; DELETE FROM nv_properties_items WHERE website = ' . $website_id . '; DELETE FROM nv_search_log WHERE website = ' . $website_id . '; DELETE FROM nv_webdictionary WHERE website = ' . $website_id . '; DELETE FROM nv_webdictionary_history WHERE website = ' . $website_id . '; '); if ($ok) { users_log::action($_REQUEST['fid'], $website_id, 'remove_content', "", json_encode($_REQUEST)); } echo $ok ? 'true' : $DB->error(); } else { echo ''; } core_terminate(); break; case 0: // list / search result // list / search result default: $out = websites_list(); break; } return $out; }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new feed(); switch ($_REQUEST['act']) { 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 $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = " f.website = " . $website->id; 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']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $sql = ' SELECT SQL_CALC_FOUND_ROWS f.*, d.text as title FROM nv_feeds f LEFT JOIN nv_webdictionary d ON f.id = d.node_id AND d.node_type = "feed" AND d.subtype = "title" AND d.lang = "' . $website->languages_list[0] . '" AND d.website = ' . $website->id . ' WHERE ' . $where . ' 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(); $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 => count(explode(',', $dataset[$i]['categories'])), 3 => $dataset[$i]['format'], 4 => $dataset[$i]['views'], 5 => $permissions[$dataset[$i]['permission']], 6 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />'); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } core_terminate(); break; 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(); $id = $item->id; unset($item); $item = new feed(); $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); } } $out = feeds_form($item); 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 = feeds_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = feeds_list(); } } break; case "path_check": // check if a requested path is not used $path = $_REQUEST['path']; $id = $_REQUEST['id']; $DB->query('SELECT type, object_id, lang FROM nv_paths WHERE path = ' . protect($path) . ' AND website = ' . $website->id); $rs = $DB->result(); echo json_encode($rs); core_terminate(); break; case 0: // list / search result // list / search result default: $out = feeds_list(); break; } return $out; }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new backup(); switch ($_REQUEST['act']) { 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 $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = " i.website = " . $website->id; 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']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $sql = ' SELECT SQL_CALC_FOUND_ROWS i.* FROM nv_backups i WHERE ' . $where . ' 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(); $out = array(); if (empty($dataset)) { $rows = 0; } else { $rows = count($dataset); } for ($i = 0; $i < $rows; $i++) { $out[$i] = array(0 => $dataset[$i]['id'], 1 => core_ts2date($dataset[$i]['date_created'], true), 2 => $dataset[$i]['title'], 3 => core_bytes($dataset[$i]['size']), 4 => backup::status($dataset[$i]['status'])); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } core_terminate(); break; case 2: // edit/new form if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); } if ($_REQUEST['form-sent'] == 'true') { $item->load_from_post(); try { // update an existing backup $item->save(); $id = $item->id; $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } $out = backups_form($item); 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 = backups_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = webdictionary_list(); } } break; case 'backup': if (!empty($_REQUEST['id'])) { // trick to generate a underground process ;) @set_time_limit(0); @ignore_user_abort(true); $foo = str_pad('Navigate CMS ', 2048, 'Navigate CMS '); header("HTTP/1.1 200 OK"); header("Content-Length: " . strlen($foo)); echo $foo; header('Connection: close'); ob_end_flush(); ob_flush(); flush(); session_write_close(); // now the process is running in the server, the client thinks the http request has finished $item->load(intval($_REQUEST['id'])); $item->backup(); } core_terminate(); break; case 'restore': // TO DO: Restore break; case 'download': // download backup $item->load(intval($_REQUEST['id'])); ob_end_flush(); header('Content-type: application/zip'); header("Content-Length: " . filesize(NAVIGATE_PRIVATE . $item->file)); header('Content-Disposition: attachment; filename="' . basename($item->file) . '"'); readfile(NAVIGATE_PRIVATE . $item->file); core_terminate(); break; case 0: // list / search result // list / search result default: $out = backups_list(); break; } return $out; }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new comment(); 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 $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = ' website = ' . $website->id; 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']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $DB->queryLimit('id,item,user,email,date_created,status,message', 'nv_comments', $where, $orderby, $offset, $max); $dataset = $DB->result(); $total = $DB->foundRows(); //echo $DB->get_last_error(); $out = array(); $permissions = array(-1 => '<img src="img/icons/silk/new.png" align="absmiddle" /> ' . t(257, 'To review'), 0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(64, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(251, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(181, 'Hidden'), 3 => '<img src="img/icons/silk/error.png" align="absmiddle" /> ' . t(466, 'Spam')); for ($i = 0; $i < count($dataset); $i++) { if (empty($dataset[$i])) { continue; } // retrieve webuser name $webuser = $DB->query_single('username', 'nv_webusers', ' id = ' . $dataset[$i]['user']); // retrieve item title $item = new item(); $item->load($dataset[$i]['item']); $title = $item->dictionary[$website->languages_list[0]]['title']; $message = core_string_clean($dataset[$i]['message']); $message = core_string_cut($message, 60, '…'); $out[$i] = array(0 => $dataset[$i]['id'], 1 => $title, 2 => core_ts2date($dataset[$i]['date_created'], true), 3 => empty($dataset[$i]['user']) ? $dataset[$i]['email'] : $webuser, 4 => strip_tags($message), 5 => $permissions[$dataset[$i]['status']]); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } session_write_close(); exit; break; case 2: // edit/new form // edit/new form case 'edit': 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('comment', $item->id); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'save', $item->name, json_encode($_REQUEST)); } } else { if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'load', $item->name); } } $out = comments_form($item); break; case 4: // remove // remove case 'remove': if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = comments_list(); if (!empty($item->id)) { users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->name, json_encode($_REQUEST)); } } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = comments_form($item); } } break; case 'remove_spam': $count = comment::remove_spam(); $layout->navigate_notification(t(524, 'Items removed successfully') . ': <strong>' . $count . '</strong>', false); $out = comments_list(); users_log::action($_REQUEST['fid'], $website->id, 'remove_spam', "", json_encode($_REQUEST)); break; case 'json_find_webuser': // json find webuser by name (for "user" autocomplete) $DB->query('SELECT id, username as text FROM nv_webusers WHERE username LIKE ' . protect('%' . $_REQUEST['username'] . '%') . ' ORDER BY username ASC LIMIT 30', 'array'); $rows = $DB->result(); $total = $DB->foundRows(); echo json_encode(array('items' => $rows, 'totalCount' => $total)); core_terminate(); break; case 'json_find_comment': // json find comment by text search (for "in reply to" autocomplete) $DB->query('SELECT c.id, c.date_created, c.name, u.username, c.message FROM nv_comments c LEFT JOIN nv_webusers u ON c.user = u.id WHERE c.website = ' . $website->id . ' AND c.item = ' . $_REQUEST['node_id'] . ' AND c.date_created <= ' . $_REQUEST['maxdate'] . ' AND c.id <> ' . $_REQUEST['exclude'] . ' AND ( c.name LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' OR c.message LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' OR u.username LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' ) ORDER BY c.date_created DESC LIMIT 30', 'array'); $rows = $DB->result(); $total = $DB->foundRows(); for ($r = 0; $r < count($rows); $r++) { $rows[$r]['text'] = '<span title="' . core_string_cut($rows[$r]['message'], 100) . '"><i class="fa fa-user"></i> ' . $rows[$r]['name'] . $rows[$r]['username'] . ' <i class="fa fa-clock-o"></i> ' . core_ts2date($rows[$r]['date_created'], true) . '</span>'; } echo json_encode(array('items' => $rows, 'totalCount' => $total)); core_terminate(); break; case 91: // json search title request (for "item" autocomplete) $DB->query('SELECT DISTINCT node_id as id, text as label, text as value FROM nv_webdictionary WHERE node_type = "item" AND subtype = "title" AND website = ' . $website->id . ' AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . ' ORDER BY text ASC LIMIT 30', 'array'); // AND lang = '.protect($_REQUEST['lang']).' echo json_encode($DB->result()); session_write_close(); exit; break; case 0: // list / search result // list / search result default: $out = comments_list(); break; } return $out; }
public static function jqgridCheck($row, $filters) { $filters = json_decode($filters); if ($filters->groupOp == 'OR') { $result = false; } else { $result = true; } foreach ($filters->rules as $rule) { if ($filters->groupOp == 'OR') { $result = $result || navitable::jqgridcompare($row[$rule->field], $rule->op, $rule->data, true); } else { $result = $result && navitable::jqgridcompare($row[$rule->field], $rule->op, $rule->data, true); } } return $result; }