Repository navigation
Expand file tree
/
Copy pathOffice.php
More file actions
236 lines (213 loc) · 7.56 KB
/
Copy pathOffice.php
File metadata and controls
236 lines (213 loc) · 7.56 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/**
* M PHP Framework
*
*
* @package M
* @subpackage M_Office
* @author Arnaud Sellenet <demental at github>
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
* @version 0.1
*/
if(!defined('ROOT_ADMIN_SCRIPT')) {
define('ROOT_ADMIN_SCRIPT','');
}
if(!defined('OFFICE_TEMPLATES_FOLDER')) {
define('OFFICE_TEMPLATES_FOLDER', realpath(dirname(__FILE__)).'/Office/Templates/');
}
$dispatchopt = &PEAR::getStaticProperty('Dispatcher', 'global');
T::addPath(dirname(__FILE__).'/Office/lang/');
/**
*
* "Office" application dispatcher
* The office application is one of the most powerful features of the M framework.
* It's also the one that needs most refactoring
* This was originally base upon Justin Patrin's PEAR_DB_DataObject_FormBuilder_Frontend
*
*
*/
class M_Office extends M_Office_Controller implements iListener {
public static $dsp='__defaut/index';
public function __construct($layout = 'main') {
parent::__construct();
$setup = new M_Office_Setup($this);
$setup->setup();
try {
$this->run();
} catch(Exception $e) {
M_Office::$dsp='__defaut/error';
Mreg::get('tpl')->assign('__action','error');
Mreg::get('tpl')->assign('message', $e->getMessage());
Mreg::get('tpl')->assign('error', $e);
}
}
public function run()
{
$this->ajaxAuth=true;
if($this->getOption('auth')){
$this->ajaxAuth=false;
$subController = new M_Office_Auth($_REQUEST['database']);
if(!key_exists('adminPrivileges',$_SESSION) || key_exists('logout',$_REQUEST)){
$this->assign('username',User::getInstance('office')->getProperty('username'));
$this->ajaxAuth=true;
} elseif(!User::getInstance('office')->isLoggedIn()) {
$this->ajaxAuth=false;
} else {
$subController->initOptions();
$this->assign('username',User::getInstance('office')->getProperty('username'));
}
}
$not = Notifier::getInstance();
$not->addListener($this);
if($this->getOption('auth') && !User::getInstance('office')->isLoggedIn()) {
if(self::isAjaxRequest()) {
$this->assign('__action','ajaxlogin');
}
return;
}
if(key_exists('updateSuccess',$_REQUEST)) {
$this->say(__('Record was successfully updated'));
M_Office_Util::clearRequest(array('updateSuccess'=>1));
}
if(isset($_REQUEST['module'])) {
$info = M_Office_Util::getModuleInfo($_REQUEST['module']);
$module = $_REQUEST['module'];
if(!$info) {
if(strpos($_REQUEST['module'],':')) {
$info = array('type'=>'dyn','title'=>'Plugin');
$module = $tab[1];
}elseif(preg_match('`^(.+)helper$`',$_REQUEST['module'],$tab)) {
$info = array('type'=>'dyn','title'=> __("modules.{$tab[1]}helper.title"));
$module = $_REQUEST['module'];
} else {
throw new NotFoundException(__('error.module_not_found', array($_REQUEST['module'])));
}
}
}
if($this->isAjaxRequest() && $this->ajaxAuth && $info['type']!='dyn') {
$this->output='';
unset($this->localOutput);
}
if (isset($_REQUEST['debug']) && MODE == 'development') {
$debug=(int)$_REQUEST['debug']%3;
DB_DataObject::debugLevel($debug);
ini_set('display_errors',1);
}
if($_REQUEST['livesearch']) {
$aj = new M_Office_livesearch($_REQUEST['searchtext'],$_REQUEST['expand']);
$this->output = $aj->processRequest();
return;
} elseif($_REQUEST['treesort']) {
$aj = new M_Office_treesort();
$this->output=$aj->processRequest();
return;
} elseif($_REQUEST['liveedit']) {
$aj = new M_Office_liveedit($_REQUEST['liveedit']);
$this->output=$aj->processRequest();
return;
} elseif(key_exists('ajaxfromtable',$_REQUEST)) {
$table = $_REQUEST['module'];
$do = DB_DataObject::factory($table);
$do->get($_REQUEST['filterField'],$_REQUEST['filterValue']);
$aj = new M_Office_ajaxFromTable($do,$_REQUEST['module'],$_REQUEST['module'],$_REQUEST['filterField'],$_REQUEST['filterValue']);
$this->output = $aj->processRequest();
return;
}
if(isset($_REQUEST['module'])) {
if(!$info) {
$info = M_Office_Util::getModuleInfo($_REQUEST['module']);
}
switch($info['type']) {
case 'db':
// TODO ajouter ce path en avant-dernier et non en dernier
Mreg::get('tpl')->addPath(APP_ROOT.'app/'.APP_NAME.'/templates/'.$info['table'].'/','after');
Mreg::get('tpl')->addPath(APP_ROOT.'app/'.APP_NAME.'/templates/'.$_REQUEST['module'].'/','after');
$subController = new M_Office_ShowTable($_REQUEST['module'],$filter);
break;
case 'dyn':
// home module = available for everyone
$allowAccess = $_REQUEST['module'] == 'home' || M_Office_Util::getGlobalOption('view','showtable',$_REQUEST['module']);
if(!$allowAccess) {
Log::warn('User is NOT allowed to access '.$_REQUEST['module']);
M_Office_Util::refresh(M_Office::URL(array(),array_keys($_REQUEST)));
} else {
Log::info('User is allowed to access '.$_REQUEST['module']);
}
$subController = Module::factory($_REQUEST['module'], M::getPaths('module'));
$subController->executeAction($_REQUEST['action']?$_REQUEST['action']:'index');
$this->assign('__action','dyn');
$layout = $subController->getConfig('layout',$_REQUEST['action']?$_REQUEST['action']:'index');
if($layout=='__self') {
M_Office::$dsp='__defaut/ajaxindex';
} elseif($layout) {
M_Office::$dsp=$layout;
}
$this->assign('output',$subController->output(null,'__self'));
break;
}
$this->assign('currentmodule',$_REQUEST['module']);
} else {
$subController = new M_Office_FrontEndHome();
}
}
public function display() {
echo $this->fetch();
}
public function fetch()
{
try {
$tpl = Mreg::get('tpl');
$tpl->concat('adminTitle',' :: '.$this->getOption('adminTitle'));
if(self::isAjaxRequest()) {
M_Office::$dsp='__defaut/ajaxindex';
$vars = $tpl->getVars();
$action = $vars['__action'];
if(!is_array($action)) {
$tpl->assign('__action',array($action.'.bloc',$action));
}
}
$tables = $this->getGlobalOption('searchInTables','frontendhome');
if(array_key_exists('flashmessages', $_SESSION)) {
$tpl->assign('messages', $_SESSION['flashmessages']);
}
if(count($tables)==0) {
$tpl->assign('showlivesearch',false);
} else {
$tpl->assign('showlivesearch',true);
}
return $tpl->fetch(M_Office::$dsp);
} catch(Exception $e) {
M_Office::$dsp='__defaut/error';
$tpl->assign('message', $e->getMessage());
$tpl->assign('error', $e);
return $tpl->fetch(M_Office::$dsp);
}
}
public function getEvents() {
return array('notification');
}
public function handleEvent($sender,$event,&$params = null) {
$_SESSION['flashmessages'][]=array($params,$event);
}
public static function isAjaxRequest() {
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])=='xmlhttprequest' || $_REQUEST['__ajax'];
}
// ==============================
// = Proxy (for faster writing) =
// ==============================
public static function cleanURL($params = array(), $remove = array(), $entities = false) {
return self::URL($params,$remove,$entities,true);
}
public static function URL($params = array(), $remove = array(), $entities = false,$clean = false)
{
if(!is_array($params)) {
$tmp = explode('/',$params);
$params = $remove;
$params['module'] = $tmp[0];
$params['action'] = $tmp[1];
$remove = $entities;
$entities = false;
}
return M_Office_Util::getQueryParams($params,$remove,$entities,$clean);
}
}