From 298c4c6fc769f71ed7d5a21564dbb7d0d5872aff Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 22 Sep 2010 08:52:48 +0000 Subject: [PATCH] Add Smartphone class Fix: mutualized code --- htdocs/core/class/smartphone.class.php | 29 ++++++++++--- htdocs/lib/security.lib.php | 13 +++--- .../phones/smartphone/tpl/footer.tpl.php | 27 ++++++++++++ .../phones/smartphone/tpl/header.tpl.php | 43 +++++++++++++++++++ .../theme/phones/smartphone/tpl/login.tpl.php | 27 ++---------- .../smartphone/tpl/passwordforgotten.tpl.php | 26 ++--------- htdocs/user/passwordforgotten.php | 9 ++-- 7 files changed, 115 insertions(+), 59 deletions(-) create mode 100644 htdocs/theme/phones/smartphone/tpl/footer.tpl.php create mode 100644 htdocs/theme/phones/smartphone/tpl/header.tpl.php diff --git a/htdocs/core/class/smartphone.class.php b/htdocs/core/class/smartphone.class.php index 2100b290e62..ce774cd0c04 100644 --- a/htdocs/core/class/smartphone.class.php +++ b/htdocs/core/class/smartphone.class.php @@ -33,6 +33,8 @@ class Smartphone { var $phone; var $theme; + var $title; + var $template_dir; /** * Constructor for class @@ -52,21 +54,38 @@ class Smartphone { if (preg_match('/android|blackberry|iphone/i',$this->phone)) { $this->theme = 'default'; - $template_dir=DOL_DOCUMENT_ROOT."/theme/phones/smartphone/tpl/"; + $this->template_dir=DOL_DOCUMENT_ROOT."/theme/phones/smartphone/tpl/"; } // Special template elseif (file_exists(DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone)) { $this->theme = 'default'; - $template_dir=DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone."/tpl/"; + $this->template_dir=DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone."/tpl/"; } // Default template else { - $template_dir=DOL_DOCUMENT_ROOT."/theme/phones/others/tpl/"; + $this->template_dir=DOL_DOCUMENT_ROOT."/theme/phones/others/tpl/"; } - - return $template_dir; } + + /** + * Show HTML header + * @param title Web page title + */ + function smartheader() + { + global $conf; + + include_once($this->template_dir.'header.tpl.php'); + } + + /** + * Show HTML footer + */ + function smartfooter() + { + include_once($this->template_dir.'footer.tpl.php'); + } } diff --git a/htdocs/lib/security.lib.php b/htdocs/lib/security.lib.php index 9f00bfd63c7..62f1eb1f48a 100644 --- a/htdocs/lib/security.lib.php +++ b/htdocs/lib/security.lib.php @@ -51,11 +51,18 @@ function dol_loginfunction($langs,$conf,$mysoc) $php_self = $_SERVER['PHP_SELF']; $php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:''; + + // Title + $title='Dolibarr '.DOL_VERSION; + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; // Select templates if (class_exists('Smartphone')) { - $template_dir = $smartphone->getTemplateDir(); + // Template directory + $smartphone->getTemplateDir(); + $smartphone->title = $title; + $template_dir = $smartphone->template_dir; } else { @@ -88,10 +95,6 @@ function dol_loginfunction($langs,$conf,$mysoc) $login_background=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_background.png'; } - // Title - $title='Dolibarr '.DOL_VERSION; - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; - $demologin=''; $demopassword=''; if (! empty($dolibarr_main_demo)) diff --git a/htdocs/theme/phones/smartphone/tpl/footer.tpl.php b/htdocs/theme/phones/smartphone/tpl/footer.tpl.php new file mode 100644 index 00000000000..e4578d21972 --- /dev/null +++ b/htdocs/theme/phones/smartphone/tpl/footer.tpl.php @@ -0,0 +1,27 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ +?> + + + + + + + \ No newline at end of file diff --git a/htdocs/theme/phones/smartphone/tpl/header.tpl.php b/htdocs/theme/phones/smartphone/tpl/header.tpl.php new file mode 100644 index 00000000000..9b722bb10e6 --- /dev/null +++ b/htdocs/theme/phones/smartphone/tpl/header.tpl.php @@ -0,0 +1,43 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ +header('Cache-Control: Public, must-revalidate'); +header("Content-type: text/html; charset=".$conf->file->character_set_client); +?> + + + + + + + + +<?php echo $this->title; ?> + + + + + + + + + + + \ No newline at end of file diff --git a/htdocs/theme/phones/smartphone/tpl/login.tpl.php b/htdocs/theme/phones/smartphone/tpl/login.tpl.php index 84caeb5f5a9..c8e076f55f5 100644 --- a/htdocs/theme/phones/smartphone/tpl/login.tpl.php +++ b/htdocs/theme/phones/smartphone/tpl/login.tpl.php @@ -17,28 +17,10 @@ * * $Id$ */ -header('Cache-Control: Public, must-revalidate'); -header("Content-type: text/html; charset=".$conf->file->character_set_client); +$smartphone->smartheader($title); ?> - - - - - - - -<?php echo $title; ?> - - - - - - - - - +
@@ -127,7 +109,6 @@ header("Content-type: text/html; charset=".$conf->file->character_set_client); - - +smartfooter(); ?> - \ No newline at end of file + \ No newline at end of file diff --git a/htdocs/theme/phones/smartphone/tpl/passwordforgotten.tpl.php b/htdocs/theme/phones/smartphone/tpl/passwordforgotten.tpl.php index 09259e672e5..a737e8e9bbc 100644 --- a/htdocs/theme/phones/smartphone/tpl/passwordforgotten.tpl.php +++ b/htdocs/theme/phones/smartphone/tpl/passwordforgotten.tpl.php @@ -17,27 +17,10 @@ * * $Id$ */ -header('Cache-Control: Public, must-revalidate'); -header("Content-type: text/html; charset=".$conf->file->character_set_client); +$smartphone->smartheader($title); ?> - - - - - - - -<?php echo $langs->trans('Password'); ?> - - - - - - - - +
trans('Password'); ?>
@@ -112,7 +95,6 @@ header("Content-type: text/html; charset=".$conf->file->character_set_client); - - +smartfooter(); ?> - \ No newline at end of file + \ No newline at end of file diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index 3121751948e..33a04ec0121 100644 --- a/htdocs/user/passwordforgotten.php +++ b/htdocs/user/passwordforgotten.php @@ -143,11 +143,16 @@ $php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:''; $dol_url_root = DOL_URL_ROOT; +// Title +$title='Dolibarr '.DOL_VERSION; +if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; + // Select templates if (class_exists('Smartphone')) { // Template directory $smartphone->getTemplateDir(); + $smartphone->title = $title; $template_dir = $smartphone->template_dir; } else @@ -177,10 +182,6 @@ else if (! $_REQUEST["username"]) $focus_element = 'username'; else $focus_element = 'password'; -// Title -$title='Dolibarr '.DOL_VERSION; -if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; - // Send password button enabled ? $disabled='disabled'; if ($mode == 'dolibarr') $disabled='';