/**
  * Clean up and validate the input data
  *
  * @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_validation(Doku_Event $event, $param)
 {
     global $ID, $INPUT;
     $act = act_clean($event->data);
     if (!in_array($act, array('save', 'preview'))) {
         return false;
     }
     $this->tosave = array();
     // run the validation for each assignded schema
     $valid = AccessDataValidator::validateDataForPage($INPUT->arr(self::$VAR), $ID, $errors);
     if ($valid === false) {
         $this->validated = false;
         foreach ($errors as $error) {
             msg(hsc($error), -1);
         }
     } else {
         $this->validated = true;
         $this->tosave = $valid;
     }
     // FIXME we used to set the cleaned data as new input data. this caused #140
     // could we just not do that, and keep the cleaning to saving only? and fix that bug this way?
     // did validation go through? otherwise abort saving
     if (!$this->validated && $act == 'save') {
         $event->data = 'edit';
     }
     return true;
 }
 /**
  * Saves data for a given page (creates a new revision)
  *
  * If this call succeeds you can assume your data has either been saved or it was
  * not necessary to save it because the data already existed in the wanted form or
  * the given schemas are no longer assigned to that page.
  *
  * Important: You have to check write permissions for the given page before calling
  * this function yourself!
  *
  * this duplicates a bit of code from entry.php - we could also fake post data and let
  * entry handle it, but that would be rather unclean and might be problematic when multiple
  * calls are done within the same request.
  *
  * @todo should this try to lock the page?
  *
  *
  * @param string $page
  * @param array $data ('schema' => ( 'fieldlabel' => 'value', ...))
  * @param string $summary
  * @throws StructException
  */
 public function saveData($page, $data, $summary = '')
 {
     $page = cleanID($page);
     $summary = trim($summary);
     if (!$summary) {
         $summary = $this->getLang('summary');
     }
     if (!page_exists($page)) {
         throw new StructException("Page does not exist. You can not attach struct data");
     }
     // validate and see if anything changes
     $valid = AccessDataValidator::validateDataForPage($data, $page, $errors);
     if ($valid === false) {
         throw new StructException("Validation failed:\n%s", join("\n", $errors));
     }
     if (!$valid) {
         return;
     }
     // empty array when no changes were detected
     $newrevision = self::createPageRevision($page, $summary);
     // save the provided data
     $assignments = new Assignments();
     foreach ($valid as $v) {
         $v->saveData($newrevision);
         // make sure this schema is assigned
         $assignments->assignPageSchema($page, $v->getAccessTable()->getSchema()->getTable());
     }
 }