/**
  * Perform any actions for the page
  * 
  * @returns boolean.  true on sucess
  */
 public function action()
 {
     parent::action();
     if (count($this->request_remainder) != 1) {
         $this->userMessage("Cannot view archived report");
         $this->setRedirect("CustomReports/view/reportViews");
         return false;
     }
     reset($this->request_remainder);
     $this->reportView = (string) current($this->request_remainder);
     if (isset($config->reportViews->{$this}->reportView->limit_view_to) && $config->reportViews->{$this}->reportView->limit_view_to) {
         if (!$this->hasPermission(' task(custom_reports_admin) or ' . $config->reportViews->{$this}->reportView->limit_view_to)) {
             $this->userMessage("You do not have permission to view this report");
             $this->setRedirect("CustomReports/view/reportViews");
             return false;
         }
     }
     if ($this->request_exists('id')) {
         $id = $this->request('id');
         $link = I2CE_FormField_BINARY_FILE::getFieldLink($id, 'report');
         $this->redirect($link);
         return true;
     } else {
         $node = $this->template->addFile("archiveReports_menu.html");
         if (!$node instanceof DOMNode) {
             return false;
         }
         $dn = $this->reportView;
         I2CE::getConfig()->setIfIsSet($dn, "/modules/CustomReports/reportViews/{$this->reportView}/display_name");
         $this->template->setDisplayDataImmediate('reportView_name', $dn, $node);
         $where = array('operator' => 'FIELD_LIMIT', 'field' => 'report_view', 'style' => 'equals', 'data' => array('value' => $this->reportView));
         $list = I2CE_FormStorage::listDisplayFields('archived_report', I2CE_List::getDisplayFields('archived_report'), false, $where, I2CE_List::getSortFields('archived_report'));
         $disp_string = I2CE_List::getDisplayString('archived_report');
         foreach ($list as &$val) {
             $val = vsprintf($disp_string, $val);
         }
         return $this->paginateList($list);
     }
 }
 /**
  * Sets the value of this field from the database format.
  * @param mixed $value
  */
 public function setFromDB($value)
 {
     parent::setFromDB($value);
     if (is_resource($this->image_rsrc)) {
         imagedestroy($this->image_rsrc);
         $this->createImageResource();
     }
 }
 /**
  * Perform menu action 
  * 
  * @param array $ids of string
  * @returns boolean.  true on success
  */
 protected function action_menu($ids)
 {
     reset($ids);
     list($form, $junk) = explode('|', current($ids), 2);
     $form = trim($form);
     $valid = I2CE_Module_PrintedForms::getValidPrintedForms($form);
     $mf = I2CE_ModuleFactory::instance();
     if (count($valid) == 0 || !$this->hasPermission("task(printed_forms_all_generate)")) {
         $this->template->setDisplayDataImmediate('has_valid_forms', 0);
     } else {
         $archive = $mf->isEnabled('BinField') && $this->hasPermission("task(printed_forms_create_all_archives)");
         $this->template->setDisplayDataImmediate('has_valid_forms', 1);
         $append_node = $this->template->getElementById('printed_forms_list');
         if (!$append_node instanceof DOMNode) {
             I2CE::raiseError("Could no find printed_forms_list");
             return false;
         }
         $add_node = $this->template->loadFile('printed_forms_menu_each.html', 'li');
         if (!$add_node instanceof DOMElement) {
             I2CE::raiseError("Bad 'printed_forms_menu_each.html'");
             return true;
         } else {
             foreach ($valid as $pf => $data) {
                 $node = $add_node->cloneNode(true);
                 $this->template->appendNode($node, $append_node);
                 $link = "PrintedForms/print/{$pf}?" . http_build_query(array('ids' => $ids));
                 $archive_form = false;
                 if ($archive && $data['archive']) {
                     $archive_link = "PrintedForms/archive/{$pf}?" . http_build_query(array('ids' => $ids));
                 } else {
                     $archive_link = '';
                 }
                 $this->template->setDisplayDataImmediate('standard_form_display_name', $data['displayName'], $node);
                 $this->template->setDisplayDataImmediate('standard_form_link', $link, $node);
                 $this->template->setDisplayDataImmediate('standard_form_archive_link', $archive_link, $node);
             }
         }
     }
     $archive = $mf->isEnabled('BinField') && $this->hasPermission("task(printed_forms_view_all_archives)");
     if (count($ids) != 1 || !$archive || !$this->hasPermission("task(printed_forms_view_all_archives)")) {
         $this->template->setDisplayDataImmediate('show_archive', 0);
         return true;
     }
     $this->template->setDisplayDataImmediate('show_archive', 1);
     $archives = I2CE_Module_PrintedForms::getValidArchivedForms($form);
     reset($ids);
     $id = current($ids);
     $ff = I2CE_FormFactory::instance();
     $docData = I2CE_FormStorage::listDisplayFields('generated_doc', array('date', 'description'), $id, array(), array('date'));
     //gets the generated docs which have this id as a parent
     $where = array('operator' => 'FIELD_LIMIT', 'field' => 'primary_form', 'style' => 'equals', 'data' => array('value' => $id));
     $docDataPrim = I2CE_FormStorage::listDisplayFields('generated_doc', array('date', 'description'), false, $where, array('date'));
     //gets the generated docs which have this id as a parent
     $docData = $docData + $docDataPrim;
     if (count($docData) == 0) {
         $this->template->setDisplayData('has_archives', 0);
         return true;
     }
     $this->template->setDisplayData('has_archives', 1);
     $append_node = $this->template->getElementById('printed_forms_archive');
     if (!$append_node instanceof DOMNode) {
         I2CE::raiseError("Could no find printed_forms_archive");
         return false;
     }
     $add_node = $this->template->loadFile('printed_forms_menu_archive_each.html', 'li');
     if (!$add_node instanceof DOMElement) {
         I2CE::raiseError("Bad 'printed_forms_menu_archive each.html'");
         return true;
     }
     foreach ($docData as $id => $data) {
         $node = $add_node->cloneNode(true);
         $this->template->appendNode($node, $append_node);
         $link = I2CE_FormField_BINARY_FILE::getFieldLink("generated_doc|" . $id, 'document');
         $this->template->setDisplayDataImmediate('view_archive_link', $link, $node);
         $this->template->setDisplayData('gen_date', $data['date'], $node);
         $this->template->setDisplayData('gen_desc', $data['description'], $node);
     }
     return true;
 }
 /**
  * Load this value from the temporary upload table
  * @param $key;
  */
 public function storeInTemporaryTable()
 {
     if (!$this->tmp_key) {
         return false;
     }
     if (!self::$storeStmt) {
         $db = MDB2::singleton();
         $stmt = $db->prepare("REPLACE INTO `temp_upload` (`key`,`value`) VALUES (?,?)", array('text', 'blob'), MDB2_PREPARE_MANIP);
         if (I2CE::pearError($stmt, "Error creating store stement")) {
             return false;
         }
         self::$storeStmt = $stmt;
     }
     $res = self::$storeStmt->execute(array($this->tmp_key, $this->getDBValue()));
     if (I2CE::pearError($res, "Could not store into temp_upload")) {
         return false;
     }
 }