Project

General

Profile

« Previous | Next » 

Revision 2087

Added by darkviper over 10 years ago

! admin/pages/add class AccessFile implemented

View differences:

add.php
25 25
}
26 26
// Create new admin object and print admin header
27 27
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
28
$oReg  = WbAdaptor::getInstance();
29
$oDb   = WbDatabase::getInstance();
28 30
$mLang = Translate::getinstance();
29 31
$mLang->enableAddon('admin\pages');
30 32

  
......
50 52
$viewing_groups = $admin->get_post('viewing_groups');
51 53

  
52 54
// Work-out if we should check for existing page_code
53
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
55
$field_set = $oDb->isField($oDb->TablePrefix.'pages', 'page_code');
54 56

  
55 57
// add Admin to admin and viewing-groups
56 58
$admin_groups[] = 1;
......
155 157
}
156 158

  
157 159
// Check if a page with same page filename exists
158
//$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
160
//$get_same_page = $oDb->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
159 161
//if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
160 162
//{
161 163
//	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
......
163 165
$bLinkExists = file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) || file_exists(WB_PATH.PAGES_DIRECTORY.$link);
164 166

  
165 167
// UNLOCK TABLES
166
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'pages` '
168
$sql = 'SELECT COUNT(*) FROM `'.$oDb->TablePrefix.'pages` '
167 169
     . 'WHERE `link` = \''.$link.'\' ';
