Пример #1
0
Файл: edit.php Проект: rair/yacs
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // maybe posts are not allowed here
} elseif (!isset($item['id']) && $anchor->has_option('locked') && !Surfer::is_empowered()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('This page has been locked.'));
    // an error occured
} elseif (count($context['error'])) {
    $item = $_REQUEST;
    $with_form = TRUE;
    // process uploaded data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // the follow-up page
    $next = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
    // display the form on error
    if (!($_REQUEST['id'] = Tables::post($_REQUEST))) {
        $item = $_REQUEST;
        $with_form = TRUE;
        // post-processing
    } else {
        // a new post
        if (!$item['id']) {
            // touch the related anchor
            $anchor->touch('table:create', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y');
            // clear cache
            Tables::clear($_REQUEST);
            // increment the post counter of the surfer
            Users::increment_posts(Surfer::get_id());
            // an update
        } else {
            // touch the related anchor
Пример #2
0
 /**
  * duplicate all tables for a given anchor
  *
  * This function duplicates records in the database, and changes anchors
  * to attach new records as per second parameter.
  *
  * @param string the source anchor
  * @param string the target anchor
  * @return int the number of duplicated records
  *
  * @see shared/anchors.php
  */
 public static function duplicate_for_anchor($anchor_from, $anchor_to)
 {
     global $context;
     // look for records attached to this anchor
     $count = 0;
     $query = "SELECT * FROM " . SQL::table_name('tables') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // the list of transcoded strings
         $transcoded = array();
         // process all matching records one at a time
         while ($item = SQL::fetch($result)) {
             // a new id will be allocated
             $old_id = $item['id'];
             unset($item['id']);
             // target anchor
             $item['anchor'] = $anchor_to;
             // actual duplication
             if ($item['id'] = Tables::post($item)) {
                 // more pairs of strings to transcode
                 $transcoded[] = array('/\\[table=' . preg_quote($old_id, '/') . '/i', '[table=' . $item['id']);
                 $transcoded[] = array('/\\[table.bars=' . preg_quote($old_id, '/') . '/i', '[table.bars=' . $item['id']);
                 $transcoded[] = array('/\\[table.chart=' . preg_quote($old_id, '/') . '/i', '[table.chart=' . $item['id']);
                 $transcoded[] = array('/\\[table.filter=' . preg_quote($old_id, '/') . '/i', '[table.filter=' . $item['id']);
                 $transcoded[] = array('/\\[table.line=' . preg_quote($old_id, '/') . '/i', '[table.line=' . $item['id']);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('table:' . $old_id, 'table:' . $item['id']);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
         // clear the cache for tables
         Cache::clear(array('tables', 'table:'));
     }
     // number of duplicated records
     return $count;
 }
Пример #3
0
     }
 }
 // tables
 //
 $text .= Skin::build_block(i18n::s('Tables'), 'subtitle');
 // 'my_articles' article
 if (Tables::get('my_articles')) {
     $text .= i18n::s('A sample "my_articles" table already exists.') . BR . "\n";
 } elseif ($anchor = Articles::lookup('my_article')) {
     $fields = array();
     $fields['anchor'] = $anchor;
     $fields['nick_name'] = 'my_articles';
     $fields['title'] = i18n::c('My Articles');
     $fields['description'] = i18n::c('This is a sample table to let you learn and practice.');
     $fields['query'] = "SELECT \n" . "articles.title as titre, \n" . "articles.id as 'id', \n" . "articles.introduction as introduction, \n" . "articles.edit_name as 'last editor', \n" . "articles.edit_date as 'Date' \n" . "FROM " . SQL::table_name('articles') . " AS articles \n" . "WHERE (articles.active='Y') \n" . "ORDER BY articles.rank, articles.edit_date DESC, articles.title LIMIT 0,10";
     if (Tables::post($fields)) {
         $text .= sprintf(i18n::s('A table "%s" has been created.'), $fields['nick_name']) . BR . "\n";
     } else {
         $text .= Logger::error_pop() . BR . "\n";
     }
 }
 // job done
 $context['text'] .= $text;
 // follow-up commands
 $menu = array();
 $menu = array_merge($menu, array('sections/' => i18n::s('Check the updated Site Map')));
 $menu = array_merge($menu, array('help/populate.php' => i18n::s('Launch the Content Assistant again')));
 $menu = array_merge($menu, array('control/' => i18n::s('Control Panel')));
 $context['text'] .= Skin::build_box(i18n::s('What do you want to do now?'), Skin::build_list($menu, 'menu_bar'), 'page_bottom');
 // flush the cache
 Cache::clear();