| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       *
 
     | 
  
  
    | 
      4
     | 
    
       * @category        admin
 
     | 
  
  
    | 
      5
     | 
    
       * @package         pages
 
     | 
  
  
    | 
      6
     | 
    
       * @author          WebsiteBaker Project
 
     | 
  
  
    | 
      7
     | 
    
       * @copyright       2004-2009, Ryan Djurovich
 
     | 
  
  
    | 
      8
     | 
    
       * @copyright       2009-2011, Website Baker Org. e.V.
 
     | 
  
  
    | 
      9
     | 
    
       * @link			http://www.websitebaker2.org/
 
     | 
  
  
    | 
      10
     | 
    
       * @license         http://www.gnu.org/licenses/gpl.html
 
     | 
  
  
    | 
      11
     | 
    
       * @platform        WebsiteBaker 2.8.x
 
     | 
  
  
    | 
      12
     | 
    
       * @requirements    PHP 5.2.2 and higher
 
     | 
  
  
    | 
      13
     | 
    
       * @version         $Id: add.php 1425 2011-02-03 23:16:12Z Luisehahne $
 
     | 
  
  
    | 
      14
     | 
    
       * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
 
     | 
  
  
    | 
      15
     | 
    
       * @lastmodified    $Date: 2011-02-04 00:16:12 +0100 (Fri, 04 Feb 2011) $
 
     | 
  
  
    | 
      16
     | 
    
       *
 
     | 
  
  
    | 
      17
     | 
    
       */
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      // Create new admin object and print admin header
 
     | 
  
  
    | 
      20
     | 
    
      require('../../config.php');
     | 
  
  
    | 
      21
     | 
    
      require_once(WB_PATH.'/framework/class.admin.php');
 
     | 
  
  
    | 
      22
     | 
    
      $admin = new admin('Pages', 'pages_add');
     | 
  
  
    | 
      23
     | 
    
      
 
     | 
  
  
    | 
      24
     | 
    
      if (!$admin->checkFTAN())
 
     | 
  
  
    | 
      25
     | 
    
      {
     | 
  
  
    | 
      26
     | 
    
      	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
 
     | 
  
  
    | 
      27
     | 
    
      	exit();
 
     | 
  
  
    | 
      28
     | 
    
      }
 
     | 
  
  
    | 
      29
     | 
    
      
 
     | 
  
  
    | 
      30
     | 
    
      // Include the WB functions file
 
     | 
  
  
    | 
      31
     | 
    
      require_once(WB_PATH.'/framework/functions.php');
 
     | 
  
  
    | 
      32
     | 
    
      
 
     | 
  
  
    | 
      33
     | 
    
      // Get values
 
     | 
  
  
    | 
      34
     | 
    
      $title = $admin->get_post_escaped('title');
     | 
  
  
    | 
      35
     | 
    
      $title = htmlspecialchars($title);
 
     | 
  
  
    | 
      36
     | 
    
      $module = preg_replace("/\W/", "", $admin->get_post('type')); // fix secunia 2010-93-4
     | 
  
  
    | 
      37
     | 
    
      $parent = (int) $admin->get_post('parent'); // fix secunia 2010-91-2
     | 
  
  
    | 
      38
     | 
    
      $visibility = $admin->get_post('visibility');
     | 
  
  
    | 
      39
     | 
    
      if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
     | 
  
  
    | 
      40
     | 
    
      $admin_groups = $admin->get_post('admin_groups');
     | 
  
  
    | 
      41
     | 
    
      $viewing_groups = $admin->get_post('viewing_groups');
     | 
  
  
    | 
      42
     | 
    
      
 
     | 
  
  
    | 
      43
     | 
    
      // Work-out if we should check for existing page_code
 
     | 
  
  
    | 
      44
     | 
    
      $sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
 
     | 
  
  
    | 
      45
     | 
    
      $field_sql = $database->query($sql);
 
     | 
  
  
    | 
      46
     | 
    
      $field_set = $field_sql->numRows();
 
     | 
  
  
    | 
      47
     | 
    
      
 
     | 
  
  
    | 
      48
     | 
    
      // add Admin to admin and viewing-groups
 
     | 
  
  
    | 
      49
     | 
    
      $admin_groups[] = 1;
 
     | 
  
  
    | 
      50
     | 
    
      $viewing_groups[] = 1;
 
     | 
  
  
    | 
      51
     | 
    
      
 
     | 
  
  
    | 
      52
     | 
    
      // check parent page permissions:
 
     | 
  
  
    | 
      53
     | 
    
      if ($parent!=0) {
     | 
  
  
    | 
      54
     | 
    
      	if (!$admin->get_page_permission($parent,'admin'))
 
     | 
  
  
    | 
      55
     | 
    
          {
     | 
  
  
    | 
      56
     | 
    
              $admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
 
     | 
  
  
    | 
      57
     | 
    
          }
 
     | 
  
  
    | 
      58
     | 
    
      
 
     | 
  
  
    | 
      59
     | 
    
      } elseif (!$admin->get_permission('pages_add_l0','system'))
     | 
  
  
    | 
      60
     | 
    
      {
     | 
  
  
    | 
      61
     | 
    
      	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
 
     | 
  
  
    | 
      62
     | 
    
      }	
 
     | 
  
  
    | 
      63
     | 
    
      
 
     | 
  
  
    | 
      64
     | 
    
      // check module permissions:
 
     | 
  
  
    | 
      65
     | 
    
      if (!$admin->get_permission($module, 'module'))
 
     | 
  
  
    | 
      66
     | 
    
      {
     | 
  
  
    | 
      67
     | 
    
      	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
 
     | 
  
  
    | 
      68
     | 
    
      }	
 
     | 
  
  
    | 
      69
     | 
    
      
 
     | 
  
  
    | 
      70
     | 
    
      // Validate data
 
     | 
  
  
    | 
      71
     | 
    
      if($title == '' || substr($title,0,1)=='.')
 
     | 
  
  
    | 
      72
     | 
    
      {
     | 
  
  
    | 
      73
     | 
    
      	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
 
     | 
  
  
    | 
      74
     | 
    
      }
 
     | 
  
  
    | 
      75
     | 
    
      
 
     | 
  
  
    | 
      76
     | 
    
      // Check to see if page created has needed permissions
 
     | 
  
  
    | 
      77
     | 
    
      if(!in_array(1, $admin->get_groups_id()))
 
     | 
  
  
    | 
      78
     | 
    
      {
     | 
  
  
    | 
      79
     | 
    
      	$admin_perm_ok = false;
 
     | 
  
  
    | 
      80
     | 
    
      	foreach ($admin_groups as $adm_group)
 
     | 
  
  
    | 
      81
     | 
    
          {
     | 
  
  
    | 
      82
     | 
    
      		if (in_array($adm_group, $admin->get_groups_id()))
 
     | 
  
  
    | 
      83
     | 
    
              {
     | 
  
  
    | 
      84
     | 
    
      			$admin_perm_ok = true;
 
     | 
  
  
    | 
      85
     | 
    
      		} 
 
     | 
  
  
    | 
      86
     | 
    
      	}
 
     | 
  
  
    | 
      87
     | 
    
      	if ($admin_perm_ok == false)
 
     | 
  
  
    | 
      88
     | 
    
          {
     | 
  
  
    | 
      89
     | 
    
      		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
 
     | 
  
  
    | 
      90
     | 
    
      	}
 
     | 
  
  
    | 
      91
     | 
    
      	$admin_perm_ok = false;
 
     | 
  
  
    | 
      92
     | 
    
      	foreach ($viewing_groups as $view_group)
 
     | 
  
  
    | 
      93
     | 
    
          {
     | 
  
  
    | 
      94
     | 
    
      		if (in_array($view_group, $admin->get_groups_id()))
 
     | 
  
  
    | 
      95
     | 
    
              {
     | 
  
  
    | 
      96
     | 
    
      			$admin_perm_ok = true;
 
     | 
  
  
    | 
      97
     | 
    
      		}
 
     | 
  
  
    | 
      98
     | 
    
      	}
 
     | 
  
  
    | 
      99
     | 
    
      	if ($admin_perm_ok == false)
 
     | 
  
  
    | 
      100
     | 
    
          {
     | 
  
  
    | 
      101
     | 
    
      		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
 
     | 
  
  
    | 
      102
     | 
    
      	}
 
     | 
  
  
    | 
      103
     | 
    
      }
 
     | 
  
  
    | 
      104
     | 
    
      
 
     | 
  
  
    | 
      105
     | 
    
      $admin_groups = implode(',', $admin_groups);
     | 
  
  
    | 
      106
     | 
    
      $viewing_groups = implode(',', $viewing_groups);
     | 
  
  
    | 
      107
     | 
    
      
 
     | 
  
  
    | 
      108
     | 
    
      // Work-out what the link and page filename should be
 
     | 
  
  
    | 
      109
     | 
    
      if($parent == '0')
 
     | 
  
  
    | 
      110
     | 
    
      {
     | 
  
  
    | 
      111
     | 
    
      	$link = '/'.page_filename($title);
 
     | 
  
  
    | 
      112
     | 
    
      	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
 
     | 
  
  
    | 
      113
     | 
    
      	if($link == '/index' || $link == '/intro')
 
     | 
  
  
    | 
      114
     | 
    
          {
     | 
  
  
    | 
      115
     | 
    
      		$link .= '_0';
 
     | 
  
  
    | 
      116
     | 
    
      		$filename = WB_PATH .PAGES_DIRECTORY .'/' .page_filename($title) .'_0' .PAGE_EXTENSION;
 
     | 
  
  
    | 
      117
     | 
    
      	} else {
     | 
  
  
    | 
      118
     | 
    
      		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION;
 
     | 
  
  
    | 
      119
     | 
    
      	}
 
     | 
  
  
    | 
      120
     | 
    
      } else {
     | 
  
  
    | 
      121
     | 
    
      	$parent_section = '';
 
     | 
  
  
    | 
      122
     | 
    
      	$parent_titles = array_reverse(get_parent_titles($parent));
 
     | 
  
  
    | 
      123
     | 
    
      	foreach($parent_titles AS $parent_title)
 
     | 
  
  
    | 
      124
     | 
    
          {
     | 
  
  
    | 
      125
     | 
    
      		$parent_section .= page_filename($parent_title).'/';
 
     | 
  
  
    | 
      126
     | 
    
      	}
 
     | 
  
  
    | 
      127
     | 
    
      	if($parent_section == '/') { $parent_section = ''; }
     | 
  
  
    | 
      128
     | 
    
      	$link = '/'.$parent_section.page_filename($title);
 
     | 
  
  
    | 
      129
     | 
    
      	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
 
     | 
  
  
    | 
      130
     | 
    
      	make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
 
     | 
  
  
    | 
      131
     | 
    
      }
 
     | 
  
  
    | 
      132
     | 
    
      
 
     | 
  
  
    | 
      133
     | 
    
      // Check if a page with same page filename exists
 
     | 
  
  
    | 
      134
     | 
    
      $get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
     | 
  
  
    | 
      135
     | 
    
      if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
 
     | 
  
  
    | 
      136
     | 
    
      {
     | 
  
  
    | 
      137
     | 
    
      	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
 
     | 
  
  
    | 
      138
     | 
    
      }
 
     | 
  
  
    | 
      139
     | 
    
      
 
     | 
  
  
    | 
      140
     | 
    
      // Include the ordering class
 
     | 
  
  
    | 
      141
     | 
    
      require(WB_PATH.'/framework/class.order.php');
 
     | 
  
  
    | 
      142
     | 
    
      $order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
 
     | 
  
  
    | 
      143
     | 
    
      // First clean order
 
     | 
  
  
    | 
      144
     | 
    
      $order->clean($parent);
 
     | 
  
  
    | 
      145
     | 
    
      // Get new order
 
     | 
  
  
    | 
      146
     | 
    
      $position = $order->get_new($parent);
 
     | 
  
  
    | 
      147
     | 
    
      
 
     | 
  
  
    | 
      148
     | 
    
      // Work-out if the page parent (if selected) has a seperate template or language to the default
 
     | 
  
  
    | 
      149
     | 
    
      $query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
     | 
  
  
    | 
      150
     | 
    
      if($query_parent->numRows() > 0)
 
     | 
  
  
    | 
      151
     | 
    
      {
     | 
  
  
    | 
      152
     | 
    
      	$fetch_parent = $query_parent->fetchRow();
 
     | 
  
  
    | 
      153
     | 
    
      	$template = $fetch_parent['template'];
 
     | 
  
  
    | 
      154
     | 
    
      	$language = $fetch_parent['language'];
 
     | 
  
  
    | 
      155
     | 
    
      } else {
     | 
  
  
    | 
      156
     | 
    
      	$template = '';
 
     | 
  
  
    | 
      157
     | 
    
      	$language = DEFAULT_LANGUAGE;
 
     | 
  
  
    | 
      158
     | 
    
      }
 
     | 
  
  
    | 
      159
     | 
    
      
 
     | 
  
  
    | 
      160
     | 
    
      // Insert page into pages table
 
     | 
  
  
    | 
      161
     | 
    
      $sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` SET ';
 
     | 
  
  
    | 
      162
     | 
    
      $sql .= '`parent` = '.$parent.', ';
 
     | 
  
  
    | 
      163
     | 
    
      $sql .= '`target` = "_top", ';
 
     | 
  
  
    | 
      164
     | 
    
      $sql .= '`page_title` = "'.$title.'", ';
 
     | 
  
  
    | 
      165
     | 
    
      $sql .= '`menu_title` = "'.$title.'", ';
 
     | 
  
  
    | 
      166
     | 
    
      $sql .= '`template` = "'.$template.'", ';
 
     | 
  
  
    | 
      167
     | 
    
      $sql .= '`visibility` = "'.$visibility.'", ';
 
     | 
  
  
    | 
      168
     | 
    
      $sql .= '`position` = '.$position.', ';
 
     | 
  
  
    | 
      169
     | 
    
      $sql .= '`menu` = 1, ';
 
     | 
  
  
    | 
      170
     | 
    
      $sql .= '`language` = "'.$language.'", ';
 
     | 
  
  
    | 
      171
     | 
    
      $sql .= '`searching` = 1, ';
 
     | 
  
  
    | 
      172
     | 
    
      $sql .= '`modified_when` = '.time().', ';
 
     | 
  
  
    | 
      173
     | 
    
      $sql .= '`modified_by` = '.$admin->get_user_id().', ';
 
     | 
  
  
    | 
      174
     | 
    
      $sql .= '`admin_groups` = "'.$admin_groups.'", ';
 
     | 
  
  
    | 
      175
     | 
    
      $sql .= '`viewing_groups` = "'.$viewing_groups.'"';
 
     | 
  
  
    | 
      176
     | 
    
      
 
     | 
  
  
    | 
      177
     | 
    
      $database->query($sql);
 
     | 
  
  
    | 
      178
     | 
    
      /*
 
     | 
  
  
    | 
      179
     | 
    
      $query = "INSERT INTO ".TABLE_PREFIX."pages
 
     | 
  
  
    | 
      180
     | 
    
      (page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES
 
     | 
  
  
    | 
      181
     | 
    
      ('$title','$title','$parent','$template','_top','$position','$visibility','1','1','$language','$admin_groups','$viewing_groups','".time()."','".$admin->get_user_id()."')";
     | 
  
  
    | 
      182
     | 
    
      $database->query($query);
 
     | 
  
  
    | 
      183
     | 
    
      */
 
     | 
  
  
    | 
      184
     | 
    
      if($database->is_error())
 
     | 
  
  
    | 
      185
     | 
    
      {
     | 
  
  
    | 
      186
     | 
    
      	$admin->print_error($database->get_error());
 
     | 
  
  
    | 
      187
     | 
    
      }
 
     | 
  
  
    | 
      188
     | 
    
      
 
     | 
  
  
    | 
      189
     | 
    
      // Get the page id
 
     | 
  
  
    | 
      190
     | 
    
      $page_id = $database->get_one("SELECT LAST_INSERT_ID()");
     | 
  
  
    | 
      191
     | 
    
      
 
     | 
  
  
    | 
      192
     | 
    
      // Work out level
 
     | 
  
  
    | 
      193
     | 
    
      $level = level_count($page_id);
 
     | 
  
  
    | 
      194
     | 
    
      // Work out root parent
 
     | 
  
  
    | 
      195
     | 
    
      $root_parent = root_parent($page_id);
 
     | 
  
  
    | 
      196
     | 
    
      // Work out page trail
 
     | 
  
  
    | 
      197
     | 
    
      $page_trail = get_page_trail($page_id);
 
     | 
  
  
    | 
      198
     | 
    
      
 
     | 
  
  
    | 
      199
     | 
    
      // Update page with new level and link
 
     | 
  
  
    | 
      200
     | 
    
      $sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
 
     | 
  
  
    | 
      201
     | 
    
      $sql .= '`root_parent` = '.$root_parent.', ';
 
     | 
  
  
    | 
      202
     | 
    
      $sql .= '`level` = '.$level.', ';
 
     | 
  
  
    | 
      203
     | 
    
      $sql .= '`link` = "'.$link.'", ';
 
     | 
  
  
    | 
      204
     | 
    
      $sql .= '`page_trail` = "'.$page_trail.'"';
 
     | 
  
  
    | 
      205
     | 
    
      $sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES)
     | 
  
  
    | 
      206
     | 
    
               && $field_set
 
     | 
  
  
    | 
      207
     | 
    
               && ($language == DEFAULT_LANGUAGE)
 
     | 
  
  
    | 
      208
     | 
    
               && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')
 
     | 
  
  
    | 
      209
     | 
    
               )
 
     | 
  
  
    | 
      210
     | 
    
               ? ', `page_code` = '.(int)$page_id.' ' : ' ';
 
     | 
  
  
    | 
      211
     | 
    
      $sql .= 'WHERE `page_id` = '.$page_id;
 
     | 
  
  
    | 
      212
     | 
    
      $database->query($sql);
 
     | 
  
  
    | 
      213
     | 
    
      /*
 
     | 
  
  
    | 
      214
     | 
    
      $database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
     | 
  
  
    | 
      215
     | 
    
      */
 
     | 
  
  
    | 
      216
     | 
    
      if($database->is_error())
 
     | 
  
  
    | 
      217
     | 
    
      {
     | 
  
  
    | 
      218
     | 
    
      	$admin->print_error($database->get_error());
 
     | 
  
  
    | 
      219
     | 
    
      }
 
     | 
  
  
    | 
      220
     | 
    
      // Create a new file in the /pages dir
 
     | 
  
  
    | 
      221
     | 
    
      create_access_file($filename, $page_id, $level);
 
     | 
  
  
    | 
      222
     | 
    
      
 
     | 
  
  
    | 
      223
     | 
    
      // add position 1 to new page
 
     | 
  
  
    | 
      224
     | 
    
      $position = 1;
 
     | 
  
  
    | 
      225
     | 
    
      
 
     | 
  
  
    | 
      226
     | 
    
      // Add new record into the sections table
 
     | 
  
  
    | 
      227
     | 
    
      $database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
     | 
  
  
    | 
      228
     | 
    
      
 
     | 
  
  
    | 
      229
     | 
    
      // Get the section id
 
     | 
  
  
    | 
      230
     | 
    
      $section_id = $database->get_one("SELECT LAST_INSERT_ID()");
     | 
  
  
    | 
      231
     | 
    
      
 
     | 
  
  
    | 
      232
     | 
    
      // Include the selected modules add file if it exists
 
     | 
  
  
    | 
      233
     | 
    
      if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
     | 
  
  
    | 
      234
     | 
    
      	require(WB_PATH.'/modules/'.$module.'/add.php');
 
     | 
  
  
    | 
      235
     | 
    
      }
 
     | 
  
  
    | 
      236
     | 
    
      
 
     | 
  
  
    | 
      237
     | 
    
      // Check if there is a db error, otherwise say successful
 
     | 
  
  
    | 
      238
     | 
    
      if($database->is_error()) {
     | 
  
  
    | 
      239
     | 
    
      	$admin->print_error($database->get_error());
 
     | 
  
  
    | 
      240
     | 
    
      } else {
     | 
  
  
    | 
      241
     | 
    
      	$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
 
     | 
  
  
    | 
      242
     | 
    
      }
 
     | 
  
  
    | 
      243
     | 
    
      
 
     | 
  
  
    | 
      244
     | 
    
      // Print admin footer
 
     | 
  
  
    | 
      245
     | 
    
      $admin->print_footer();
 
     | 
  
  
    | 
      246
     | 
    
      
 
     | 
  
  
    | 
      247
     | 
    
      ?>
 
     |