3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * A Page is basically data in a nice pretty format.
39 * Pages should not have any form actions / elements in them. If they
40 * do, make sure you use CRM_Core_Form and the related structures. You can
41 * embed simple forms in Page and do your own form handling.
47 * The name of the page (auto generated from class name)
55 * the title associated with this page
63 * A page can have multiple modes. (i.e. displays
64 * a different set of data based on the input
71 * Is this object being embedded in another object. If
72 * so the display routine needs to not do any work. (The
73 * parent object takes care of the display)
78 protected $_embedded = FALSE;
81 * Are we in print mode? if so we need to modify the display
82 * functionality to do a minimal display :)
87 protected $_print = FALSE;
90 * cache the smarty template for efficiency reasons
92 * @var CRM_Core_Smarty
96 static protected $_template;
99 * cache the session for efficiency reasons
101 * @var CRM_Core_Session
105 static protected $_session;
110 * @param string $title title of the page
111 * @param int $mode mode of the page
113 * @return CRM_Core_Page
115 function __construct($title = NULL, $mode = NULL) {
116 $this->_name
= CRM_Utils_System
::getClassName($this);
117 $this->_title
= $title;
118 $this->_mode
= $mode;
120 // let the constructor initialize this, should happen only once
121 if (!isset(self
::$_template)) {
122 self
::$_template = CRM_Core_Smarty
::singleton();
123 self
::$_session = CRM_Core_Session
::singleton();
126 if (isset($_REQUEST['snippet']) && $_REQUEST['snippet']) {
127 if ($_REQUEST['snippet'] == 3) {
128 $this->_print
= CRM_Core_Smarty
::PRINT_PDF
;
130 else if ($_REQUEST['snippet'] == 5) {
131 $this->_print
= CRM_Core_Smarty
::PRINT_NOFORM
;
134 $this->_print
= CRM_Core_Smarty
::PRINT_SNIPPET
;
138 // if the request has a reset value, initialize the controller session
139 if (CRM_Utils_Array
::value('reset', $_REQUEST)) {
145 * This function takes care of all the things common to all
146 * pages. This typically involves assigning the appropriate
149 * @return string The content generated by running this page
152 if ($this->_embedded
) {
156 self
::$_template->assign('mode', $this->_mode
);
158 $pageTemplateFile = $this->getTemplateFileName();
159 self
::$_template->assign('tplFile', $pageTemplateFile);
161 // invoke the pagRun hook, CRM-3906
162 CRM_Utils_Hook
::pageRun($this);
165 if (in_array( $this->_print
, array( CRM_Core_Smarty
::PRINT_SNIPPET
,
166 CRM_Core_Smarty
::PRINT_PDF
, CRM_Core_Smarty
::PRINT_NOFORM
))) {
167 $content = self
::$_template->fetch('CRM/common/snippet.tpl');
170 $content = self
::$_template->fetch('CRM/common/print.tpl');
173 CRM_Utils_System
::appendTPLFile($pageTemplateFile,
175 $this->overrideExtraTemplateFileName()
178 //its time to call the hook.
179 CRM_Utils_Hook
::alterContent($content, 'page', $pageTemplateFile, $this);
181 if ($this->_print
== CRM_Core_Smarty
::PRINT_PDF
) {
182 CRM_Utils_PDF_Utils
::html2pdf($content, "{$this->_name}.pdf", FALSE,
183 array('paper_size' => 'a3', 'orientation' => 'landscape')
189 CRM_Utils_System
::civiExit();
192 $config = CRM_Core_Config
::singleton();
194 // TODO: Is there a better way to ensure these actions don't happen during AJAX requests?
195 if (empty($_GET['snippet'])) {
196 // Version check and intermittent alert to admins
197 CRM_Utils_VersionCheck
::singleton()->versionAlert();
199 // Debug msg once per hour
200 if ($config->debug
&& CRM_Core_Permission
::check('administer CiviCRM') && CRM_Core_Session
::singleton()->timer('debug_alert', 3600)) {
201 $msg = ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/debug', 'reset=1')));
202 CRM_Core_Session
::setStatus($msg, ts('Debug Mode'));
206 $content = self
::$_template->fetch('CRM/common/' . strtolower($config->userFramework
) . '.tpl');
208 // Render page header
209 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
210 CRM_Utils_System
::addHTMLHead($region->render(''));
212 CRM_Utils_System
::appendTPLFile($pageTemplateFile, $content);
214 //its time to call the hook.
215 CRM_Utils_Hook
::alterContent($content, 'page', $pageTemplateFile, $this);
217 echo CRM_Utils_System
::theme($content, $this->_print
);
222 * Store the variable with the value in the form scope
224 * @param string|array $name name of the variable or an assoc array of name/value pairs
225 * @param mixed $value value of the variable if string
232 function set($name, $value = NULL) {
233 self
::$_session->set($name, $value, $this->_name
);
237 * Get the variable from the form scope
239 * @param string name : name of the variable
246 function get($name) {
247 return self
::$_session->get($name, $this->_name
);
251 * assign value to name in template
253 * @param array|string $name name of variable
254 * @param mixed $value value of varaible
259 function assign($var, $value = NULL) {
260 self
::$_template->assign($var, $value);
264 * assign value to name in template by reference
266 * @param array|string $name name of variable
267 * @param mixed $value (reference) value of varaible
272 function assign_by_ref($var, &$value) {
273 self
::$_template->assign_by_ref($var, $value);
277 * function to destroy all the session state of this page.
284 self
::$_session->resetScope($this->_name
);
288 * Use the form name to create the tpl file name
293 function getTemplateFileName() {
294 return str_replace('_',
296 CRM_Utils_System
::getClassName($this)
301 * Default extra tpl file basically just replaces .tpl with .extra.tpl
302 * i.e. we dont override
307 function overrideExtraTemplateFileName() {
312 * setter for embedded
314 * @param boolean $embedded
319 function setEmbedded($embedded) {
320 $this->_embedded
= $embedded;
324 * getter for embedded
326 * @return boolean return the embedded value
329 function getEmbedded() {
330 return $this->_embedded
;
336 * @param boolean $print
341 function setPrint($print) {
342 $this->_print
= $print;
348 * @return boolean return the print value
351 function getPrint() {
352 return $this->_print
;
355 static function &getTemplate() {
356 return self
::$_template;
359 function getVar($name) {
360 return isset($this->$name) ?
$this->$name : NULL;
363 function setVar($name, $value) {
364 $this->$name = $value;