www.hsifin.com /html/AppCode/expressionengine/third_party/ndg_flexible_admin/mod.ndg_flexible_admin.php

Language PHP Lines 210
MD5 Hash 79dbe0830cb9ab101d911bc4a3096f69
Repository https://github.com/w3bg/www.hsifin.com.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

error_reporting(1);
ini_set('display_errors', TRUE);

require('libraries/JSON.php');

/**
 * Core Module file for NDG Flexible Admin
 *
 * This file must be in your /system/third_party/ndg_flexible_admin directory of your ExpressionEngine installation
 *
 * @package             NDG Flexible Admin for EE2
 * @author              Nico De Gols (nicodegols@me.com)
 * @copyright			Copyright (c) 2010 Nico De Gols
 * @version             Release: 1.0
 * @link                http://pixelclub.be
 */

class Ndg_flexible_admin {

	function Ndg_flexible_admin()
	{	
		$this->EE =& get_instance();
		$this->EE->output->enable_profiler(FALSE);
	}
	
	function ajax_preview(){
		$this->EE->output->enable_profiler(FALSE);
		echo $this->get_tree_html($this->EE->input->post('jsontree'));
	}
	
	function my_strip_tags($str) {
		$str = strip_tags($str, "<img>");
	    $pos1 = strpos($str,'<img');
		$pos1 = (!$pos1) ? strpos($str,'<IMG'):$pos1;
		$pos2 = strpos($str,'>', $pos1);
	        if($pos1 && $pos2){
				$img = "<img src=".$this->EE->config->item('theme_folder_url')."cp_themes/default/images/home_icon.png />";
	            $str = substr_replace($str, $img, $pos1, $pos2-$pos1+1);
	    }
	    return $str;   
	}
	
	function get_tree_ul($child){
		$navhtml = "";
		if(count($child->children) > 0){
				$navhtml .= '<ul class="">';
				foreach($child->children as $subchild){
					$navhtml .= '<li class="'.$subchild->className.'" id="'.$subchild->id.'"><a href="'.$subchild->url.'">'.$subchild->title.'</a>';
					$navhtml .= $this->get_tree_ul($subchild);
					$navhtml .= '</li>';
				}
				$navhtml .= '</ul>';
		}
		return $navhtml;
	}

	function get_tree_html($jsontree){
	
		$this->EE->output->enable_profiler(FALSE);
		$cpurl = $this->EE->config->item('cp_url');
		
		$pieces = explode("/",$cpurl);
		$cpurl_index = $pieces[count($pieces)-1];

		$jsontree = str_replace("'",'"',(string)$jsontree);
		
		$jsontree = $this->my_strip_tags($jsontree);



		$jsontree = str_replace('EDIT','',$jsontree);
		$jsontree = str_replace('DELETE','',$jsontree);
		$jsontree = str_replace('&nbsp;','',$jsontree);
	
		    $json = new Services_JSON();
			
		    $json_decoded = $json->decode($jsontree);
		
			$navhtml = '';
			foreach($json_decoded as $item){

				$navhtml .= '<li class="'.$item->className.'"  id="'.$item->id.'" ><a href="'.$item->url.'" class="first_level">'.str_replace('"', '\"',$item->title).'</a>';
				$navhtml .= $this->get_tree_ul($item);
				$navhtml .= '</li>';
			}
			
		return $navhtml;	
	}

	function ajax_load_tree()
	{
		$this->EE->output->enable_profiler(FALSE);
	
		$site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
		$this->EE->db->select('nav');
		$this->EE->db->where('group_id', $this->EE->input->post("group_id")); 
		$this->EE->db->where('site_id', $site_id); 
		$this->EE->db->from($this->EE->db->dbprefix('ndg_flexible_admin_menus'));

		$query = $this->EE->db->get();

		if ($query->num_rows() == 0)
		{
			echo "no_nav_found";
		}else{
			echo strpos($query->row()->nav, "'");
			echo str_replace("'",'"',$query->row()->nav);
		}
	}
	
	function ajax_load_settings()
	{
		$this->EE->output->enable_profiler(FALSE);
	
		$site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
		$this->EE->db->select('nav, autopopulate');
		$this->EE->db->where('group_id', $this->EE->input->post("group_id")); 
		$this->EE->db->where('site_id', $site_id); 
		$this->EE->db->from($this->EE->db->dbprefix('ndg_flexible_admin_menus'));

		$query = $this->EE->db->get();

		if ($query->num_rows() == 0)
		{
			echo '{ "autopopulate" : "false" }';
		}else{
			echo '{ "autopopulate" : "'.$query->row()->autopopulate.'" }';
		}	
	}
	
	function ajax_save_tree()
	{
		$this->EE->output->enable_profiler(FALSE);
		
		$new = TRUE;

		$site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
		$group_id = $this->EE->input->post('group_id');
		$autopopulate = ($this->EE->input->post('autopopulate') == "true")? 1 : 0;
		$nav_content = $this->get_tree_html($this->EE->input->post('jsontree'));
		
		$nav_content = str_replace('S='.$this->EE->session->userdata("session_id").'&',"",$nav_content);
		if ($group_id == '' || $nav_content == '')
		{
			echo "cannot_save";
		}else{
				
			$results = $this->EE->db->query("SELECT group_id FROM ".$this->EE->db->dbprefix('ndg_flexible_admin_menus')." WHERE group_id = '".$group_id."'");
						
			if ($results->num_rows() == 0)
			{
				$data = array(
					'site_id'			=> $site_id,
					'group_id'			=> $group_id,
					'nav'				=> $nav_content,
					'autopopulate'		=> $autopopulate
				);
				
				$this->EE->db->query($this->EE->db->insert_string($this->EE->db->dbprefix('ndg_flexible_admin_menus'), $data));

				$cp_message = 'added';
			}
			else
			{
				$data = array(
					'nav'				=> $nav_content,
					'autopopulate'		=> $autopopulate
				);
				
				$where = array(
					'group_id' 		=> $group_id, 
					'site_id' 		=> $site_id
				);
				 
				$this->EE->db->query($this->EE->db->update_string($this->EE->db->dbprefix('ndg_flexible_admin_menus'), $data, $where));
				$cp_message = 'updated';
			}
			if ($this->EE->db->affected_rows() > 0) {
			    echo $cp_message;
			}else{
				echo "no_affected_rows";
			}
		}
		
	}
	
	function ajax_remove_tree()
	{
		$this->EE->output->enable_profiler(FALSE);
		
		$site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
		$group_id = $this->EE->input->post('group_id');
		
		$this->EE->db->where('site_id', $site_id);
		$this->EE->db->where('group_id', $group_id);
		$this->EE->db->delete($this->EE->db->dbprefix('ndg_flexible_admin_menus'));
		
		if ($this->EE->db->affected_rows() > 0) {
		    echo "removed";
		}else{
			echo "no_affected_rows";
		}
	}
		
}

/* End of file mod.ndg_flexible_admin.php */
/* Location: ./system/expressionengine/third_party/Cpnav/mod.ndg_flexible_admin.php */
Back to Top