Ejemplo n.º 1
0
 /**
  * Shows the jumper.  This jumper works for pages that process a get request.  The page must put the all results in
  * the node with id "{$id_base}_results".   The jumper is placed in the node with id "{$id_base}_pager_display".  It
  * is expected that the node with id "{$id_base}_pager_display" is a sub-node of the node with id "{$id_base}_results".
  * Note:  there will be several nodes created with id's of the form "{$id_base}_pager_$something" so with the exception
  * of $something='display' you should not use id's of this form.  
  *
  * This fuzzy method can be called either from an I2CE_Page or an I2CE_Template.
  *
  * @param string $id_base the base id that should be used in identifying the node to update (e.g. 'report')
  * @param array $jumps array of int, the pages we want in the jumper.  Does not inclu
  * @param int $page the current page number
  * @param int $total_pages  the total numnber pf pages
  * @param string $pageURL the url of the page we will make the request from
  * @param associatibe array $query_fields  keys are the query variables needed for the get request.  values are the _unencoded_ values that
  * the variable should have.  
  * @param string $pageVaraiable the get variable to store the requested page number in.  Defaults to 'page'
  */
 public function _makeJumper($template, $id_base, $jumps, $page, $total_pages, $pageURL, $query_fields, $pageVariable = 'page')
 {
     if ($template instanceof I2CE_Page) {
         $template = $template->getTemplate();
     }
     $template->addHeaderLink("jumper.css");
     if (!is_array($query_fields)) {
         I2CE::raiseError("Display jumper expects {$query_fields} to be an array.  Got: " . print_r($query_fields, true));
     }
     $qry_string = '';
     $query_fields = I2CE_Page::flattenRequestVars($query_fields);
     foreach ($query_fields as $name => $value) {
         $qry_string .= $name . '=' . urlencode($value) . '&';
     }
     if (strpos($pageURL, '?') !== false) {
         if ($qry_string) {
             $page_root = $pageURL . '&' . $qry_string . $pageVariable . '=';
         } else {
             $page_root = $pageURL . '&' . $pageVariable . '=';
         }
     } else {
         if ($qry_string) {
             $page_root = $pageURL . '?' . $qry_string . $pageVariable . '=';
         } else {
             $page_root = $pageURL . '?' . $pageVariable . '=';
         }
     }
     if (!in_array(1, $jumps)) {
         $rewind_node = $template->appendElementById("{$id_base}_pager_display", "a", array("href" => $page_root . '1', 'id' => "{$id_base}_pager_rewind_page"));
         $template->appendElementByNode($rewind_node, "img", array("src" => 'file/rewind.gif', "height" => 7, "width" => 9, "border" => 0));
         $prev_node = $template->appendElementById("{$id_base}_pager_display", "a", array("href" => $page_root . ($page - 1), 'id' => "{$id_base}_pager_prev_page"));
         $template->appendElementByNode($prev_node, "img", array("src" => 'file/prev.gif', "height" => 7, "width" => 6, "border" => 0));
         if ($template->hasAjax()) {
             $template->addAjaxUpdate("{$id_base}_results", "{$id_base}_pager_rewind_page", 'click', $page_root . '1', "{$id_base}_results", true);
             $template->addAjaxUpdate("{$id_base}_results", "{$id_base}_pager_prev_page", 'click', $page_root . ($page - 1), "{$id_base}_results", true);
         }
     }
     foreach ($jumps as $jump) {
         if ($jump < 1 || $jump > $total_pages) {
             continue;
         }
         if ($jump == $page) {
             $template->appendElementById("{$id_base}_pager_display", "span", array("class" => "pager_current"), $jump);
         } else {
             $template->appendElementById("{$id_base}_pager_display", "a", array("href" => $page_root . $jump, 'id' => "{$id_base}_pager_" . $jump . "_page"), $jump);
             if ($template->hasAjax()) {
                 $template->addAjaxUpdate("{$id_base}_results", "{$id_base}_pager_" . $jump . "_page", 'click', $page_root . $jump, "{$id_base}_results", true);
             }
         }
     }
     if (!in_array($total_pages, $jumps)) {
         $next_node = $template->appendElementById("{$id_base}_pager_display", "a", array("href" => $page_root . ($page + 1), "id" => "{$id_base}_pager_next_page"));
         $template->appendElementByNode($next_node, "img", array("src" => 'file/next.gif', "height" => 7, "width" => 6, "border" => 0));
         $ff_node = $template->appendElementById("{$id_base}_pager_display", "a", array("href" => $page_root . $total_pages, "id" => "{$id_base}_pager_fast_forward_page"));
         $template->appendElementByNode($ff_node, "img", array("src" => 'file/fastforward.gif', "height" => 7, "width" => 9, "border" => 0));
         if ($template->hasAjax()) {
             $template->addAjaxUpdate("{$id_base}_results", "{$id_base}_pager_fast_forward_page", 'click', $page_root . $total_pages, "{$id_base}_results", true);
             $template->addAjaxUpdate("{$id_base}_results", "{$id_base}_pager_next_page", 'click', $page_root . ($page + 1), "{$id_base}_results", true);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     $task = $this->getViewChildTask();
     if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) {
         $this->userMessage("You do not have permission to view this {$childForm}", true);
         return false;
     }
     $tag = array_key_exists('template_tag', $this->args) && is_scalar($this->args['template_tag']) ? $this->args['template_tag'] : 'div';
     $append_id = array_key_exists('template_id', $this->args) && is_scalar($this->args['template_id']) ? $this->args['template_id'] : 'child_form';
     $appendNode = $this->template->getElementById($append_id);
     if (!$appendNode instanceof DOMNode) {
         I2CE::raiseError("No {$append_id} to add child form " . $this->childForm);
         return false;
     }
     $limit_page = $this->request_exists('limit_page') ? $this->request('limit_page') : 1;
     if ($limit_page < 1) {
         $limit_page = 1;
     }
     $order_by = $this->getOrderBy();
     $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1));
     if (!$found && $limit_page > 1) {
         $limit_page = 1;
         $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1));
     }
     if (!$found) {
         $this->redirect("view?id=" . $this->parent->getNameId());
         return true;
     }
     $total_rows = I2CE_FormStorage::getLastListCount($this->childForm);
     if ($total_rows <= 1) {
         $this->template->setAttribute('style', 'display:none;', 'child_pager_div');
     } else {
         $query = $this->request();
         unset($query['limit_page']);
         $query = I2CE_Page::flattenRequestVars($query);
         $this->makeScalingJumper('child', $limit_page, $total_rows, $this->pageRoot(), $query, 'limit_page');
     }
     $this->child = I2CE_FormFactory::instance()->createContainer($this->childForm . "|" . $found);
     $this->child->populate();
     I2CE_ModuleFactory::callHooks('pre_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'set_on_node' => null, 'append_node' => $appendNode));
     $childNode = $this->template->appendFileByNode($this->getViewChildTemplate(), $tag, $appendNode);
     $this->template->setForm($this->child, $childNode);
     I2CE_ModuleFactory::callHooks('post_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'node' => $childNode, 'set_on_node' => null, 'append_node' => $appendNode));
     $this->template->setDisplayDataImmediate("child_form_header", "View " . $this->child->getDisplayName());
     if (array_key_exists('show_edit', $this->args) ? !$this->args['show_edit'] : true) {
         $this->template->findAndRemoveNodes("//div[@class='editRecord']");
     }
     // Do we want this?
     // $this->template->findAndRemoveNodes( "//span[@history='false']" );
     return true;
 }
 /**
  *Get the query fields for the jumper
  * @returns array
  */
 protected function getJumperQryFields()
 {
     $qry_fields = $this->page->request();
     foreach (array('limit_page') as $key) {
         unset($qry_fields[$key]);
     }
     $qry_fields = I2CE_Page::flattenRequestVars($qry_fields);
     return $qry_fields;
 }