/**
  * Renames all occurances of a page ID in the database
  *
  * @param Doku_Event $event event object by reference
  * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return bool
  */
 public function handle_move(Doku_Event $event, $param)
 {
     /** @var helper_plugin_struct_db $hlp */
     $hlp = plugin_load('helper', 'struct_db');
     $db = $hlp->getDB();
     if (!$db) {
         return false;
     }
     $old = $event->data['src_id'];
     $new = $event->data['dst_id'];
     // ALL data tables (we don't trust the assigments are still there)
     foreach (Schema::getAll() as $tbl) {
         $sql = "UPDATE data_{$tbl} SET pid = ? WHERE pid = ?";
         $db->query($sql, array($new, $old));
         $sql = "UPDATE multi_{$tbl} SET pid = ? WHERE pid = ?";
         $db->query($sql, array($new, $old));
     }
     // assignments
     $sql = "UPDATE schema_assignments SET pid = ? WHERE pid = ?";
     $db->query($sql, array($new, $old));
     // make sure assignments still match patterns;
     $assignments = new Assignments();
     $assignments->reevaluatePageAssignments($new);
     return true;
 }
 /**
  * Adds all available schemas to the Table of Contents
  *
  * @return array
  */
 public function getTOC()
 {
     global $ID;
     $toc = array();
     $link = wl($ID, array('do' => 'admin', 'page' => 'struct_assignments'));
     $toc[] = html_mktocitem($link, $this->getLang('menu_assignments'), 0, '');
     $slink = wl($ID, array('do' => 'admin', 'page' => 'struct_schemas'));
     $toc[] = html_mktocitem($slink, $this->getLang('menu'), 0, '');
     $tables = Schema::getAll('page');
     if ($tables) {
         $toc[] = html_mktocitem($slink, $this->getLang('page schema'), 1, '');
         foreach ($tables as $table) {
             $link = wl($ID, array('do' => 'admin', 'page' => 'struct_schemas', 'table' => $table));
             $toc[] = html_mktocitem($link, hsc($table), 2, '');
         }
     }
     $tables = Schema::getAll('lookup');
     if ($tables) {
         $toc[] = html_mktocitem($slink, $this->getLang('lookup schema'), 1, '');
         foreach ($tables as $table) {
             $link = wl($ID, array('do' => 'admin', 'page' => 'struct_schemas', 'table' => $table));
             $toc[] = html_mktocitem($link, hsc($table), 2, '');
         }
     }
     return $toc;
 }
 /**
  * Get info about existing schemas
  *
  * @param string|null $schema the schema to query, null for all
  * @return Schema[]
  * @throws StructException
  */
 public function getSchema($schema = null)
 {
     if (is_null($schema)) {
         $schemas = Schema::getAll();
     } else {
         $schemas = array($schema);
     }
     $result = array();
     foreach ($schemas as $table) {
         $result[$table] = new Schema($table);
     }
     return $result;
 }
 /**
  * Render HTML output, e.g. helpful text and a form
  */
 public function html()
 {
     global $ID;
     echo $this->locale_xhtml('assignments_intro');
     $ass = new Assignments();
     $assignments = $ass->getAllPatterns();
     echo '<form action="' . wl($ID) . '" action="post">';
     echo '<input type="hidden" name="do" value="admin" />';
     echo '<input type="hidden" name="page" value="struct_assignments" />';
     echo '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
     echo '<table class="inline">';
     // header
     echo '<tr>';
     echo '<th>' . $this->getLang('assign_assign') . '</th>';
     echo '<th>' . $this->getLang('assign_tbl') . '</th>';
     echo '<th></th>';
     echo '</tr>';
     // existing assignments
     foreach ($assignments as $assignment) {
         $schema = $assignment['tbl'];
         $assignee = $assignment['pattern'];
         $link = wl($ID, array('do' => 'admin', 'page' => 'struct_assignments', 'action' => 'delete', 'sectok' => getSecurityToken(), 'assignment[tbl]' => $schema, 'assignment[assign]' => $assignee));
         echo '<tr>';
         echo '<td>' . hsc($assignee) . '</td>';
         echo '<td>' . hsc($schema) . '</td>';
         echo '<td><a class="deleteSchema" href="' . $link . '">' . $this->getLang('assign_del') . '</a></td>';
         echo '</tr>';
     }
     // new assignment form
     echo '<tr>';
     echo '<td><input type="text" name="assignment[assign]" /></td>';
     echo '<td>';
     echo '<select name="assignment[tbl]">';
     foreach (Schema::getAll('page') as $table) {
         echo '<option value="' . hsc($table) . '">' . hsc($table) . '</option>';
     }
     echo '</select>';
     echo '</td>';
     echo '<td><button type="submit" name="action" value="add">' . $this->getLang('assign_add') . '</button></td>';
     echo '</tr>';
     echo '</table>';
 }
 /**
  * this possibly duplicates @see helper_plugin_struct::getSchema()
  */
 public function getAllSchemasList()
 {
     return Schema::getAll();
 }