//------------------------------------------------------------------------------
// FICHIER : $RCSfile: annu_old_class.php,v $
// AUTEUR : $Author: guillaume $
// VERSION : $Revision: 1.25 $
// DATE : $Date: 2010-01-07 13:55:59 $
//------------------------------------------------------------------------------
// GSite - Web site management in PHP - users management
//
// Copyright (C) 2002 COUDOUNEAU Laurent (lc@gsite.org)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Require classes.
require_once 'php/api_annu.php';
require_once 'modules/frameworks/engine/engine_class.php';
require_once 'modules/std/annu_old/annu_old_show_class.php';
require_once 'modules/std/annu_old/annu_old_admin_class.php';
require_once 'modules/std/annu_old/annu_old_fields_class.php';
require_once 'modules/std/annu_old/annu_old_filter.php';
require_once 'resources/phpmailer/class.phpmailer.php';
//------------------------------------------------------------------------------
class annuOldClass extends engineClass {
/**
* Array to stock temporarily infos to use with pattern callback.
* @var array
*/
var $automailStatusInfos_ = null;
/**
* AnnuOldFilterClass object .
* @var array
*/
var $filterObj_ = null;
/*
* Bolean to know if we manage label mode
* of a filter.
*/
var $filter_mode_is_label_ = false;
/**
* In the case where the filter_mode is label, this variable represents the appli
* name of the field L_APPL to the Label linked to the translation filter.
* @var string
*/
var $filter_appli_label_ = 'filter_kw';
/**
* Store the user id which the icon status for update is hidden
* @var string
*/
var $noUpdateStatusIconUsersArray_ = null;
//============================================================================
/**
* OVERLOAD of factory
*/
//============================================================================
function & factory ($args = null) {
static $S_instance = null;
if ($S_instance == null) {
$S_instance = new annuOldClass ($args);
}
return $S_instance;
}
//============================================================================
/**
* OVERLOAD of run
*/
//============================================================================
function run ($args = null) {
//--------------------------------------------------------------------------
// Get object.
$object =& annuOldClass::factory ($args);
//----------------------------------------------------------------------------
// Manage auth.
if (! $object->manageAuth ($loginForm)) return $loginForm;
//----------------------------------------------------------------------------
// Run engine management.
return $object->manageEngine ();
}
//============================================================================
// CONSTRUCTOR
//
// By default, we provide standard classes to manage users (annuOldShowClass,
// annuOldAdminClass and annuOldFieldsClass). But subclasses of annuOldClass may pass
// to this constructor subclasses of these classes.
// $args is an alternate solution for $GS_ARGUMENTS arguments. See parent
// class for more informations.
//============================================================================
function annuOldClass ($show = null, $admin = null, $fields = null, $args = null) {
parent::engineClass (
(empty ($show) ? new annuOldShowClass () : $show),
(empty ($admin) ? new annuOldAdminClass () : $admin),
(empty ($fields) ? new annuOldFieldsClass () : $fields),
$args);
//--------------------------------------------------------------------------
// Arguments.
global $GS_GLOBAL;
global $GS_ARGUMENTS;
global $GS_PROJECT_ARGUMENTS;
if (empty ($args)) $args = $GS_ARGUMENTS;
$prjArgs = $GS_PROJECT_ARGUMENTS;
$this->args_ = array ();
$this->args_['filter'] = (isset ($args['filter']) ? $args['filter'] : '');
$this->args_['popupset'] = (isset ($args['popupset']) ? $args['popupset'] : 'frame');
$this->args_['searchtype'] = (isset ($args['searchtype']) ? $args['searchtype'] : 'letter');
$this->args_['empty_start']= (isset ($args['empty_start'])? $args['empty_start'] =='true': false);
$this->args_['seealso'] = (isset ($args['seealso']) ? $args['seealso'] : '');
$this->args_['auth_annu'] = (isset ($args['auth_annu']) ? $args['auth_annu'] : '');
$this->args_['onlyone'] = (isset ($args['onlyone']) && !empty ($args['onlyone']) ? $args['onlyone'] : -1);
//--------------------------------------------------------------------------
// Manage filter mode / filter_appli_label.
$this->args_['filter_mode'] = (isset ($args['filter_mode'])? $args['filter_mode']:'');
$this->filter_mode_is_label_ = ($this->args_['filter_mode'] == 'label');
$this->args_['filter_appli_label'] = (isset ($args['filter_appli_label'])? $args['filter_appli_label'] : '');
$this->filter_appli_label_ = ($this->args_['filter_appli_label']!='')? $this->args_['filter_appli_label'] : $this->filter_appli_label_;
//--------------------------------------------------------------------------
// Manage diffusion action.
//old: $this->args_['diffusion'] = (isset ($args['diffusion']) ? $args['diffusion'] == 'true' : false);
$this->args_['diffusion'] = ($this->action_ == 'diffusion');
//-- SMTP server
$this->args_['diffusion_smtp'] = (isset ($args['diffusion_smtp']) ? $args['diffusion_smtp'] : 'localhost:25');
//-- Project Arguments priority
$this->args_['diffusion_smtp'] = (isset ($prjArgs['diffusion_smtp']) ? $prjArgs['diffusion_smtp'] : $this->args_['diffusion_smtp']);
//--------------------------------------------------------------------------
// The mode 'diffusion' force several options :
if ($this->args_['diffusion']) {
//Force to 'show' mode.
$this->action_ = 'show';
//Always Authentification mode.
$this->withAuth_ = true;
//No close.
$this->openclose_ = false;
//No max.
$this->max_ = 0;
}
//--------------------------------------------------------------------------
// Manage U_STATUS TRIGGER
//-- status_automail : if <> 0, send an email automatically when a cmd
// update U_STATUS on the zero value.
$this->args_['status_automail'] = (isset ($args['status_automail'])? $args['status_automail']: '0');
if ( $this->args_['status_automail'] == '') $this->args_['status_automail']= '0';
//-- status_okmsg_pattern : pattern
$this->args_['status_okmsg_pattern'] = (isset ($args['status_okmsg_pattern']) ? $args['status_okmsg_pattern'] : '');
//-- Force a default pattern
if ( $this->args_['status_okmsg_pattern'] == '') $this->args_['status_okmsg_pattern']= 'statut_automail.html';
//-- status_emailsender
$this->args_['status_emailsender'] = (isset ($args['status_emailsender']) ? $args['status_emailsender'] : '');
//-- status_smtp .
// NOTE: we have the same smtp for status_automail and diffusion mode.
$this->args_['status_smtp'] = $this->args_['diffusion_smtp'];
//-- status_filter_value
$this->args_['status_filter_value'] = (isset ($args['status_filter_value']) ? $args['status_filter_value'] : '');
//-- status_mailformat
$this->args_['status_mailformat'] = (isset ($args['status_mailformat']) ? $args['status_mailformat'] : 'plaintxt');
//-- Pattern mandatory sections
$this->initAutoMailStatusInfos ();
//-- Allow to display the icon to update u_status.
$this->args_['status_mode_desactif'] = (isset ($args['status_mode_desactif']) ? $args['status_mode_desactif'] == 'true' : false);
if (!$this->args_['status_mode_desactif']) {
//-- Allow to display the icon to update u_status.
$this->args_['noUpdateStatusIconForUsers'] = (isset ($args['noUpdateStatusIconForUsers']) ? $args['noUpdateStatusIconForUsers']:'');
/*
if ($this->args_['noUpdateStatusIconForUsers']!= '' ) {
$uidArray = explode ('|', $this->args_['noUpdateStatusIconForUsers']);
foreach ($uidArray as $uidKey) {
$this->noUpdateStatusIconUsersArray_[$uidKey] = 1 ;
}
}
*/
$this->initNoUpdateStatusIconUsersArray ($this, $this->noUpdateStatusIconUsersArray_);
}
//--------------------------------------------------------------------------
// Include see also ?
if (! empty ($this->args_['seealso'])) {
$seealsoFile = 'appl/'.$this->args_['seealso'].'.php';
if (file_exists ($seealsoFile)) {
include_once ($seealsoFile);
} else {
echo "Unable to find see also file $seealsoFile ";
}
}
//--------------------------------------------------------------------------
// Init instance of filter object. (NOTE: We must place this initialisation
// after all args inits.)
$this->initFilterObj ($this);
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// OVERLOAD METHODS
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//============================================================================
/**
* Overload user login management, according to a special object.
*
* We check that the level of the user is not greater than 1.
*
* @param object this object defines the login policy
* @param string if login is needed, login form
* @return boolean
*/
//============================================================================
function manageAuthWithObject (&$loginObj, &$outputText) {
$ok = engineClass::manageAuthWithObject ($loginObj, $outputText);
if ($ok && $this->withAuth_) {
if ($this->userLevel_ > 1) {
$msg = $this->label ('adm_not_admin', 'gsite');
$outputText =
'
'."\n".
'
'.$msg.'
'."\n".
'
'."\n";
return false;
}
}
return $ok;
}
//============================================================================
// OVERLOAD withSearch ()
//
// If we are under admin mode (action == admin), we have search only if the
// user is an administrator. Under other modes, we use $this->withSearch_.
//============================================================================
function withSearch () {
if ($this->action_ == 'admin') {
return $this->isAdministrator_;
}
return $this->withSearch_;
}
//============================================================================
// OVERLOAD manageEngine ()
//
// Manage a new action: filter (filters management), for administrators only.
//============================================================================
function manageEngine () {
$msg = '';
//--------------------------------------------------------------------------
// Manage filters ?
if ($this->action_ == 'filter') {
if (($this->userID_ > 0) && $this->isAdministrator_) {
return $this->filterObj_->filterAdministration ($this);
} else {
$msg = $this->label ('adm_not_admin', 'gsite');
return
'
'."\n".
'
'.$msg.'
'."\n".
'
'."\n";
}
}
//--------------------------------------------------------------------------
// Automail status.
if (! $this->manageAutoMailStatus ($msg)) {
$introMsg = $this->label ('annu_mailstatus_msgintro'); //"Mode d'envoi automatique de mail sur changement de statut IMPOSSIBLE :";
$adviceMsg = $this->label ('annu_mailstatus_advice'); //"Veuillez changer ce mode pour pouvoir utiliser ce module.";
return
'
'."\n".
'
'.$introMsg.'
'."\n".
'
'."\n".
'
'."\n".
'
'.$msg.'
'."\n".
'
'."\n".
'
'."\n".
'
'.$adviceMsg.'
'."\n".
'
'."\n";
}
//--------------------------------------------------------------------------
// Default.
$engine = parent::manageEngine ();
//--------------------------------------------------------------------------
// Diffusion ?
$diffusion = '';
if ($this->args_['diffusion']) {
registerJS($this);
$diffusion = $this->diffusion ();
}
return $engine.$diffusion;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// SPECIFIC METHODS
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//============================================================================
/**
* Init Filter Object.
*/
//============================================================================
function initFilterObj (&$mainObj) {
$this->filterObj_ = new annuOldFilterClass($mainObj);
}
//============================================================================
/**
* Init automail status Infos.
*/
//============================================================================
function initAutoMailStatusInfos () {
//-- Init mandatory section in the pattern file.
$this->automailStatusInfos_['sections'] =
array('vBody' => 'statut_automail_validate_body',
'vSubject'=> 'statut_automail_validate_subject');
//-- Init mailformat (html|plaintxt).
$this->automailStatusInfos_['mailformat'] = $this->args_['status_mailformat'];
//-- Init addBcc flag.
$this->automailStatusInfos_['isAddBcc'] = false;
}
//============================================================================
/**
* Manage automail status controle.
*/
//============================================================================
function manageAutoMailStatus (&$msg) {
//--------------------------------------------------------------------------
// Inits
$bIsOk = true;
$pattern = '';
//--------------------------------------------------------------------------
// Manage Check.
if ($this->args_['status_automail'] != '0') {
if (empty($this->args_['status_smtp'])) {
$bIsOk = false;
$msg = $this->label ('annu_mailstatus_badsmtp');
} elseif ( $this->args_['status_emailsender'] == '') {
//-- In this case test if user current have an valid email.
$userROW = gsapi_annu_getUserByAnnuFromID ($this, $this->userID_, $this->args_['auth_annu']);
if ( (empty ($userROW->U_MAIL)) || (! gs_isValidEmail ($userROW->U_MAIL)) ) {
$bIsOk = false;
$msg = $this->label ('annu_mailstatus_baduseremail1');
$msg .= $this->label ('annu_mailstatus_baduseremail2');
} else {
//-- Force current user email as email sender.
$this->args_['status_emailsender'] = $userROW->U_MAIL;
}
} elseif (! gs_isValidEmail ($this->args_['status_emailsender'])) {
$bIsOk = false;
$msg = $this->label ('annu_mailstatus_badsender');
$msg .= ' ('.$this->args_['status_emailsender'].')';
} elseif (empty($this->args_['status_okmsg_pattern'])) {
$bIsOk = false;
$msg = $this->label ('annu_mailstatus_nookpattern');
} else {
//----------------------------------------------------------------------
// Check - pattern && mandatory sections
foreach ($this->automailStatusInfos_['sections'] as $section) {
$pattern = $this->args_['status_okmsg_pattern'].'#'.$section;
if (! gs_loadPattern ($this->project_,
$pattern,
$this,
'')
) {
$bIsOk = false;
$msg = $this->label ('annu_mailstatus_badokpattern');
$msg .= ' ('.$pattern.')';
return $bIsOk;
}
}
}
return $bIsOk;
}
return $bIsOk;
}
//============================================================================
/**
* Manage automail status callback to send a Automail with the pattern
* (status_okmsg_pattern).
* This function is called in adminAnnuClass::sendAutomailStatus() function.
*/
//============================================================================
function callbackAutoMailStatus(&$mainObj, &$args) {
if (isset($args[0]) && isset($args[1]) ) {
$fieldType = $args[0];
$fieldName = $args[1];
//------------------------------------------------------------------------
// Get Field infos data row
//
// NOTE : we must use showObj_ or annuShowClass to use correctly the
// dumpFieldByName function. Because adminObj or adminAnnuClass
// overload dumpFieldByName function by dumpUpdateFieldByName
// to have a correct interactivity to update each ield.
// So, here we just wants to keep the value in the goal to
// push it in the pattern.
// Then, a call like 'annuShowClass::dumpFieldByName(..)
// is also right.
$fieldData = $mainObj->showObj_->dumpFieldByName ($mainObj, $fieldName, $mainObj->automailStatusInfos_['uRow']);
switch ($fieldType) {
case 'value':
return $fieldData['value'];
break;
case 'field':
return $fieldData['field'];
break;
default :
return '';
}
}
return '';
}
//============================================================================
/**
* Init the array of user where the update icon status mode is hidden.
*
* We check that the level of the user is not greater than 1.
*
* @param object $mainObj Main object.
* @param array $uidArray Array to store the uid list of such users.
* @return boolean
*/
//============================================================================
function initNoUpdateStatusIconUsersArray (&$mainObj, &$uidArray) {
$tmpArray = null;
if ($mainObj->args_['noUpdateStatusIconForUsers']!= '' ) {
$tmpArray = explode ('|', $mainObj->args_['noUpdateStatusIconForUsers']);
foreach ($tmpArray as $key => $value) {
$uidArray [$value] = 1 ;
}
}
}
//============================================================================
/**
* Manage diffusion mode.
*/
//============================================================================
function diffusion () {
global $GS_GLOBAL;
$STYLErow = $GS_GLOBAL['style_row'];
//--------------------------------------------------------------------------
// An user must be logged.
if ($this->userID_ <= 0) return '';
//--------------------------------------------------------------------------
// Register css.
css_register ('linkBtn',
".linkBtn {\n".
" font-family: $STYLErow->S_FONT_FAMILY;\n".
" font-size: $STYLErow->S_FONT_SIZE_SMALL;\n".
" font-style: normal;\n".
" font-weight: bold;\n".
" text-align: center;\n".
" text-decoration: none;\n".
" vertical-align: middle;\n".
" color: $STYLErow->S_COLOR_TEXT;\n".
" background-color: $STYLErow->S_COLOR_3;\n".
"}\n"
);
//--------------------------------------------------------------------------
// The current user must have a mail.
//
// BE CAREFUL : THE USER CONNECTED IS IN THE $this->args_['auth_annu'] annu
// not necessarily in the $this->annu !
$userROW = gsapi_annu_getUserByAnnuFromID ($this, $this->userID_, $this->args_['auth_annu']);
if (empty ($userROW->U_MAIL)) {
$error =
'