//------------------------------------------------------------------------------ // FICHIER : $RCSfile: common.php,v $ // AUTEUR : $Author: jpm $ // VERSION : $Revision: 1.3 $ // DATE : $Date: 2002/12/16 16:25:12 $ //------------------------------------------------------------------------------ // GSite - Web site management in PHP - utilities functions // // Copyright (C) 2001 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 //------------------------------------------------------------------------------ // Utilities functions. //------------------------------------------------------------------------------ // Database table : /* CREATE TABLE LABELS ( L_IDENT varchar(32) NOT NULL default '', L_LOCALE varchar(5) NOT NULL default '', L_TRANSLATION varchar(255) NOT NULL default '', L_APPL varchar(32) NOT NULL default '' PRIMARY KEY (L_IDENT,L_LOCALE) ); */ //------------------------------------------------------------------------------ require 'php/img.php'; require 'php/file.php'; //============================================================================== // gs_hex2bin ($data) // $data : hex data (string) to be converted to binary. // // Convert hex value into binary value. //============================================================================== function gs_hex2bin ($data) { $len = strlen ($data); return pack ("H$len", $data); } //============================================================================== // gs_localizeTimestamp ($ts, $locale) // $ts : unix time stamp // $locale : locale code // // Convert an unix time stamp in respect with locale (en, fr, sp). //============================================================================== function gs_localizeTimestamp ($ts, $locale) { $format = 'Y/m/d H:m:s'; if ($locale == 'fr') $format = 'd/m/Y H:m:s'; if ($locale == 'sp') $format = 'd/m/Y H:m:s'; return date ($format, $ts); } //============================================================================== // gs_localizeDate ($date, $locale) // $date : date (MySQL format: YYYY-MM-DD) // $locale : locale code // // Convert a MySQL date in respect with locale (en, fr, sp). //============================================================================== function gs_localizeDate ($date, $locale) { $dateArray = explode ('-', $date); $y = $dateArray[0]; $m = $dateArray[1]; $d = $dateArray[2]; if ($locale == 'en') return "$y/$m/$d"; if ($locale == 'fr') return "$d/$m/$y"; if ($locale == 'sp') return "$d/$m/$y"; return $date; } //============================================================================== // gs_localizeDateTime ($date, $locale) // $datetime : datetime field (MySQL format: YYYY-MM-DD HH:MM:SS) // $locale : locale code // // Convert a MySQL date in respect with locale (en, fr, sp). //============================================================================== function gs_localizeDateTime ($datetime, $locale) { $date = substr ($datetime, 0, 10); $time = substr ($datetime, 11, 8); return gs_localizeDate ($date, $locale).' - '.$time; } //============================================================================== // gs_localizeDate2MySQL ($date, $locale) // $date : date (following locale) // $locale : locale code // // Convert a date to MySQL format in respect with locale (en, fr, sp). //============================================================================== function gs_localizeDate2MySQL ($date, $locale) { $dateArray = explode ('/', $date); if ($locale == 'en') return "$dateArray[0]-$dateArray[1]-$dateArray[2]"; if ($locale == 'fr') return "$dateArray[2]-$dateArray[1]-$dateArray[0]"; if ($locale == 'sp') return "$dateArray[2]-$dateArray[1]-$dateArray[0]"; return $date; } //============================================================================== // gs_getLabel ($db, $link, $ident, $locale, $appl, $entities) // $db : database name // $link : database link // $ident : label name // $locale : locale code // $appl : application name // $entities : htmlentities transformation ? // // Get localized label. If the label appears into a JavaScript string, $entities // MUST be false. //============================================================================== function gs_getLabel ($dbname, $link, $ident, $locale, $appl = '', $entities = true) { static $labelsCache = array (); $tag = "$ident $locale $appl"; if (isset ($labelsCache[$tag])) { return ($entities ? htmlentities ($labelsCache[$tag]) : $labelsCache[$tag]); } $query = "select L_TRANSLATION from $dbname.LABELS". " where L_IDENT='$ident' and L_LOCALE='$locale' and L_APPL='$appl'"; $result = mysql_query ($query, $link); if (! $result) { die ("Unable to perform query ($query / " . mysql_error ($link) . ")"); } if (mysql_num_rows ($result) == 0) { mysql_free_result ($result); return "($ident)"; } $row = mysql_fetch_object ($result); mysql_free_result ($result); $labelsCache[$tag] = $row->L_TRANSLATION; return ($entities ? htmlentities ($row->L_TRANSLATION) : $row->L_TRANSLATION); } //============================================================================== // gs_genericButtons ($db, $link, $locale, $buttons, $horizontal, $size, $styles) // $db : database name // $link : database link // $locale : locale code // $buttons : (...) // $horizontal : true if the buttons are horizontal, false otherwise // $appl : application name for labels // $size : (...) // $styles : (...) // // Button generation. // // $buttons is an array of button descriptions, each description is itself an // array, with the following informations: // - text : the label (according to gs_getLabel) of the button // - url : the URL to launch // - on : boolean, true is the button is on // - space : boolean, true if we have a space between two vertical buttons. // - appl : application name, for labels // // $size is another indexed array: // - width : button width // - height : button height // - space : space between two buttons // // $styles is the last indexed array: // - cssborder : style for border // - csson : style is the button is on // - cssoff : style is the button is off //============================================================================== function gs_genericButtons ($db, $link, $locale, $buttons, $horizontal = true, $size = '', $styles = '') { //---------------------------------------------------------------------------- // Set the sizes. if ((sizeof ($size) == 0) || (! is_array ($size))) { $width = 100; $height = 20; $space = 5; } else { $width = (isset ($size['width']) ? $size['width'] : 100); $height = (isset ($size['height']) ? $size['height'] : 20); $space = (isset ($size['space']) ? $size['space'] : 5); } //---------------------------------------------------------------------------- // Set the styles. if ((sizeof ($styles) == 0) || (! is_array ($styles))) { $cssborder = 'line'; $csson = 'btActive'; $cssoff = 'btInactive'; } else { $cssborder = (isset ($styles['cssborder']) ? $styles['cssborder'] : 'line'); $csson = (isset ($styles['csson']) ? $styles['csson'] : 'btActive'); $cssoff = (isset ($styles['cssoff']) ? $styles['cssoff'] : 'btInactive'); } //============================================================================ // Build the buttons. $str = ''; //---------------------------------------------------------------------------- // Main table. $str .= '
![]() | ';
}
$str .= "\n".' |||
![]() | ';
$str .= "\n".' |||
![]() | ';
$str .= "\n".' |||
![]() | ';
$str .= "\n".' |||
![]() | ';
$str .= "\n".' |||
![]() | ';
$str .= "\n".' '.$url.' | '; $str .= "\n".'![]() | ';
//-- If the button are horizontal, we put the space between two buttons.
if ($horizontal) {
$str .= "\n".' ![]() | ';
} else {
//-- If they are vertical, we end the box with a border (who block the
//-- cell).
$str .= "\n".'
![]() | ';
$str .= "\n".' ![]() | ';
$str .= "\n".' ![]() | ';
$str .= "\n".' |
![]() | ';
$str .= "\n".' |||
![]() | ';
$str .= "\n".' ![]() | ';
$str .= "\n".' ![]() | ';
}
$str .= "\n".' |
![]() | ';
}
$str .= "\n".'
'; return $str; } //============================================================================== // gs_buildControlAndPages ($db, $link, $locale, $url, $first, $max, $numItems, // $noResponse, $oneResponse, $responses, // $width, $style, $imgdir) // $db : database name // $link : database link // $locale : locale code // $url : URL to show datas, without first and max limits // $first : in the result set, the index of the first item to show // $max : max count of results by page // $numItems : results count // $noResponse : label (if no responses) // $oneResponse : label (if only one response) // $responses : label (if more than one response) // $width : table widh (if equal to zero, 100%) // $style : style used into the images control cells // $imgdir : the image set used for the control buttons // // Generation of control buttons (first, previous, next, last) and pages numbers // (search result, for example). //============================================================================== function gs_buildControlAndPages ($db, $link, $locale, $url, $first, $max, $numItems, $noResponse = null, $oneResponse = null, $responses = null, $width = null, $style = null, $imgdir = null, $appl = 'gsite') { //---------------------------------------------------------------------------- // Manage default values. if (empty ($noResponse)) $noResponse = 'ctrl_no_response'; if (empty ($oneResponse)) $oneResponse = 'ctrl_one_response'; if (empty ($responses)) $responses = 'ctrl_responses'; if (empty ($width)) $width = '100%'; if (empty ($style)) $style = 'line'; if (empty ($imgdir)) $imgdir = 'dft'; //---------------------------------------------------------------------------- // Build style. global $GS_GLOBAL; $STYLErow = $GS_GLOBAL['style_row']; $fontStyle = "font-family:$STYLErow->S_FONT_FAMILY;". "font-size:$STYLErow->S_FONT_SIZE_SMALL;". "color:$STYLErow->S_COLOR_TEXT;". "font-style:normal;". "font-weight:bold;"; $anchorStyle = ""; // "text-decoration:none;". // "color:$STYLErow->S_COLOR_TEXT;"; //---------------------------------------------------------------------------- // Get labels. $pageLabel = gs_getLabel ($db, $link, 'ctrl_page', $locale, $appl); $numresLabel0 = gs_getLabel ($db, $link, $noResponse, $locale, $appl); $numresLabel1 = gs_getLabel ($db, $link, $oneResponse, $locale, $appl); $numresLabel = gs_getLabel ($db, $link, $responses, $locale, $appl); //---------------------------------------------------------------------------- // Build labels, switch number of results. $responses = ''; if ($numItems == 0) { $responses = $numresLabel0; } else if ($numItems == 1) { $responses = $numresLabel1; } else { $responses = $numresLabel.' : '.$numItems; } //---------------------------------------------------------------------------- // Build pages count. if ($numItems > $max) { //-- More than one page. $count = $pageLabel.' :'; $pgcount = 1; //-- For all sets of items. $current = 0; $blockArray = array (); for ($i = 0; $i '.$pgcount.''); } $blockArray[$pgcount] = $tag; $pgcount++; } $firstTag = ($current - 5 > 0 ? $current - 5 : 1); $lastTag = $firstTag + 10; if ($firstTag > 1) $count .= ' ... '; while (list ($k, $v) = each ($blockArray)) { if (($k >= $firstTag) && ($k '; $str .= "\n".'
';
$str .= "\n".' ';
return $str;
}
//==============================================================================
// gs_buildControl ($url, $first, $max, $numItems, $style = 'line', $imgdir = 'dft')
// $url : URL to show datas, without first and max limits
// $first : in the result set, the index of the first item to show
// $max : max count of results by page
// $numItems : results count
// $style : style used into the images control cells
// $imgdir : the image set used for the control buttons
//
// Generation of control buttons (first, previous, next, last) for search
// result, for example.
//==============================================================================
function gs_buildControl ($url,
$first, $max, $numItems,
$style = 'line',
$imgdir = 'dft') {
//----------------------------------------------------------------------------
// Compute index of last set.
if ($numItems == 0) {
$last = 0;
} else {
$last = ($numItems % $max == 0 ?
((int)($numItems / $max) - 1) * $max :
((int)($numItems / $max)) * $max);
}
//----------------------------------------------------------------------------
// Build infos for gs_control.
$ctrlParam = array (
'style' => $style,
'imgdir' => $imgdir,
'begin' => $url.'&first=0&max='.$max,
'last' => $url.'&first='.$last.'&max='.$max
);
if ($first > 0) {
$ctrlParam['prev'] = $url.'&first='.($first - $max).'&max='.$max;
}
if ($first + $max ';
$prevImg = '';
$nextImg = '
';
$lastImg = '
';
$style = (empty ($param['style']) ? '' : ' class="'.$param['style'].'"');
$beginImg = (empty ($param['begin']) ? $beginImg : ''.$beginImg.'');
$prevImg = (empty ($param['prev']) ? $prevImg : ''.$prevImg.'');
$nextImg = (empty ($param['next']) ? $nextImg : ''.$nextImg.'');
$lastImg = (empty ($param['last']) ? $lastImg : ''.$lastImg.'');
$str = '';
$str .= "\n".'
'.$beginImg.' | '; $str .= "\n".''.$prevImg.' | '; $str .= "\n".''.$nextImg.' | '; $str .= "\n".''.$lastImg.' | '; $str .= "\n".'
'; return $str; } //============================================================================== // gs_buildOptionInVar ($db, $link, $query, $current, $valueFieldName, $labelFieldName, $locale, $appl, $isLabel) // $db : database name // $link : database link // $query : query to perform // $current : current expected value of the select (option SELECTED) // $valueFieldName : in the query, the field name of the value // $labelFieldName : in the query, the field name of the text // $locale : current locale, in case of labelled text // $name : name of application, for labels // $isLabel : true if $labelFieldName field is a label name. // // According to the result of the query $query, build SELECT options. The result // is a string. //============================================================================== function gs_buildOptionInVar ($db, $link, $query, $current, $valueFieldName, $labelFieldName, $locale = '', $appl= '', $isLabel = false) { //---------------------------------------------------------------------------- // Perform query. $res = mysql_query ($query, $link); if (! $res) { die ("Unable to perform query ($query / " . mysql_error ($link) . ")"); } //---------------------------------------------------------------------------- // Build options. $str = ''; while ($row = mysql_fetch_array ($res)) { //-- Option label. If $isLabel is true, the field named $labelFieldName is //-- used as a label. Otherwise, it's only a string. $label = ($isLabel ? gs_getLabel ($db, $link, $row[$labelFieldName], $locale, $appl) : htmlentities ($row[$labelFieldName])); //-- The value: field $valueFieldName of the result set. $value = $row[$valueFieldName]; //-- If the value if equal to $current, this option is selected. $selected = ($current == $value ? ' selected' : ''); //-- Build option. $str .= "\n".''; } mysql_free_result ($res); return $str; } //============================================================================== // gs_localePutLanguagesFlagsInVar ($dbname, $dblink, $project) // $dbname : database name // $dblink : database link // $project : project name // // Dump array of flags, one for each language supported by the project. // Images are taken from Local/flags directory. //============================================================================== function gs_localePutLanguagesFlagsInVar ($dbname, $dblink, $project) { //---------------------------------------------------------------------------- // List of all the languages supported by project. $query = "select * from $dbname.LOCALE, $dbname.LOCALE_PRJ". " where LP_PROJECT='$project' and LP_CODE=L_CODE". " order by LP_ORDER"; $result = mysql_query ($query, $dblink); if (! $result) { die ("Unable to perform query (" . mysql_error ($dblink) . ")"); } //---------------------------------------------------------------------------- // Only one language ? Do nothing. if (mysql_num_rows ($result) '; $outputText .= "\n".'
';
$outputText .= "\n".'';
mysql_free_result ($result);
return $outputText;
}
//==============================================================================
// FUNCTION gs_putAmount ($frf, $euro)
//
// Convert an amount into euro.
//
// NOTE: must be move into project module.
//==============================================================================
function gs_putAmount ($frf, $euro) {
if ($euro == 0) {
$euro = $frf / 6.55957;
$euro = (round ($euro * 100)) / 100;
}
if ($euro == 0) return ' ';
if ($euro >= 150000) return 'A ( >= 150 000 € )';
if ($euro >= 45000) return 'B ( = 45 000 € )';
if ($euro >= 15000) return 'C ( = 15 000 € )';
return 'D ( '."\n";
if (file_exists ($incFiles[$i])) {
include ($incFiles[$i]);
return;
}
}
die ("$msg
\nSearch path:
\n$searchPath");
}
//==============================================================================
// FUNCTION gs_getUser ($db, $link, $annu, $userid)
//
// Returns an array with user informations.
//==============================================================================
function gs_getUser ($db, $link, $annu, $userid) {
$query =
"select * from $db.annu_USERS".
" where U_ID=$userid".
" and U_ANNU_NAME='$annu'";
$result = mysql_query ($query, $link);
if (! $result) {
die ("Unable to perform query ($query / " . mysql_error ($link) . ")");
}
$row = mysql_fetch_object ($result);
if (! $row) return false;
$userInfo['login'] = $row->U_LOGIN;
$userInfo['name'] = $row->U_NAME;
$userInfo['surname'] = $row->U_SURNAME;
$userInfo['row'] = $row;
mysql_free_result ($result);
return $userInfo;
}
//==============================================================================
// FUNCTION gs_tabStyles ($STYLErow)
//
// Default styles for tab generation.
//==============================================================================
function gs_tabStyles ($STYLErow) {
$text = '';
$text .= ".tabBackground {\n";
$text .= " background-color: $STYLErow->S_COLOR_1;\n";
$text .= "}\n";
$text .= ".tabActive {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " text-align: left;\n";
$text .= " vertical-align: top;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_7;\n";
$text .= "}\n";
$text .= ".tabInactive {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " text-align: left;\n";
$text .= " vertical-align: top;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_4;\n";
$text .= "}\n";
$text .= ".tabInactiveAnchor {\n";
$text .= " text-decoration : none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT_INVERSE;\n";
$text .= "}\n";
return $text;
}
//==============================================================================
// FUNCTION gs_styles ($STYLErow)
//
// Default styles.
//==============================================================================
function gs_styles ($STYLErow) {
$text = '';
//-- Line.
$text .= ".line {\n";
$text .= " background-color: $STYLErow->S_COLOR_2;\n";
$text .= "}\n";
//-- Anchor.
$text .= ".anchor {\n";
$text .= " text-decoration : none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= "}\n";
$text .= ".anchorAnim {\n";
$text .= " text-decoration : none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= "}\n";
$text .= ".anchorAnim:hover { color: red }\n";
//-- Text.
$text .= ".basicText {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= "}\n";
$text .= ".text {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_3;\n";
$text .= "}\n";
$text .= ".textJustify {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " text-align: justify;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_3;\n";
$text .= "}\n";
$text .= ".text1 {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_5;\n";
$text .= "}\n";
$text .= "\n";
$text .= ".text2 {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_6;\n";
$text .= "}\n";
$text .= "\n";
$text .= ".dump {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= "}\n";
$text .= ".bold {\n";
$text .= " font-weight: bold;\n";
$text .= "}\n";
$text .= ".italic {\n";
$text .= " font-style: italic;\n";
$text .= "}\n";
//-- Titles.
$text .= ".title {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " text-decoration: none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_3;\n";
$text .= "}\n";
$text .= ".title1 {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " text-decoration: none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_5;\n";
$text .= "}\n";
$text .= ".title2 {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " text-decoration: none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_6;\n";
$text .= "}\n";
$text .= ".titleBig {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_BIG;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " text-decoration: none;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_3;\n";
$text .= "}\n";
//-- Inputs.
$text .= ".formLabel {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_5;\n";
$text .= "}\n";
$text .= "\n";
$text .= ".formLabelMandatory {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: italic;\n";
$text .= " font-weight: bold;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_5;\n";
$text .= "}\n";
$text .= "\n";
$text .= ".formInput {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: normal;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_6;\n";
$text .= "}\n";
$text .= "\n";
//-- Error.
$text .= ".error {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_BIG;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT_ALERT;\n";
$text .= " background-color: $STYLErow->S_COLOR_3;\n";
$text .= "}\n";
//-- Buttons.
$text .= ".btActive {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " text-align: center;\n";
$text .= " vertical-align: middle;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_1;\n";
$text .= "}\n";
$text .= ".btInactive {\n";
$text .= " font-family: $STYLErow->S_FONT_FAMILY;\n";
$text .= " font-size: $STYLErow->S_FONT_SIZE_SMALL;\n";
$text .= " font-style: normal;\n";
$text .= " font-weight: bold;\n";
$text .= " text-align: center;\n";
$text .= " vertical-align: middle;\n";
$text .= " color: $STYLErow->S_COLOR_TEXT;\n";
$text .= " background-color: $STYLErow->S_COLOR_3;\n";
$text .= "}\n";
return $text;
}
//==============================================================================
//==============================================================================
function gs_getDocumentAndPage ($doc, $pagendx, $page) {
//----------------------------------------------------------------------------
// Tags.
global $GS_GLOBAL;
//----------------------------------------------------------------------------
// Global variables.
$db = $GS_GLOBAL['mysql_db'];
$project = $GS_GLOBAL['project'];
$locale = $GS_GLOBAL['locale'];
//----------------------------------------------------------------------------
// Looking for document.
$query =
"select * from $db.DOCUMENT, $db.annu_USERS".
" where D_NAME='$doc'".
" and D_PROJECT='$project'".
" and D_LOCALE='$locale'".
" and D_AUTHOR_ID=U_ID";
$DOCresult = mysql_query ($query, $GS_GLOBAL['link']);
if (! $DOCresult) {
die ("Unable to perform query ($query / " . mysql_error ($GS_GLOBAL['link']) . ")");
}
if (mysql_num_rows ($DOCresult) == 0) {
die ("Unknown document (name=$doc, locale=$locale)");
}
if (mysql_num_rows ($DOCresult) > 1) {
die ("Too much documents ($doc)");
}
$GS_GLOBAL['document_row'] = mysql_fetch_object ($DOCresult);
mysql_free_result ($DOCresult);
//----------------------------------------------------------------------------
// Looking for pages associated to document.
$docIndex = $GS_GLOBAL['document_row']->D_INDEX;
$query =
"select * from $db.PAGE".
" where P_DOCUMENT=$docIndex".
" order by P_ORDER";
$GS_GLOBAL['pages_result'] = mysql_query ($query, $GS_GLOBAL['link']);
if (! $GS_GLOBAL['pages_result']) {
die ("Unable to perform query ($query / " . mysql_error ($GS_GLOBAL['link']) . ")");
}
//----------------------------------------------------------------------------
// Find application.
if (mysql_num_rows ($GS_GLOBAL['pages_result']) == 0) {
//--------------------------------------------------------------------------
// No page: assuming this is a txt application.
$GS_GLOBAL['no_page'] = true;
$GS_GLOBAL['current_page_ndx'] = 0;
$GS_GLOBAL['current_page_row'] = null;
$GS_GLOBAL['application'] = 'txt';
} else {
//--------------------------------------------------------------------------
// There is at least one page. We try to find the current page.
// If $page is set, we use P_ORDER.
// If $pagendx is set, we use P_INDEX.
//
// If nothing is set, or if we can't get a page, we'll use the first one.
mysql_data_seek ($GS_GLOBAL['pages_result'], 0);
$row = mysql_fetch_object ($GS_GLOBAL['pages_result']);
$GS_GLOBAL['no_page'] = false;
$GS_GLOBAL['current_page_ndx'] = $row->P_ORDER;
$GS_GLOBAL['current_page_row'] = $row;
//--------------------------------------------------------------------------
// We perform the search.
mysql_data_seek ($GS_GLOBAL['pages_result'], 0);
if (! empty ($pagendx)) {
//------------------------------------------------------------------------
// We use $pagendx.
while ($row = mysql_fetch_object ($GS_GLOBAL['pages_result'])) {
if ($pagendx == $row->P_INDEX) {
//--------------------------------------------------------------------
// We found the current page.
$GS_GLOBAL['current_page_ndx'] = $row->P_ORDER;
$GS_GLOBAL['current_page_row'] = $row;
break;
}
}
} else if (! empty ($page)) {
//------------------------------------------------------------------------
// We use $page.
while ($row = mysql_fetch_object ($GS_GLOBAL['pages_result'])) {
if ($page == $row->P_ORDER) {
//--------------------------------------------------------------------
// We found the current page.
$GS_GLOBAL['current_page_ndx'] = $page;
$GS_GLOBAL['current_page_row'] = $row;
break;
}
}
}
//--------------------------------------------------------------------------
// In any case, we have set the tag current_page_row. So, we can set the tag
// application.
$GS_GLOBAL['application'] = ($GS_GLOBAL['current_page_row']->P_APPLICATION == ''
? 'txt'
: $GS_GLOBAL['current_page_row']->P_APPLICATION);
}
//----------------------------------------------------------------------------
// Arguments.
global $GS_PROJECT_ARGUMENTS;
global $GS_ARGUMENTS;
$args = explode (' ', $GS_GLOBAL['current_page_row']->P_ARGUMENT);
$GS_ARGUMENTS['cache'] = false;
$GS_ARGUMENTS['nocache'] = false;
$GS_ARGUMENTS['cache_delay'] = $GS_PROJECT_ARGUMENTS['cache_delay'];
$GS_ARGUMENTS['cookie'] = false;
$GS_ARGUMENTS['cachectrl'] = false;
for ($i = 0; $i ';
}
}
$fct = '';
while (list ($k, $v) = each ($G_JavascriptFunctions)) {
$fct .= $v;
}
return
$files.
"\n".'';
}
//==============================================================================
// FUNCTION messageTo ($project, $locale, $to)
//
// Dump an icon to send a message.
//==============================================================================
function messageTo ($project, $locale, $to) {
$args = "'$project', '$locale', $to";
$icon = '';
return
''.
$icon.
'';
}
//==============================================================================
//==============================================================================
function gs_print ($item) {
ob_start ();
print_r ($item);
$p = ob_get_contents ();
ob_end_clean ();
echo '
'.htmlentities ($p).'
'; } //------------------------------------------------------------------------------ // $Log: common.php,v $ // Revision 1.3 2002/12/16 16:25:12 jpm // Suppression des doubles saut de ligne. // // Revision 1.2 2002/10/04 09:34:29 jpm // Suppression espace aprés balise fermeture php // // Revision 1.1.1.1 2002/10/02 07:32:21 root // initialisation site de Tela // // Revision 1.34 2002/06/25 11:06:51 lc // Add gs_print and anchorAnim // // Revision 1.33 2002/06/20 07:39:32 lc // Add cache management for labels. // Add basicText style. // // Revision 1.32 2002/06/18 13:21:12 lc // Add messageTo. // // Revision 1.31 2002/06/18 13:09:33 lc // Add title1 and title2 styles // // Revision 1.30 2002/06/18 07:19:39 lc // Add function js_registerFile // // Revision 1.29 2002/06/14 07:36:31 lc // Bug LC0021 : use js_init, js_register and js_dump // Bug LC0021 : use external js file // // Revision 1.28 2002/06/10 16:12:04 lc // Add annu and project into browser. // // Revision 1.27 2002/06/10 09:04:39 lc // Bug LC0006 : add nocache argument // Bug LC0008 : check if zlib extension is loaded // // Revision 1.26 2002/06/05 13:07:17 lc // Bug LC0002 // // Revision 1.25 2002/06/04 06:39:18 lc // Add function gs_localizeDateTime(). // // Revision 1.24 2002/05/29 13:14:26 lc // Javascript function eraseBrowserFields is now in php/common.php // // Revision 1.23 2002/05/29 06:44:52 lc // Add gs_JavascriptOpenBrowser function. // // Revision 1.22 2002/05/23 16:32:16 lc // Add gs_getDocumentAndPage. // Add isYear javascript function. // Add style formLabelMandatory. // Add openPopup javascript function. // // Revision 1.21 2002/05/23 08:32:37 lc // Show only a limited number of pages. // Comments. // // Revision 1.20 2002/05/22 09:52:09 lc // Add javascript function gs_JavascriptOpenDocumentPopup (open a popup with a document and a set). // // Revision 1.19 2002/05/15 09:48:41 lc // Add some default styles. // // Revision 1.18 2002/05/15 09:23:08 lc // Change buttons styles. // Add default styles generation. // // Revision 1.17 2002/05/14 12:42:40 lc // Modify default parameters for controls. // // Revision 1.16 2002/04/24 15:29:50 lc // Add gs_getUser. // // Revision 1.15 2002/04/19 06:46:17 lc // Add gs_JavascriptCheckFrenchZipCode (validation of french ZIP code). // // Revision 1.14 2002/04/18 14:05:38 lc // Bug: replace fr by sp... // // Revision 1.13 2002/04/10 09:28:40 lc // Add gs_localizeTimestamp. // // Revision 1.12 2002/03/07 09:23:07 lc // Add gs_includeFile (protection from URL). // // Revision 1.11 2002/02/28 18:48:39 schneid // Warnings... // // Revision 1.10 2002/02/26 13:31:25 lc // Bug in array test. // // Revision 1.9 2002/02/25 17:24:28 lc // Remove old compatibility. // // Revision 1.8 2002/02/25 16:32:56 lc // gs_localePutLanguagesFlags replaced by gs_localePutLanguagesFlagsInVar. // Compression management. // // Revision 1.7 2002/02/15 17:37:38 lc // Bas use of some variables... // // Revision 1.6 2002/02/13 17:38:26 lc // Modify project locale management. // // Revision 1.5 2002/02/08 15:52:22 lc // Add application in label table // // Revision 1.4 2002/01/15 16:00:02 lc // Add space between two buttons. // // Revision 1.3 2001/12/20 19:21:35 lc // Add table LABELS in comments. // // Revision 1.2 2001/12/17 20:16:40 lc // Error in comment. // // Revision 1.1 2001/12/17 20:15:03 lc // Initial version. // //-- End of source ------------------------------------------------------------ ?> //------------------------------------------------------------------------------ // FICHIER : $RCSfile: session.php,v $ // AUTEUR : $Author: root $ // VERSION : $Revision: 1.1.1.1 $ // DATE : $Date: 2002/10/02 07:32:21 $ //------------------------------------------------------------------------------ // GSite - Web site management in PHP - session management // // Copyright (C) 2001 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 //------------------------------------------------------------------------------ // Manage session with cookies. // Each page must call gs_sessionStart (bd.php do it). // If a cookie (gsite_$project) is set and if this cookie value is correct, the // lifetime of this cookie and the matching row in SESSIOn table are updated. // If no cookies are set, a new one is created, and a new row is inserted in // SESSION table. // // If the user's navigator doesn't manage cookies, we have a BIG problem... The // solution can be to manage a session ID on the URL, but *ALL* the URLs must // propagate this session ID... //------------------------------------------------------------------------------ // Database table : /* CREATE TABLE SESSION ( S_PROJECT varchar(16) NOT NULL default '', S_ID varchar(128) NOT NULL default '', S_ADDR_IP varchar(32) NOT NULL default '', S_BEGIN datetime NOT NULL default '0000-00-00 00:00:00', S_END datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (S_ID) ); */ //------------------------------------------------------------------------------ //============================================================================== // string gs_sessionCookieValue () // // Build an unique ID (with uniqid, encoded with MD5), usable as cookie value. //============================================================================== function gs_sessionCookieValue () { return md5 (uniqid (rand ())); } //============================================================================== // gs_sessionSetCookie ($cookieName, $cookieValue, $delay) // $cookieName : name of cookie // $cookieValue : value of cookie // $delay : cookie lifetime (in seconds) // // Set cookie. This function must be call before any output ! //============================================================================== function gs_sessionSetCookie ($cookieName, $cookieValue, $delay) { setcookie ($cookieName, $cookieValue, time () + $delay, '/'); } //============================================================================== // gs_sessionCleanupBdd ($dbname, $dblink, $project) // $dbname : current database // $dblink : MySQL link // $project : current project // // Delete from table SESSION (and for project $project) expired rows. //============================================================================== function gs_sessionCleanupBdd ($dbname, $dblink, $project) { $query = "delete from $dbname.SESSION where S_PROJECT='$project' and S_END NOW()"; global $GS_PROJECT_ARGUMENTS; if ($GS_PROJECT_ARGUMENTS['verify_ip']) { global $REMOTE_ADDR; $query .= " and S_ADDR_IP='$REMOTE_ADDR'"; } $result = mysql_query ($query, $dblink); if (! $result) { die ("Unable to perform query ($query / " . mysql_error ($dblink) . ")"); } $existInBDD = (mysql_num_rows ($result) == 1); mysql_free_result ($result); return $existInBDD; } //============================================================================== // string gs_sessionStart ($dbname, $dblink, $project, $delay = 3600, $cleanup = false) // $dbname : current database // $dblink : MySQL link // $project : current project // $delay : connexion lifetime (in seconds) // $cleanup : delete expired rows // // Start a new session. This function returns a session ID. //============================================================================== function gs_sessionStart ($dbname, $dblink, $project, $delay = 3600, $cleanup = false) { //---------------------------------------------------------------------------- // The cookie name is 'gsite_$project'. $cookieName = "gsite_$project"; global $$cookieName; $cookieValue = (isset ($$cookieName) ? $$cookieName : ''); //---------------------------------------------------------------------------- // Cleanup database. // Cleanup BDD is a way to reduce BDD size. But, if we store all the data, we // can perform a lot of statistics... if ($cleanup) gs_sessionCleanupBdd ($dbname, $dblink, $project); //---------------------------------------------------------------------------- // The right cookie is set ? if ($cookieValue != '') { //-------------------------------------------------------------------------- // We have a session cookie. Is it valid ? if (gs_sessionBddValidateCookie ($dbname, $dblink, $project, $cookieValue, $delay)) { //------------------------------------------------------------------------ // Update database (new END date). gs_sessionBddUpdate ($dbname, $dblink, $cookieValue, $delay); //------------------------------------------------------------------------ // Update cookie (new END date). gs_sessionSetCookie ($cookieName, $cookieValue, $delay); return $cookieValue; } } //---------------------------------------------------------------------------- // No cookie session, or invalid cookie. We build a new one. $cookieValue = gs_sessionCookieValue (); //---------------------------------------------------------------------------- // Adding new session in database. gs_sessionBddAdd ($dbname, $dblink, $project, $cookieValue, $delay); //---------------------------------------------------------------------------- // Setting cookie. gs_sessionSetCookie ($cookieName, $cookieValue, $delay); //---------------------------------------------------------------------------- // Returning cookie value as session ID. return $cookieValue; } //============================================================================== // int gs_sessionCountVisits ($dbname, $dblink, $project) // $dbname : current database // $dblink : MySQL link // $project : current project // // Count access for a project. //============================================================================== function gs_sessionCountVisits ($dbname, $dblink, $project) { $query = "select COUNT(S_ID) as TOTAL". " from $dbname.SESSION". " where S_PROJECT='$project'"; $result = mysql_query ($query, $dblink); if (! $result) { die ("Unable to perform query ($query / " . mysql_error ($dblink) . ")"); } $row = mysql_fetch_object ($result); $total = (! $row ? 0 : $row->TOTAL); mysql_free_result ($result); return $total; } //------------------------------------------------------------------------------ // $Log: session.php,v $ // Revision 1.1.1.1 2002/10/02 07:32:21 root // initialisation site de Tela // // Revision 1.3 2002/03/18 10:46:19 lc // Check IP address, or not. // // Revision 1.2 2002/02/25 16:32:06 lc // echo replaced by die. // // Revision 1.1 2002/01/14 10:27:50 lc // Initial version. // //-- End of source ------------------------------------------------------------ ?>