168
if( (($iSamePages = intval($database->get_one($sql))) > 0) || $bLinkExists ){
170
if( (($iSamePages = intval($oDb->getOne($sql))) > 0) || $bLinkExists ){
169 171
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
170 172
}
171 173

  
172 174
// Include the ordering class
173 175
require(WB_PATH.'/framework/class.order.php');
174
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
176
$order = new order($oDb->TablePrefix.'pages', 'position', 'page_id', 'parent');
175 177
// First clean order
176 178
$order->clean($parent);
177 179
// Get new order
178 180
$position = $order->get_new($parent);
179 181

  
180 182
// Work-out if the page parent (if selected) has a seperate template or language to the default
181
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
183
$query_parent = $oDb->doQuery("SELECT template, language FROM ".$oDb->TablePrefix."pages WHERE page_id = '$parent'");
182 184
if($query_parent->numRows() > 0)
183 185
{
184 186
	$fetch_parent = $query_parent->fetchRow();
......
190 192
}
191 193

  
192 194
// Insert page into pages table
193
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` ';
194
$sql .= 'SET `parent` = '.$parent.', ';
195
$sql .= '`target` = "_top", ';
196
$sql .= '`page_title` = "'.$title.'", ';
197
$sql .= '`menu_title` = "'.$title.'", ';
198
$sql .= '`tooltip` = "'.$title.'", ';
199
$sql .= '`template` = "'.$template.'", ';
200
$sql .= '`visibility` = "'.$visibility.'", ';
201
$sql .= '`position` = '.$position.', ';
202
$sql .= '`menu` = 1, ';
203
$sql .= '`language` = "'.$language.'", ';
204
$sql .= '`searching` = 1, ';
205
$sql .= '`modified_when` = '.time().', ';
206
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
207
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
208
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
195
$sql = 'INSERT INTO `'.$oDb->TablePrefix.'pages` '
196
     . 'SET `parent` = '.$parent.', '
197
     .     '`target` = \'_top\', '
198
     .     '`page_title` = \''.$title.'\', '
199
     .     '`menu_title` = \''.$title.'\', '
200
     .     '`tooltip` = \''.$title.'\', '
201
     .     '`template` = \''.$template.'\', '
202
     .     '`visibility` = \''.$visibility.'\', '
203
     .     '`position` = '.$position.', '
204
     .     '`menu` = 1, '
205
     .     '`language` = \''.$language.'\', '
206
     .     '`searching` = 1, '
207
     .     '`modified_when` = '.time().', '
208
     .     '`modified_by` = '.$admin->get_user_id().', '
209
     .     '`admin_groups` = \''.$admin_groups.'\', '
210
     .     '`viewing_groups` = \''.$viewing_groups.'\'';
209 211

  
210
if(!$database->query($sql)) {
211
	if($database->is_error())
212
if(!$oDb->doQuery($sql)) {
213
	if($oDb->isError())
212 214
	{
213
		$admin->print_error($database->get_error());
215
		$admin->print_error($oDb->getError());
214 216
	}
215 217
}
216 218

  
217 219
// Get the page id
218
//$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
219
$page_id = $database->LastInsertId;
220
//$page_id = $oDb->getOne("SELECT LAST_INSERT_ID()");
221
$page_id = $oDb->LastInsertId;
220 222
// Work out level
221 223
$level = level_count($page_id);
222 224
// Work out root parent
......
225 227
$page_trail = get_page_trail($page_id);
226 228

  
227 229
/*
228
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
230
$oDb->doQuery("UPDATE ".$oDb->TablePrefix."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
229 231
*/
230 232
// Update page with new level and link
231
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
232
$sql .= '`root_parent` = '.$root_parent.', ';
233
$sql .= '`level` = '.$level.', ';
234
$sql .= '`link` = \''.$link.'\', ';
235
$sql .= '`page_trail` = \''.$page_trail.'\'';
236
$sql .= ((defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && ($language == DEFAULT_LANGUAGE)
237
                                    && class_exists('m_MultiLingual_Lib') ? ', `page_code` = '.(int)$page_id.' ' : ' ');
238
$sql .= 'WHERE `page_id` = '.$page_id;
239
$database->query($sql);
240
if($database->is_error())
233
$sql = 'UPDATE `'.$oDb->TablePrefix.'pages` '
234
     . 'SET `root_parent` = '.$root_parent.', '
235
     .     '`level` = '.$level.', '
236
     .     '`link` = \''.$link.'\', '
237
     .     '`page_trail` = \''.$page_trail.'\' '
238
     .     ( (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set
239
              && ($language == DEFAULT_LANGUAGE) && class_exists('m_MultiLingual_Lib')
240
             ? ', `page_code` = '.(int)$page_id.' '
241
             : ''
242
           )
243
     . 'WHERE `page_id` = '.$page_id;
244
$oDb->doQuery($sql);
245
if($oDb->isError())
241 246
{
242
	$admin->print_error($database->get_error());
247
	$admin->print_error($oDb->getError());
243 248
}
244 249

  
245 250
// add position 1 to new page section
......
247 252

  
248 253
// Add new record into the sections table
249 254
// Insert module into DB
250
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` ';
251
$sql .= 'SET `page_id` = '.(int)$page_id.', ';
252
$sql .= '`module` = \''.$module.'\', ';
253
$sql .= '`position` = '.(int)$position.', ';
254
$sql .= '`block` = \'1\', ';
255
$sql .= '`publ_start` = \'0\',';
256
$sql .= '`publ_end` = \'0\' ';
257
if($database->query($sql)) {
255
$sql = 'INSERT INTO `'.$oDb->TablePrefix.'sections` '
256
     . 'SET `page_id` = '.(int)$page_id.', '
257
     .     '`module` = \''.$module.'\', '
258
     .     '`position` = '.(int)$position.', '
259
     .     '`block` = \'1\', '
260
     .     '`publ_start` = \'0\','
261
     .     '`publ_end` = \'0\' ';
262
if($oDb->doQuery($sql)) {
258 263
	// Get the section id
259
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
264
	$section_id = $oDb->getOne("SELECT LAST_INSERT_ID()");
260 265
	// Include the selected modules add file if it exists
261 266
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
262 267
    {
263 268
		require(WB_PATH.'/modules/'.$module.'/add.php');
264 269
	}
265 270
}
266

  
267 271
// Create a new file in the /pages dir
268
create_access_file($filename, $page_id, $level);
269

  
270
if(!file_exists($filename)) {
271
	$admin->print_error($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE);
272
$sNewLink = str_replace($oReg->AppPath.$oReg->PagesDir, '', str_replace('\\', '/', $filename));
273
try{
274
    $oAccFile = new AccessFile($oReg->AppPath.$oReg->PagesDir, $sNewLink, $page_id);
275
    $oAccFile->write();
276
    unset($oAccFile);
277
} catch (AccessFileException $e) {
278
    $sMsg = $oLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE
279
          . '<br />'.$e->getMessage();
280
    $admin->print_error($sMsg);
272 281
}
273

  
274 282
// Check if there is a db error, otherwise say successful
275
if($database->is_error()) {
276
	$admin->print_error($database->get_error().' (sections)');
283
if($oDb->isError()) {
284
	$admin->print_error($oDb->getError().' (sections)');
277 285
} else {
278 286
	$admin->print_success($mLang->MESSAGE_PAGES_ADDED, ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
279 287
}

Also available in: Unified diff