3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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)
54 * The title associated with this page.
61 * A page can have multiple modes. (i.e. displays
62 * a different set of data based on the input
68 * Is this object being embedded in another object. If
69 * so the display routine needs to not do any work. (The
70 * parent object takes care of the display)
74 protected $_embedded = FALSE;
77 * Are we in print mode? if so we need to modify the display
78 * functionality to do a minimal display :)
82 protected $_print = FALSE;
85 * Cache the smarty template for efficiency reasons
87 * @var CRM_Core_Smarty
89 static protected $_template;
92 * Cache the session for efficiency reasons
94 * @var CRM_Core_Session
96 static protected $_session;
99 * What to return to the client if in ajax mode (snippet=json)
103 public $ajaxResponse = array();
106 * Url path used to reach this page
110 public $urlPath = array();
113 * Should crm.livePage.js be added to the page?
116 public $useLivePageJS;
121 * @param string $title
126 * @return CRM_Core_Page
128 public function __construct($title = NULL, $mode = NULL) {
129 $this->_name
= CRM_Utils_System
::getClassName($this);
130 $this->_title
= $title;
131 $this->_mode
= $mode;
133 // let the constructor initialize this, should happen only once
134 if (!isset(self
::$_template)) {
135 self
::$_template = CRM_Core_Smarty
::singleton();
136 self
::$_session = CRM_Core_Session
::singleton();
139 // FIXME - why are we messing with 'snippet'? Why not just pass it directly into $this->_print?
140 if (!empty($_REQUEST['snippet'])) {
141 if ($_REQUEST['snippet'] == CRM_Core_Smarty
::PRINT_PDF
) {
142 $this->_print
= CRM_Core_Smarty
::PRINT_PDF
;
144 // FIXME - why does this number not match the constant?
145 elseif ($_REQUEST['snippet'] == 5) {
146 $this->_print
= CRM_Core_Smarty
::PRINT_NOFORM
;
148 // Support 'json' as well as legacy value '6'
149 elseif (in_array($_REQUEST['snippet'], array(CRM_Core_Smarty
::PRINT_JSON
, 6))) {
150 $this->_print
= CRM_Core_Smarty
::PRINT_JSON
;
153 $this->_print
= CRM_Core_Smarty
::PRINT_SNIPPET
;
157 // if the request has a reset value, initialize the controller session
158 if (!empty($_REQUEST['reset'])) {
164 * This function takes care of all the things common to all
165 * pages. This typically involves assigning the appropriate smarty
168 * @return void|string
169 * The content generated by running this page
171 public function run() {
172 if ($this->_embedded
) {
176 self
::$_template->assign('mode', $this->_mode
);
178 $pageTemplateFile = $this->getHookedTemplateFileName();
179 self
::$_template->assign('tplFile', $pageTemplateFile);
181 // invoke the pagRun hook, CRM-3906
182 CRM_Utils_Hook
::pageRun($this);
185 if (in_array($this->_print
, array(
186 CRM_Core_Smarty
::PRINT_SNIPPET
,
187 CRM_Core_Smarty
::PRINT_PDF
,
188 CRM_Core_Smarty
::PRINT_NOFORM
,
189 CRM_Core_Smarty
::PRINT_JSON
,
191 $content = self
::$_template->fetch('CRM/common/snippet.tpl');
194 $content = self
::$_template->fetch('CRM/common/print.tpl');
197 CRM_Utils_System
::appendTPLFile($pageTemplateFile,
199 $this->overrideExtraTemplateFileName()
202 //its time to call the hook.
203 CRM_Utils_Hook
::alterContent($content, 'page', $pageTemplateFile, $this);
205 if ($this->_print
== CRM_Core_Smarty
::PRINT_PDF
) {
206 CRM_Utils_PDF_Utils
::html2pdf($content, "{$this->_name}.pdf", FALSE,
207 array('paper_size' => 'a3', 'orientation' => 'landscape')
210 elseif ($this->_print
== CRM_Core_Smarty
::PRINT_JSON
) {
211 $this->ajaxResponse
['content'] = $content;
212 CRM_Core_Page_AJAX
::returnJsonResponse($this->ajaxResponse
);
217 CRM_Utils_System
::civiExit();
220 $config = CRM_Core_Config
::singleton();
222 // Version check and intermittent alert to admins
223 CRM_Utils_VersionCheck
::singleton()->versionAlert();
224 CRM_Utils_Check
::singleton()->showPeriodicAlerts();
226 if ($this->useLivePageJS
&&
227 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'ajaxPopupsEnabled', NULL, TRUE)
229 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header');
230 $this->assign('includeWysiwygEditor', TRUE);
233 $content = self
::$_template->fetch('CRM/common/' . strtolower($config->userFramework
) . '.tpl');
235 // Render page header
236 if (!defined('CIVICRM_UF_HEAD') && $region = CRM_Core_Region
::instance('html-header', FALSE)) {
237 CRM_Utils_System
::addHTMLHead($region->render(''));
239 CRM_Utils_System
::appendTPLFile($pageTemplateFile, $content);
241 //its time to call the hook.
242 CRM_Utils_Hook
::alterContent($content, 'page', $pageTemplateFile, $this);
244 echo CRM_Utils_System
::theme($content, $this->_print
);
248 * Store the variable with the value in the form scope.
250 * @param string|array $name name of the variable or an assoc array of name/value pairs
251 * @param mixed $value
252 * Value of the variable if string.
257 public function set($name, $value = NULL) {
258 self
::$_session->set($name, $value, $this->_name
);
262 * Get the variable from the form scope.
264 * @param string $name name of the variable
268 public function get($name) {
269 return self
::$_session->get($name, $this->_name
);
273 * Assign value to name in template.
276 * @param mixed $value
281 public function assign($var, $value = NULL) {
282 self
::$_template->assign($var, $value);
286 * Assign value to name in template by reference.
289 * @param mixed $value
290 * (reference) value of varaible.
294 public function assign_by_ref($var, &$value) {
295 self
::$_template->assign_by_ref($var, $value);
299 * Appends values to template variables.
301 * @param array|string $tpl_var the template variable name(s)
302 * @param mixed $value
303 * The value to append.
306 public function append($tpl_var, $value = NULL, $merge = FALSE) {
307 self
::$_template->append($tpl_var, $value, $merge);
311 * Returns an array containing template variables.
313 * @param string $name
317 public function get_template_vars($name = NULL) {
318 return self
::$_template->get_template_vars($name);
322 * Destroy all the session state of this page.
327 public function reset() {
328 self
::$_session->resetScope($this->_name
);
332 * Use the form name to create the tpl file name.
336 public function getTemplateFileName() {
338 CRM_Utils_System
::getClassName($this),
340 '_' => DIRECTORY_SEPARATOR
,
341 '\\' => DIRECTORY_SEPARATOR
,
347 * A wrapper for getTemplateFileName that includes calling the hook to
348 * prevent us from having to copy & paste the logic of calling the hook
350 public function getHookedTemplateFileName() {
351 $pageTemplateFile = $this->getTemplateFileName();
352 CRM_Utils_Hook
::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile);
353 return $pageTemplateFile;
357 * Default extra tpl file basically just replaces .tpl with .extra.tpl
358 * i.e. we dont override
362 public function overrideExtraTemplateFileName() {
367 * Setter for embedded.
369 * @param bool $embedded
373 public function setEmbedded($embedded) {
374 $this->_embedded
= $embedded;
378 * Getter for embedded.
381 * return the embedded value
383 public function getEmbedded() {
384 return $this->_embedded
;
394 public function setPrint($print) {
395 $this->_print
= $print;
402 * return the print value
404 public function getPrint() {
405 return $this->_print
;
409 * @return CRM_Core_Smarty
411 public static function &getTemplate() {
412 return self
::$_template;
416 * @param string $name
420 public function getVar($name) {
421 return isset($this->$name) ?
$this->$name : NULL;
425 * @param string $name
428 public function setVar($name, $value) {
429 $this->$name = $value;