3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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;
108 * What to return to the client if in ajax mode (snippet=json)
112 public $ajaxResponse = array();
115 * Url path used to reach this page
119 public $urlPath = array();
122 * Should crm.livePage.js be added to the page?
125 public $useLivePageJS;
130 * @param string $title title of the page
131 * @param int $mode mode of the page
133 * @return CRM_Core_Page
135 function __construct($title = NULL, $mode = NULL) {
136 $this->_name
= CRM_Utils_System
::getClassName($this);
137 $this->_title
= $title;
138 $this->_mode
= $mode;
140 // let the constructor initialize this, should happen only once
141 if (!isset(self
::$_template)) {
142 self
::$_template = CRM_Core_Smarty
::singleton();
143 self
::$_session = CRM_Core_Session
::singleton();
146 // FIXME - why are we messing with 'snippet'? Why not just pass it directly into $this->_print?
147 if (!empty($_REQUEST['snippet'])) {
148 if ($_REQUEST['snippet'] == CRM_Core_Smarty
::PRINT_PDF
) {
149 $this->_print
= CRM_Core_Smarty
::PRINT_PDF
;
151 // FIXME - why does this number not match the constant?
152 elseif ($_REQUEST['snippet'] == 5) {
153 $this->_print
= CRM_Core_Smarty
::PRINT_NOFORM
;
155 // Support 'json' as well as legacy value '6'
156 elseif (in_array($_REQUEST['snippet'], array(CRM_Core_Smarty
::PRINT_JSON
, 6))) {
157 $this->_print
= CRM_Core_Smarty
::PRINT_JSON
;
160 $this->_print
= CRM_Core_Smarty
::PRINT_SNIPPET
;
164 // if the request has a reset value, initialize the controller session
165 if (!empty($_REQUEST['reset'])) {
171 * This function takes care of all the things common to all
172 * pages. This typically involves assigning the appropriate
175 * @return string The content generated by running this page
178 if ($this->_embedded
) {
182 self
::$_template->assign('mode', $this->_mode
);
184 $pageTemplateFile = $this->getHookedTemplateFileName();
185 self
::$_template->assign('tplFile', $pageTemplateFile);
187 // invoke the pagRun hook, CRM-3906
188 CRM_Utils_Hook
::pageRun($this);
191 if (in_array( $this->_print
, array( CRM_Core_Smarty
::PRINT_SNIPPET
,
192 CRM_Core_Smarty
::PRINT_PDF
, CRM_Core_Smarty
::PRINT_NOFORM
, CRM_Core_Smarty
::PRINT_JSON
))) {
193 $content = self
::$_template->fetch('CRM/common/snippet.tpl');
196 $content = self
::$_template->fetch('CRM/common/print.tpl');
199 CRM_Utils_System
::appendTPLFile($pageTemplateFile,
201 $this->overrideExtraTemplateFileName()
204 //its time to call the hook.
205 CRM_Utils_Hook
::alterContent($content, 'page', $pageTemplateFile, $this);
207 if ($this->_print
== CRM_Core_Smarty
::PRINT_PDF
) {
208 CRM_Utils_PDF_Utils
::html2pdf($content, "{$this->_name}.pdf", FALSE,
209 array('paper_size' => 'a3', 'orientation' => 'landscape')
212 elseif ($this->_print
== CRM_Core_Smarty
::PRINT_JSON
) {
213 $this->ajaxResponse
['content'] = $content;
214 CRM_Core_Page_AJAX
::returnJsonResponse($this->ajaxResponse
);
219 CRM_Utils_System
::civiExit();
222 $config = CRM_Core_Config
::singleton();
224 // Version check and intermittent alert to admins
225 CRM_Utils_VersionCheck
::singleton()->versionAlert();
226 CRM_Utils_Check_Security
::singleton()->showPeriodicAlerts();
228 // Debug msg once per hour
229 if ($config->debug
&& CRM_Core_Permission
::check('administer CiviCRM') && CRM_Core_Session
::singleton()->timer('debug_alert', 3600)) {
230 $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')));
231 CRM_Core_Session
::setStatus($msg, ts('Debug Mode'));
234 if ($this->useLivePageJS
&&
235 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'ajaxPopupsEnabled', NULL, TRUE))
237 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
240 $content = self
::$_template->fetch('CRM/common/' . strtolower($config->userFramework
) . '.tpl');
242 // Render page header
243 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
244 CRM_Utils_System
::addHTMLHead($region->render(''));
246 CRM_Utils_System
::appendTPLFile($pageTemplateFile, $content);
248 //its time to call the hook.
249 CRM_Utils_Hook
::alterContent($content, 'page', $pageTemplateFile, $this);
251 echo CRM_Utils_System
::theme($content, $this->_print
);
256 * Store the variable with the value in the form scope
258 * @param string|array $name name of the variable or an assoc array of name/value pairs
259 * @param mixed $value value of the variable if string
266 function set($name, $value = NULL) {
267 self
::$_session->set($name, $value, $this->_name
);
271 * Get the variable from the form scope
273 * @param string name : name of the variable
280 function get($name) {
281 return self
::$_session->get($name, $this->_name
);
285 * assign value to name in template
287 * @param array|string $name name of variable
288 * @param mixed $value value of varaible
293 function assign($var, $value = NULL) {
294 self
::$_template->assign($var, $value);
298 * assign value to name in template by reference
300 * @param array|string $name name of variable
301 * @param mixed $value (reference) value of varaible
306 function assign_by_ref($var, &$value) {
307 self
::$_template->assign_by_ref($var, $value);
311 * appends values to template variables
313 * @param array|string $tpl_var the template variable name(s)
314 * @param mixed $value the value to append
317 function append($tpl_var, $value=NULL, $merge=FALSE) {
318 self
::$_template->append($tpl_var, $value, $merge);
322 * Returns an array containing template variables
324 * @param string $name
325 * @param string $type
328 function get_template_vars($name=null) {
329 return self
::$_template->get_template_vars($name);
333 * function to destroy all the session state of this page.
340 self
::$_session->resetScope($this->_name
);
344 * Use the form name to create the tpl file name
349 function getTemplateFileName() {
350 return str_replace('_',
352 CRM_Utils_System
::getClassName($this)
357 * A wrapper for getTemplateFileName that includes calling the hook to
358 * prevent us from having to copy & paste the logic of calling the hook
360 function getHookedTemplateFileName() {
361 $pageTemplateFile = $this->getTemplateFileName();
362 CRM_Utils_Hook
::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile);
363 return $pageTemplateFile;
367 * Default extra tpl file basically just replaces .tpl with .extra.tpl
368 * i.e. we dont override
373 function overrideExtraTemplateFileName() {
378 * setter for embedded
380 * @param boolean $embedded
385 function setEmbedded($embedded) {
386 $this->_embedded
= $embedded;
390 * getter for embedded
392 * @return boolean return the embedded value
395 function getEmbedded() {
396 return $this->_embedded
;
402 * @param boolean $print
407 function setPrint($print) {
408 $this->_print
= $print;
414 * @return boolean return the print value
417 function getPrint() {
418 return $this->_print
;
421 static function &getTemplate() {
422 return self
::$_template;
425 function getVar($name) {
426 return isset($this->$name) ?
$this->$name : NULL;
429 function setVar($name, $value) {
430 $this->$name = $value;