Example #1
0
 /**
  * edit tour step
  * 
  * @param String $tour_id    tour id
  * @param String $step_nr    number of step
  * @param String $mode       indicates edit mode (new, edit or save*)
  */
 function edit_step_action($tour_id, $step_nr, $mode = 'edit')
 {
     if (!$this->help_admin) {
         return $this->render_nothing();
     }
     // Output as dialog (Ajax-Request) or as Stud.IP page?
     if ($this->via_ajax) {
         header('X-Title: ' . _('Schritt bearbeiten'));
     }
     // save step position
     if ($mode == 'save_position') {
         $temp_step = new HelpTourStep(array($tour_id, $step_nr));
         $temp_step->css_selector = trim(Request::get('position'));
         if ($temp_step->validate() and !$temp_step->isNew()) {
             $temp_step->store();
         }
         return $this->render_nothing();
     }
     // save step action (next)
     if ($mode == 'save_action_next') {
         $temp_step = new HelpTourStep(array($tour_id, $step_nr));
         $temp_step->action_next = trim(Request::get('position'));
         if ($temp_step->validate() and !$temp_step->isNew()) {
             $temp_step->store();
         }
         return $this->render_nothing();
     }
     // save step action (prev)
     if ($mode == 'save_action_prev') {
         $temp_step = new HelpTourStep(array($tour_id, $step_nr));
         $temp_step->action_prev = trim(Request::get('position'));
         if ($temp_step->validate() and !$temp_step->isNew()) {
             $temp_step->store();
         }
         return $this->render_nothing();
     }
     // save step
     if ($mode == 'save') {
         CSRFProtection::verifySecurityToken();
         if (Request::option('tour_step_editmode') == 'new') {
             $this->tour = new HelpTour($tour_id);
             if ($tour_id and $this->tour->isNew()) {
                 throw new AccessDeniedException(_('Die Tour mit der angegebenen ID existiert nicht.'));
             }
             $step_data = array('title' => trim(Request::get('step_title')), 'tip' => trim(Request::get('step_tip')), 'interactive' => trim(Request::get('step_interactive')), 'route' => trim(Request::get('step_route')), 'css_selector' => trim(Request::get('step_css')), 'action_prev' => trim(Request::get('action_prev')), 'action_next' => trim(Request::get('action_next')), 'orientation' => trim(Request::get('step_orientation')), 'mkdate' => time(), 'author_email' => $GLOBALS['user']->Email);
             if ($this->tour->addStep($step_data, $step_nr)) {
                 header('X-Dialog-Close: 1');
             } else {
                 $mode = 'new';
             }
         } else {
             $temp_step = new HelpTourStep(array($tour_id, $step_nr));
             $temp_step->title = trim(Request::get('step_title'));
             $temp_step->tip = trim(Request::get('step_tip'));
             $temp_step->interactive = trim(Request::get('step_interactive'));
             $temp_step->route = trim(Request::get('step_route'));
             $temp_step->css_selector = trim(Request::get('step_css'));
             $temp_step->action_next = trim(Request::get('action_next'));
             $temp_step->action_prev = trim(Request::get('action_prev'));
             $temp_step->orientation = Request::option('step_orientation');
             $temp_step->author_email = $GLOBALS['user']->Email;
             if ($temp_step->validate()) {
                 $temp_step->store();
                 header('X-Dialog-Close: 1');
             } else {
                 $mode = 'edit';
             }
         }
     }
     // prepare edit dialog
     $this->tour_id = $tour_id;
     if ($mode == 'new') {
         $this->step = new HelpTourStep();
         $this->step->step = $step_nr;
         $temp_step = new HelpTourStep(array($tour_id, $step_nr - 1));
         if (!$temp_step->isNew()) {
             $this->step->route = $temp_step->route;
         }
     } else {
         $this->step = new HelpTourStep(array($tour_id, $step_nr));
     }
     if (Request::option('hide_route')) {
         $this->force_route = $this->step->route;
     }
     $this->mode = $mode;
 }
Example #2
0
 /**
  * adds step to the tour and rearranges existing steps
  */
 function addStep($data, $position = 0)
 {
     $step = new HelpTourStep();
     $step->setData($data, true);
     if ($position) {
         $step->step = $position;
     } else {
         $step->step = count($this->steps) + 1;
     }
     $step->tour_id = $this->tour_id;
     if ($step->validate()) {
         if ($position and $position <= count($this->steps)) {
             $query = "UPDATE help_tour_steps \n                          SET step = step+1 \n                          WHERE tour_id = ? AND step >= ? \n                          ORDER BY step DESC";
             $statement = DBManager::get()->prepare($query);
             $statement->execute(array($this->tour_id, $position));
         }
         $step->store();
         $this->restore();
         return true;
     }
     return false;
 }