/includes/cphplib/cphplib.inc
PHP | 4203 lines | 2890 code | 416 blank | 897 comment | 823 complexity | d5ef5cee4ea951782ea3e7aceb14e341 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * cphplib is a PHP-functions library. Those could simply be integrated into existing PHP-Scripts and allow an easy use.
- * These functions are very flexible to use because they are kept very common.
- *
- * PHP versions 4 and 5
- *
- * @category Utilities
- * @package cphplib
- * @author Alexander Meindl <am@meindlsoft.com>
- * @author Sven Reul <heffer@quaddamage.de>
- * @copyright (c) 2002-2005 meindlSOFT
- * @license Released under v2 of the GNU LGPL
- * @version Version 0.50 CVS: $Id: cphplib.inc,v 1.20 2005/11/11 09:12:25 alex Exp $
- * @link http://www.meindlsoft.com/tools.php
- */
- /**
- * Replacement for useless PHP empty function
- * Returns true, if string is empty
- *
- * @param string $str string to validate
- * @param bool $mode true for compatible with echo {default: false}
- * @return bool
- */
- function isvoid($str, $mode=false)
- {
- $rc = false;
- if (is_array($str))
- {
- if (count($str)==0)
- {
- $rc = true;
- }
- }
- else
- {
- $str = trim($str);
- if (strlen($str)==0)
- {
- $rc = true;
- }
- else if (($mode) && ($str=="0"))
- {
- $rc = true;
- }
- }
- return $rc;
- }
- /**
- * cphplib class
- */
- class cphplib
- {
- /**
- * cphplib version
- *
- * @var float
- */
- var $version = "0.50";
- /**
- * Error level
- * 0: show no error message
- * 1: only print message
- * 2: die, if error occurres
- * 3: user defined function (callback) => error_user_function required
- *
- * @var int
- */
- var $error_level = 2;
- /**
- * User defined function
- *
- * Required for error_level=3
- *
- * @var mixed
- */
- var $error_user_function;
- /**
- * Date format
- *
- * I = International date identifier (MM/DD/YYYY)
- * S = Science date identifier (YYYY-MM-DD)
- * C = Date without seperators (YYYYMMDD)
- * L = German date identifier (DD.MM.YYYY)
- *
- * @var char
- */
- var $date_format;
- /**
- * Time format
- *
- * Y = 24 hours mode
- * N = 12 hours mode
- *
- * @var char
- */
- var $time_format;
- /**
- * locale to use (see "man locale")
- *
- * @var string
- */
- var $locale;
- /**
- * xhtml output
- *
- * @var bool
- */
- var $xhtml = true;
- /**
- * Max. entries on one page of a list
- *
- * @var int
- */
- var $page_entries = 20;
- /**
- * Type of database
- *
- * @var string
- */
- var $db_type;
- /**
- * Database pear object
- * (mysql or pgsql)
- *
- * @var resource
- */
- var $db;
- /**
- * like not case sensitive for SQL
- *
- * @var resource
- */
- var $sql_like;
- /**
- * International seperator
- *
- * @var char
- */
- var $m_sep_i = "/";
- /**
- * Science seperator
- *
- * @var char
- */
- var $m_sep_s = "-";
- /**
- * German seperator
- *
- * @var char
- */
- var $m_sep_l = ".";
- /**
- * Image URL to all images
- *
- * @var string
- */
- var $image_url = "images";
- // db session variables
- var $m_dbsession_handler = false; // must be true for handling session_id
- var $m_dbsession_id = ""; // dbsession ID
- var $m_dbsession_id_name = "SID"; // dbsession ID name
- var $m_dbsession_table = "dbsession"; // table name for dbsession use
- var $m_dbsession_detail_table = "dbsession_detail"; // table name for dbsession use
- var $m_dbsession_timeout = 60; // dbsession timeout
- /**
- * cookies can be used for dbsession
- *
- * @var bool
- */
- var $m_dbsession_cookies = false;
- /**
- * take special care for mod_rewrite
- *
- * at the moment only url() is supported
- *
- * @var bool
- */
- var $mod_rewrite = false;
- /**
- * constructor
- *
- * @param string $locale if no empty, locale and string will be initialised
- * @return cphplib
- */
- function cphplib($locale="de_DE")
- {
- if (!empty($locale))
- {
- $this->locale = $locale;
- $this->set_locale();
- $this->set_strings();
- }
- }
- /**
- * Set locale
- *
- */
- function set_locale()
- {
- if ($this->locale=="de_DE")
- {
- $this->date_format = "L";
- $this->time_format = "Y";
- if ($this->check_php_version("4.3.0"))
- {
- setlocale(LC_TIME, 'de_DE@euro', 'de_DE', 'german', 'deu');
- setlocale(LC_CTYPE, 'de_DE@euro', 'de_DE', 'german', 'deu');
- }
- else if ($this->os_type(true) == "w")
- {
- setlocale(LC_TIME, 'german');
- setlocale(LC_CTYPE, 'german');
- }
- else
- {
- setlocale(LC_TIME, 'de_DE');
- setlocale(LC_CTYPE, 'de_DE');
- }
- }
- else
- {
- $this->set_format("I", "N");
- setlocale(LC_TIME, $this->locale);
- setlocale(LC_CTYPE, $this->locale);
- }
- }
- /**
- * Set date and time format to cphplib
- *
- * @param char $date_format see $this->date_format for valid values
- * @param char $time_format see $this->time_format for valid values
- */
- function set_format($date_format, $time_format)
- {
- $this->date_format = $date_format;
- $this->time_format = $time_format;
- }
- /**
- * Set strings for pager and Date methods
- *
- */
- function set_strings()
- {
- if (substr($this->locale, 0, 2) =="de")
- {
- include_once("i18n/german.inc");
- }
- else
- {
- include_once("i18n/english.inc");
- }
- }
- /**
- * Opens a connection to a database server and select database
- * Furthermore it sets $this->db to the PEAR database object,
- * which is required for dbsession
- *
- * @param string $dsn Data Source Name ( for more information see PEAR documentation)
- * addon array key:
- * persistent = true for persistent {default: false}
- * @param bool $set_db if true, db object will be set to $this->db
- * (and db_tyle and sql_like, too)
- * @return object PEAR database object
- */
- function db_connect($dsn, $set_db=true)
- {
- if ($this->file_exists("DB.php"))
- {
- if ((!isvoid($dsn['phptype'])) && (!(extension_loaded($dsn['phptype']))))
- {
- $this->show_error("db_connect", "PHP database module "".$dsn['phptype']."" is not supported by your system.");
- }
- require_once("DB.php");
- }
- else
- {
- $this->show_error("db_connect", "Pear \"DB Package\" required.");
- }
- if ($dsn['persistent']) $db =& DB::connect($dsn, true);
- else $db =& DB::connect($dsn ,false);
- if (DB::isError($db))
- {
- $this->show_error("db_connect", $db->getMessage(), $db->getCode());
- }
- if ($set_db)
- {
- $this->db =& $db;
- if ($dsn['phptype']=="mysqli") $this->db_type = "mysql";
- else $this->db_type = $dsn['phptype'];
- if ($dsn['phptype']=="pgsql") $this->sql_like = "ILIKE";
- else $this->sql_like = "LIKE";
- }
- return $db;
- }
- /**
- * disconnect current database connection
- * (change $this->db for select the right one, if you
- * use more the one connection)
- *
- * @return bool true if no errors occurred, otherwise false
- */
- function db_close()
- {
- if (DB::isError($this->db))
- {
- $this->show_error("db_close", $this->db->getMessage());
- }
- return @ $this->db->disconnect();
- }
- /**
- * Get the id generated from the previous INSERT operation
- *
- * @return int
- */
- function db_insert_id()
- {
- if (DB::isError($this->db))
- {
- $this->show_error("db_insert_id", $this->db->getMessage());
- }
- $rc = $this->db->getOne("SELECT last_insert_id()");
- if (DB::isError($rc))
- {
- $this->show_error("db_insert_id", $rc->getMessage());
- }
- return $rc;
- }
- /**
- * Get next available number
- *
- * @param string $table database table to use
- * @param string $column database column to use
- * @param string $where SQL WHERE restriction, e.g. "thisvalue>0"
- * (without "WHERE" in string!)
- * @return int highst number in column + 1
- */
- function db_next_id($table, $column, $where=null)
- {
- if (DB::isError($this->db))
- {
- $this->show_error("db_next_id", $this->db->getMessage());
- }
- $sqlstr = "SELECT MAX($column)+1 FROM $table";
- if (isset($where)) $sqlstr .= " WHERE ".$where;
- $tmp_id = $this->db->getOne($sqlstr);
- if (DB::isError($tmp_id))
- {
- $this->show_error("db_next_id", $tmp_id->getMessage());
- }
- if (empty($tmp_id))
- {
- return 1;
- }
- else
- {
- return $tmp_id;
- }
- }
- /**
- * Get next available number
- *
- * @param string $seq_name name of sequence
- * @return int
- */
- function db_seq_id($seq_name)
- {
- if (DB::isError($this->db))
- {
- $this->show_error("db_seq_id", $this->db->getMessage());
- }
- else if (isvoid($seq_name))
- {
- $this->show_error("db_seq_id", "seq_name is missing");
- }
- else if (!is_object($this->db))
- {
- $this->show_error("db_seq_id", "\$this->db is not an database object");
- }
- $tmp_id = $this->db->nextId($seq_name);
- if (DB::isError($tmp_id))
- {
- $this->show_error("db_seq_id", $tmp_id->getMessage());
- }
- if (empty($tmp_id)) return 1;
- else return $tmp_id;
- }
- /**
- * Get number of lowest unused number in a column)
- *
- * @param string $table database table to use
- * @param string $column database column to use
- * @param string $where_key database column name for limitation {default: void}
- * @param string $where_value limitation value {default: void}
- * @return int lowest unused number in a column
- */
- function db_free_id($table, $column, $where_key="", $where_value="")
- {
- if (DB::isError($this->db))
- {
- $this->show_error("db_free_id", $this->db->getMessage());
- }
- $rc=0;
- if ((isvoid($where_key)) && (isvoid($where_value)))
- $sqlstr = "SELECT $column FROM $table ORDER BY $column";
- else if ((!isvoid($where_key)) && (!isvoid($where_value)))
- $sqlstr = "SELECT $column FROM $table WHERE $where_key='$where_value' ORDER BY $column";
- if (!isvoid($sqlstr))
- {
- $que = $this->db->query($sqlstr);
- if ($que->numRows()>0)
- {
- $count=1;
- while ($row = $que->fetchRow())
- {
- $tmp_id = $row[0];
- if ($count==$tmp_id)
- $count++;
- else
- {
- $rc = $count;
- break;
- }
- }
- if ($rc==0)
- $rc=$count;
- }
- else
- $rc=1;
- }
- return $rc;
- }
- /**
- * check right database version
- *
- * @param float $mav major release number {default: 3.23}
- * @param float $miv minor release number {default: 6}
- * @return string active database version, if false empty
- */
- function db_version($mav="3.23", $miv="6")
- {
- if (DB::isError($this->db))
- {
- $this->show_error("db_version", $this->db->getMessage());
- }
- $rc = "unknown";
- if (($this->db_type)=="mysql")
- {
- if ($this->db->phptype=="mysqli") $tmp_rc = mysqli_get_server_info($this->db->connection);
- else $tmp_rc = mysql_get_server_info();
- $t_mav1 = strtok($tmp_rc,'.');
- $t_mav2 = strtok('.');
- $t_miv = strtok('.');
- $t_mav = $t_mav1.".".$t_mav2;
- if ($t_mav > $mav) $rc = "MySQL ".$tmp_rc;
- else if (($t_mav == $mav) && (intval($t_miv) >= $miv)) $rc = "MySQL ".$tmp_rc;
- else
- {
- $this->show_error("db_version", "MySQL version to old (version $mav.$miv or higher required), <b>program aborted</b>.");
- }
- }
- else
- {
- $tmp_rc = $this->db->getOne("SELECT version()");
- if (!isvoid($tmp_rc))
- {
- $rc = substr($tmp_rc,0,strpos($tmp_rc," on"));
- if (isvoid($rc)) $rc = $tmp_rc; // just to be sure
- }
- }
- return $rc;
- }
- /**
- * starts dbsession. Enables session fallback handling. This functions
- * will be required, if you want to handle the session_id with
- * url or formstart
- * Required : read README file
- *
- * @param string $session_id session id to use, if empty new unique id
- * will be generated
- * @param bool $table_error show error message, if dbsession tables doesn't exist
- * @return string session_id
- */
- function dbsession_start($session_id="", $table_error=true)
- {
- global $HTTP_COOKIE_VARS;
- $this->m_dbsession_handler=true;
- $IDpassed = false;
- if (DB::isError($this->db))
- {
- $this->show_error("dbsession_start", $this->db->getMessage());
- }
- else
- {
- $tdata = $this->db->getListOf("tables");
- if ((!in_array($this->m_dbsession_table,$tdata)) || (!in_array($this->m_dbsession_detail_table,$tdata)))
- $dbtables_found = false;
- else
- $dbtables_found = true;
- if ((!$dbtables_found) && ($table_error))
- {
- $this->show_error("dbsession_start", "missing dbsession database table");
- }
- }
- if (empty($session_id)) $SID = $this->get_user_var($this->m_dbsession_id_name,'POST,GET,COOKIE');
- else $SID = $session_id;
- // generate session_is
- $session_is = $this->get_id_string(false);
- // validate session_id
- if ((!empty($SID)) && (strlen($SID)==32) && ($dbtables_found))
- {
- $t_sec = date("s");
- $t_min = date("i");
- $t_hours = date("H");
- $t_day = date("d");
- $t_month = date("m");
- $t_year = date("Y");
- $session_start = $t_year."-".$t_month."-".$t_day." ".$t_hours.":".$t_min.":".$t_sec;
- $stempel = mktime($t_hours,($t_min+$this->m_dbsession_timeout),$t_sec,$t_month,$t_day,$t_year);
- $faellig = getdate($stempel);
- $session_end = $faellig['year']."-".$faellig['mon']."-".$faellig['mday']." ".$faellig['hours'].":".$faellig['minutes'].":".$faellig['seconds'];
- $sqlstr = "SELECT COUNT(*) FROM ".$this->m_dbsession_table." WHERE session_id='$SID'";
- if ($this->db->getOne($sqlstr)>0)
- {
- $sqlstr = "SELECT session_is,session_end FROM ".$this->m_dbsession_table." WHERE session_id='$SID'";
- $sdata = $this->db->getRow($sqlstr,DB_FETCHMODE_ASSOC);
- if (!empty($sdata['session_end']))
- {
- $tmp_stamp_db = $this->convtoTimestamp($sdata['session_end'],'datetime');
- $tmp_stamp_now = $this->convtoTimestamp();
- if (($sdata['session_is']==$session_is) && ($tmp_stamp_db > $tmp_stamp_now))
- {
- $sqlstr = "UPDATE ".$this->m_dbsession_table." SET session_end=".$this->sql_value($session_end);
- $sqlstr .= " WHERE session_id='$SID'";
- $this->db->query($sqlstr);
- $IDpassed = true;
- }
- else
- $this->dbsession_end($SID);
- }
- }
- else
- {
- $sqlstr = "INSERT INTO ".$this->m_dbsession_table." (session_id,session_start,session_end,session_is)";
- $sqlstr .= " VALUES ('$SID',";
- $sqlstr .= $this->sql_value($session_start).",";
- $sqlstr .= $this->sql_value($session_end).",";
- $sqlstr .= $this->sql_value($session_is) .")";
- $this->db->query($sqlstr);
- $IDpassed = true;
- }
- }
- // calculate new SID and session_is
- if (!$IDpassed) $SID = $this->get_id_string(true);
- $this->m_dbsession_id = $SID;
- setcookie($this->m_dbsession_id_name, $this->m_dbsession_id,0,"/");
- if ((!$IDpassed) && ($dbtables_found)) // no valid session_id in url found
- {
- $tmp_script_name = $_SERVER['SCRIPT_NAME'];
- $tmp_server_name = $_SERVER['SERVER_NAME'];
- $tmp_server_port = $_SERVER['SERVER_PORT'];
- $tmp_query_string = $_SERVER['QUERY_STRING'];
- $query = $tmp_query_string != ""
- ? "?".$tmp_query_string
- : "";
- $url = $tmp_script_name.$query;
- // non-standard port?
- $portMatch = array();
- $port = !preg_match("/^(80|443)$/", $tmp_server_port, $portMatch)
- ? ":".$tmp_server_port
- : "";
- $new_location = (($portMatch[1] == 443) ? "https://" : "http://");
- $new_location .= $tmp_server_name.$port.$this->url($url,"",2);
- // redirect
- header("Location: $new_location");
- exit;
- }
- $this->m_dbsession_cookies = (isset($_COOKIE[$this->m_dbsession_id_name]) && @strlen($_COOKIE[$this->m_dbsession_id_name]) == 32);
- return $SID;
- }
- /**
- * starts sub session within a session. You can use it to group the session
- * in different parts
- * Required : read README file
- *
- * @param string $session_id session id to use (main session)
- * @param string $session_subid session_subid. If empty new unique id
- * will be generated if required
- * @return string session_subid
- */
- function dbsessionsub_start($session_id, $session_subid="")
- {
- if (DB::isError($this->db))
- {
- $this->show_error("dbsessionsub_start", $this->db->getMessage());
- }
- $sqlstr = "SELECT COUNT(*) FROM ".$this->m_dbsession_table." WHERE session_id='$session_id'";
- if ($this->db->getOne($sqlstr)==0)
- {
- $this->show_error("dbsessionsub_start", "invalid session_id");
- }
- // generate session_is
- $session_is = $this->get_id_string(false);
- // validate session_subid
- if ((empty($session_subid)) || (strlen($session_subid)!=32))
- $session_subid = $this->get_id_string(true);
- $t_sec = date("s");
- $t_min = date("i");
- $t_hours = date("H");
- $t_day = date("d");
- $t_month = date("m");
- $t_year = date("Y");
- $session_start = $t_year."-".$t_month."-".$t_day." ".$t_hours.":".$t_min.":".$t_sec;
- $stempel = mktime($t_hours,($t_min+$this->m_dbsession_timeout),$t_sec,$t_month,$t_day,$t_year);
- $faellig = getdate($stempel);
- $session_end = $faellig['year']."-".$faellig['mon']."-".$faellig['mday']." ".$faellig['hours'].":".$faellig['minutes'].":".$faellig['seconds'];
- $sqlstr = "SELECT COUNT(*) FROM ".$this->m_dbsession_table." WHERE session_subid='$session_subid'";
- if ($this->db->getOne($sqlstr)>0) // maybe update is overkill, but it's safer.
- {
- $sqlstr = "UPDATE ".$this->m_dbsession_table." SET session_end=".$this->sql_value($session_end);
- $sqlstr .= " WHERE session_subid='$session_subid'";
- $this->db->query($sqlstr);
- }
- else
- {
- $sqlstr = "INSERT INTO ".$this->m_dbsession_table." (session_id,session_subid,session_start,session_end,session_is)";
- $sqlstr .= " VALUES ('$session_id','$session_subid',";
- $sqlstr .= $this->sql_value($session_start).",";
- $sqlstr .= $this->sql_value($session_end).",";
- $sqlstr .= $this->sql_value($session_is) .")";
- $this->db->query($sqlstr);
- }
- return $session_subid;
- }
- /**
- * ends dbsession or dbsessionsub
- * (Read the README file for requirements)
- *
- * @param string $session_id session id which should end ( and expired dbsession will automatically be removed)
- * @return bool true if successfully end dbsession
- */
- function dbsession_end($session_id="")
- {
- if (DB::isError($this->db))
- {
- $this->show_error("dbsession_end", $this->db->getMessage());
- }
- $sqlstr = "SELECT session_id, session_subid FROM ".$this->m_dbsession_table." WHERE session_end<=NOW()";
- if (!isvoid($session_id))
- $sqlstr .= " OR session_id=".$this->sql_value($session_id)." OR session_subid=".$this->sql_value($session_id);
- @ $que = $this->db->query($sqlstr);
- @ $num = $que->numRows();
- if ($num>0)
- {
- while ($row = $que->fetchRow())
- {
- if (!empty($row[1])) // sub session
- {
- $sqlstr1 = "DELETE FROM ".$this->m_dbsession_table." WHERE session_subid=".$this->sql_value($row[1]);
- $sqlstr2 = "DELETE FROM ".$this->m_dbsession_detail_table." WHERE session_id=".$this->sql_value($row[1]);
- }
- else // session with all sub sessions
- {
- $sqlstr1 = "DELETE FROM ".$this->m_dbsession_table." WHERE session_id=".$this->sql_value($row[0]);
- $sqlstr2 = "DELETE FROM ".$this->m_dbsession_detail_table." WHERE session_id=".$this->sql_value($row[0]);
- // take care of sub sessions /////////////
- $sqlstr = "SELECT session_subid FROM ".$this->m_dbsession_table." WHERE session_id=".$this->sql_value($row[0]);
- if (!isvoid($session_id))
- @ $sub_que = $this->db->query($sqlstr);
- @ $num = $sub_que->numRows();
- if ($num>0)
- {
- while ($sub_row = $sub_que->fetchRow())
- {
- $sqlstr = "DELETE FROM ".$this->m_dbsession_detail_table." WHERE session_id=".$this->sql_value($sub_row[0]);
- @ $this->db->query($sqlstr1);
- }
- }
- //////////////////////////////////////////
- }
- @ $this->db->query($sqlstr1);
- @ $this->db->query($sqlstr2);
- }
- }
- return true;
- }
- /**
- * register variable in dbsession
- * Required : read README file
- *
- * @param string $session_id session id to use
- * @param string $var_name variable to add
- * @param mixed $var_value value of variable
- * @return string value of variable
- */
- function dbsession_write($session_id, $var_name, $var_value)
- {
- $rc = "";
- if (DB::isError($this->db))
- {
- $this->show_error("dbsession_write", $this->db->getMessage());
- }
- if ((empty($session_id)) || (empty($var_name)))
- {
- $error_string = "dbsession_write error: var_name missing";
- trigger_error($error_string, E_USER_ERROR);
- }
- else if (empty($var_value))
- {
- $this->dbsession_delete($session_id, $var_name);
- }
- else
- {
- // if already stored, delete it
- $sqlstr = "SELECT COUNT(session_id) FROM ".$this->m_dbsession_detail_table." WHERE session_id=".$this->sql_value($session_id)." AND session_var=".$this->sql_value($var_name);
- if ($this->db->getOne($sqlstr)>0) // update
- $this->dbsession_delete($session_id,$var_name);
- if (is_array($var_value))
- {
- $sqlstr = "INSERT INTO ".$this->m_dbsession_detail_table." (session_id,session_array,session_var,session_value) VALUES (".$this->sql_value($session_id).",'Y',";
- $sqlstr .= "'$var_name',".$this->sql_value(serialize($var_value)).")";
- $this->db->query($sqlstr);
- }
- else
- {
- $sqlstr = "INSERT INTO ".$this->m_dbsession_detail_table." (session_id,session_array,session_var,session_value) VALUES (".$this->sql_value($session_id).",'N',";
- $sqlstr .= $this->sql_value($var_name) .",";
- if (!isvoid($var_value)) $sqlstr .= $this->sql_value($var_value) .")";
- else $sqlstr .= "NULL)";
- $this->db->query($sqlstr);
- }
- $rc = $var_value;
- }
- return $rc;
- }
- /**
- * register variable in dbsession
- *
- * @param string $session_id session id to use
- * @param string $var_name name of variable
- * @return string value of variable
- */
- function dbsession_read($session_id, $var_name)
- {
- $rc = "";
- if (DB::isError($this->db))
- {
- $this->show_error("dbsession_read", $this->db->getMessage());
- }
- if ((empty($session_id)) || (empty($var_name)))
- {
- $error_string = "dbsession_read error: var_name missing";
- trigger_error($error_string, E_USER_ERROR);
- }
- else
- {
- $sqlstr = "SELECT session_array,session_value FROM ".$this->m_dbsession_detail_table;
- $sqlstr .= " WHERE session_id=".$this->sql_value($session_id)." AND session_var=".$this->sql_value($var_name);
- $row = $this->db->getRow($sqlstr);
- if (is_array($row))
- {
- if ($row[0]=="N") $rc = $row[1];
- else $rc = unserialize($row[1]);
- }
- }
- return $rc;
- }
- /**
- * unregister variable in dbsession
- * Required : read README file
- *
- * @param string $session_id session id which will be used for the variabel
- * @param string $var_name variable to remove
- * @return bool true if successfully removed variable
- */
- function dbsession_delete($session_id, $var_name)
- {
- if (DB::isError($this->db))
- {
- $this->show_error("dbsession_delete", $this->db->getMessage());
- }
- if ((empty($session_id)) || (empty($var_name)))
- {
- $error_string = "dbsession_delete error: var_name missing";
- trigger_error($error_string, E_USER_ERROR);
- return false;
- }
- else
- {
- $sqlstr = "DELETE FROM ".$this->m_dbsession_detail_table." WHERE session_id=".$this->sql_value($session_id)." AND session_var=".$this->sql_value($var_name);
- $this->db->query($sqlstr);
- return true;
- }
- }
- /**
- * prints url as html tag
- * (this function can only handle the session_id, if dbsession_start has
- * been called immediately after creating the class object)
- *
- * @param string $url url
- * @param string $name name of url {default: url}
- * @param int $mode 0: no session_id
- * 1: with session_id if required {default: 1}
- * 2: just url with session_id (without TAG)
- * 3: just url with session_id (without TAG), but with delimiter & instead of &
- * 4: with session_id (always)
- * @param string $title url title (hover text)
- * @param string $customize other parameters like target, style or class
- * @return string created url
- */
- function url($url, $name="", $mode=1, $title="", $customize="")
- {
- if ((($mode>0) && (!$this->m_dbsession_cookies) && (!$this->mod_rewrite))
- || ($mode==4))
- {
- if ($this->m_dbsession_handler) // if cphplib handles session fallback
- {
- // only add session_id if its on same host as script was executed (server).
- if ((($this->url_on_scripthost($url)) || ($mode==4)) &&
- (substr_count($url,"mailto:")==0))
- {
- // Anchor-Fragment extrahieren
- $dummyArray = split("#",$url);
- $pathInfo = $dummyArray[0];
- // evtl. (defekte) Session-ID(s) aus dem Querystring entfernen
- $pathInfo = preg_replace("/[?|&]".$this->m_dbsession_id_name."=[^?|&]*/","",$pathInfo);
- // evtl. Query-Delimiter korrigieren
- if (preg_match("/&/",$pathInfo) && !preg_match("/\?/",$pathInfo))
- $pathInfo = preg_replace("/&/","?",$pathInfo,1);
- // clear trash
- $match = array();
- preg_match("/(.*)(?<!&|\?)/",$pathInfo,$match);
- $url = $match[0];
- // add new session name and session id
- if (($mode==1) || ($mode==3) || ($mode==4)) $url .= preg_match("/\?/",$url) ? "&" : "?";
- else $url .= preg_match("/\?/",$url) ? "&" : "?";
- $url .= $this->m_dbsession_id_name."=".$this->m_dbsession_id;
- // add anchor part again
- $url .= isset($dummyArray[1]) ? "#".$dummyArray[1] : "";
- }
- }
- }
- if (($mode==2) || ($mode==3)) return $url;
- else
- {
- if (isvoid($name)) $name = $url;
- else $name = trim($name);
- $rc = "<a href=\"".$url."\"";
- if (!isvoid($title)) $rc .= " title=\"".$title."\"";
- if (!isvoid($customize)) $rc .= " $customize";
- $rc .= ">".$name."</a>";
- return $rc;
- }
- }
- /**
- * removes magic quotes
- *
- * @param array $array
- */
- function remove_magic_quotes(&$array)
- {
- if(!get_magic_quotes_gpc()) return;
- foreach($array as $key => $value)
- {
- if(is_array($value)) $this->remove_magic_quotes($value);
- else $array[$key] = stripslashes($value);
- }
- }
- /**
- * returns value of special variable type from user input
- * (If register_globals is Off (default since 4.2.0), this function
- * can be used, to handle user variables (insecure variables).
- * You can use more than one type (seperated with ",")
- * DBSESSION only works if dbsession_start has been called before.
- *
- * @param string $var_name name of variable
- * @param string $var_type type of variable (POST, GET, COOKIE, SCRIPT, SESSION or DBSESSION)
- * (note: SCRIPT means, declared variable above the function)
- * @return mixed value of variable or "", if invalid
- */
- function get_user_var($var_name, $var_type)
- {
- global $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_SESSION_VARS, $HTTP_COOKIE_VARS;
- $rc = "";
- $types = explode(",", $var_type);
- while (list(, $value) = each($types))
- {
- if (strtoupper($value) == "POST")
- {
- if (isset($_POST))
- {
- if ((isset($_POST[$var_name])) && (!isvoid($_POST[$var_name])))
- {
- if (get_magic_quotes_gpc())
- {
- if (is_array($_POST[$var_name]))
- {
- $this->remove_magic_quotes($_POST[$var_name]);
- return $_POST[$var_name];
- }
- else return stripslashes($_POST[$var_name]);
- }
- else return $_POST[$var_name];
- }
- }
- else
- {
- if ((isset($HTTP_POST_VARS[$var_name])) && (!isvoid($HTTP_POST_VARS[$var_name])))
- {
- if (get_magic_quotes_gpc())
- {
- if (is_array($HTTP_POST_VARS[$var_name]))
- {
- $this->remove_magic_quotes($HTTP_POST_VARS[$var_name]);
- return $HTTP_POST_VARS[$var_name];
- }
- else return stripslashes($HTTP_POST_VARS[$var_name]);
- }
- else return $HTTP_POST_VARS[$var_name];
- }
- }
- }
- else if (strtoupper($value) == "GET")
- {
- if (isset($_GET))
- {
- if ((isset($_GET[$var_name])) && (!isvoid($_GET[$var_name])))
- {
- if (get_magic_quotes_gpc())
- {
- if (is_array($_GET[$var_name]))
- {
- $this->remove_magic_quotes($_GET[$var_name]);
- return $_GET[$var_name];
- }
- else return stripslashes($_GET[$var_name]);
- }
- else return $_GET[$var_name];
- }
- }
- else
- {
- if ((isset($HTTP_GET_VARS[$var_name])) && (!isvoid($HTTP_GET_VARS[$var_name])))
- {
- if (get_magic_quotes_gpc())
- {
- if (is_array($HTTP_GET_VARS[$var_name]))
- {
- $this->remove_magic_quotes($HTTP_GET_VARS[$var_name]);
- return $HTTP_GET_VARS[$var_name];
- }
- else return stripslashes($HTTP_GET_VARS[$var_name]);
- }
- else return $HTTP_GET_VARS[$var_name];
- }
- }
- }
- else if (strtoupper($value) == "COOKIE")
- {
- if (isset($_COOKIE))
- {
- if ((isset($_COOKIE[$var_name])) && (!isvoid($_COOKIE[$var_name])))
- {
- if (get_magic_quotes_gpc())
- {
- if (is_array($_COOKIE[$var_name]))
- {
- $this->remove_magic_quotes($_COOKIE[$var_name]);
- return $_COOKIE[$var_name];
- }
- else return stripslashes($_COOKIE[$var_name]);
- }
- else return $_COOKIE[$var_name];
- }
- }
- else
- {
- if ((isset($HTTP_COOKIE_VARS[$var_name])) && (!isvoid($HTTP_COOKIE_VARS[$var_name])))
- {
- if (get_magic_quotes_gpc())
- {
- if (is_array($HTTP_COOKIE_VARS[$var_name]))
- {
- $this->remove_magic_quotes($HTTP_COOKIE_VARS[$var_name]);
- return $HTTP_COOKIE_VARS[$var_name];
- }
- else return stripslashes($HTTP_COOKIE_VARS[$var_name]);
- }
- else return $HTTP_COOKIE_VARS[$var_name];
- }
- }
- }
- else if (strtoupper($value) == "SESSION")
- {
- if (isset($_SESSION))
- {
- if ((isset($_SESSION[$var_name])) && (!isvoid($_SESSION[$var_name])))
- return $_SESSION[$var_name];
- }
- else
- {
- if ((isset($HTTP_SESSION_VARS)) && (!isvoid($HTTP_SESSION_VARS)))
- return $HTTP_SESSION_VARS[$var_name];
- }
- }
- else if ((strtoupper($value) == "DBSESSION") && ($this->m_dbsession_handler))
- {
- $SID = $this->m_dbsession_id;
- if (empty($SID))
- {
- $this->show_error("get_user_var", "dbsession_id is missing (DBSESSION)");
- }
- $tmp_rc = $this->dbsession_read($SID,$var_name);
- if (isset($tmp_rc)) return $tmp_rc;
- }
- }
- return $rc;
- }
- /**
- * search needle in multi array
- *
- * @param string $needle
- * @param array $haystack
- * @return bool
- */
- function in_multi_array($needle, $haystack)
- {
- $rc = false;
- if(is_array($haystack))
- {
- if(in_array($needle, $haystack))
- {
- $rc = true;
- }
- else
- {
- for($i = 0; $i<sizeof($haystack); $i++)
- {
- if(is_array($haystack[$i]))
- {
- if($this->in_multi_array($needle, $haystack[$i]))
- {
- $rc = true;
- break;
- }
- }
- }
- }
- }
- return $rc;
- }
- /**
- * Removes duplicate values from an array (recursive)
- * (this function is much slower than the internal php function)
- *
- * @param array $thearray array to unique
- * @return array
- */
- function array_unique(&$thearray)
- {
- sort($thearray);
- reset($thearray);
- $newarray = array();
- $i = 0;
- $element = current($thearray);
- for ($n=0;$n<sizeof($thearray);$n++)
- {
- if (next($thearray) != $element)
- {
- $newarray[$i] = $element;
- $element = current($thearray);
- $i++;
- }
- }
- return $newarray;
- }
- /**
- * sort array (subfunction for usort)
- *
- * @param array $a keys
- * @param array $b values
- * @return array
- */
- function array_sort($a, $b)
- {
- $as = strtoupper(trim($a[1]));
- $bs = strtoupper(trim($b[1]));
- $as = strtr($as, "ä", "A");
- $as = strtr($as, "ö", "O");
- $as = strtr($as, "ü", "U");
- $as = strtr($as, "ß", "S");
- $bs = strtr($bs, "Ä", "A");
- $bs = strtr($bs, "Õ", "O");
- $bs = strtr($bs, "Ü", "U");
- if ($as == $bs) return 0;
- else return ($as > $bs)?1:-1;
- }
- /**
- *reverse sort array (subfunction for usort)
- *
- * @param array $a keys
- * @param array $b values
- * @return array
- */
- function array_rsort($a, $b)
- {
- $as = strtoupper(trim($a[1]));
- $bs = strtoupper(trim($b[1]));
- $as = strtr($as, "ä", "A");
- $as = strtr($as, "ö", "O");
- $as = strtr($as, "ü", "U");
- $as = strtr($as, "ß", "S");
- $bs = strtr($bs, "Ä", "A");
- $bs = strtr($bs, "Õ", "O");
- $bs = strtr($bs, "Ü", "U");
- if ($as == $bs) return 0;
- else return ($as < $bs)?1:-1;
- }
- /**
- * the current date
- *
- * @param char $date_format see member variables $this->date_format below
- * @return date
- */
- function currentDate($date_format=null)
- {
- if ((!isset($date_format)) || (empty($date_format))) $date_format = $this->date_format;
- $day = date("d");
- $month = date("m");
- $year = date("Y");
- if ($date_format=="I") return $month.$this->m_sep_i.$day .$this->m_sep_i.$year;
- else if ($date_format=="S") return $year .$this->m_sep_s.$month.$this->m_sep_s.$day;
- else if ($date_format=="C") return $year .$month. $day;
- else return $day .$this->m_sep_l.$month.$this->m_sep_l.$year;
- }
- /**
- * the current time
- *
- * @param char $time_format see member variable $this->time_format below
- * @return time
- */
- function currentTime($time_format=null)
- {
- if ((!isset($time_format)) || (empty($time_format))) $time_format = $this->time_format;
- if ($time_format=="Y")
- return date("H").":".date("i").":".date("s");
- else
- return date("h").":".date("i").":".date("s")." ".date("a");
- }
- /**
- * Get date from db-date format
- * (short form of convDate)
- *
- * @param string $dbdate
- * @param bool $short_mode
- * @return string
- */
- function show_dbdate($dbdate, $short_mode=true)
- {
- if ($short_mode==true)
- {
- return $this->convDate($dbdate, 'S', $this->date_format, array('short_mode'=>true));
- }
- else
- {
- return $this->convDate($dbdate, 'S', $this->date_format);
- }
- }
- /**
- * Get Datetime from db-date format
- * (short form of convDate)
- *
- * @param string $dbdate
- * @param bool $with_seconds
- * @param bool $short_mode
- * @param string $at
- * @return string
- */
- function show_dbdatetime($dbdate, $with_seconds=false, $short_mode=true, $at=null)
- {
- return $this->convDateTime($dbdate, $this->date_format, $this->time_format, $with_seconds, $short_mode, $at);
- }
- /**
- * Removes all whitespaces in a string
- *
- * @param string $str
- * @return string
- */
- function killSpace($str)
- {
- $rc = htmlentities($str);
- $rc = str_replace(" ","",$rc);
- $rc = str_replace(" ","",$rc);
- $rc = str_replace(" ","",$rc);
- return $rc;
- }
- /**
- * validate given date
- *
- * @param mixed $timestamp array of date for validating or timestamp
- * array keys: timestamp['year']
- * timestamp['month']
- * timestamp['day']
- * timestamp['hour']
- * timestamp['minute']
- * timestamp['second']
- * @param bool $mode if true, input date is a timestamp {default: false}
- * @return timestamp timestamp with valid date, if invalid input datas, return timestamp will
- * be return the nearest valid date
- */
- function validate_timestamp($timestamp,$mode=false)
- {
- if (!$mode)
- {
- $timestamp = mktime($timestamp['hour'],
- $timestamp['minute'],
- $timestamp['second'],
- $timestamp['month'],
- $timestamp['day'],
- $timestamp['year']);
- }
- if ($timestamp<mktime(2,0,0,1,1,1970))
- return mktime(2,0,0,1,1,1970);
- else if ($timestamp>mktime(2,0,0,12,31,2037))
- return mktime(2,0,0,12,31,2037);
- else
- return $timestamp;
- }
- /**
- * calculates days to a given date
- *
- * @param date $start_date first date
- * @param date $end_date last date
- * @param char $date_format see member variables $this->date_format below
- * @return int number of days, if date is out of range -1
- */
- function date2days($start_date, $end_date, $date_format="S")
- {
- if ($date_format!="S")
- {
- $start_date = $this->convDate($start_date, $date_format, 'S');
- $end_date = $this->convDate($end_date, $date_format, 'S');
- }
- $start_year = strtok($start_date,"-");
- $start_month = strtok("-");
- $start_day = strtok("-");
- $end_year = strtok($end_date,"-");
- $end_month = strtok("-");
- $end_day = strtok("-");
- if ($this->file_exists("Date.php"))
- require_once("Date.php");
- else
- {
- $this->show_error("date2days", "Pear \"Date Package\" required.");
- }
- return Date_Calc::dateDiff($start_day,$start_month,$start_year,$end_day,$end_month,$end_year);
- }
- /**
- * return file extension
- *
- * @param string $filename
- * @return string
- */
- function fileExtension($filename)
- {
- $rc="";
- $max_length = strlen($filename);
- $counter=0;
- while($max_length>0)
- {
- $ch = $filename[$max_length];
- if ($ch == ".")
- break;
- $rc .= $ch;
- $max_length--;
- $counter++;
- }
- if ($rc!="") $rc = strrev($rc);
- return $rc;
- }
- /**
- * convert string to number while converting old seperator with "."
- *
- * @param string $value string to convert {default: ","}
- * @param string $sep_old old seperator
- * @return float
- */
- function convToNum($value,$sep_old=",")
- {
- $rc = "";
- if (empty($sep_old))
- {
- $this->show_error("convtoNum", "missing parameter sep_old");
- }
- $st = trim($value);
- $sep_new = ".";
- if (!isvoid($st))
- {
- if ($this->checkNumber($st,$sep_old))
- {
- if ($sep_old != $sep_new)
- {
- if ($this->checkNumber($st,$sep_old))
- {
- $num_sep = substr_count($st,$sep_old);
- if ($num_sep==1)
- $rc = str_replace($sep_old,$sep_new,$st);
- else
- $rc = $st;
- }
- }
- else
- $rc = $st;
- }
- }
- return $rc;
- }
- /**
- * convert seperator in number and fill number to specified length
- *
- * @param float $st number to convert
- * @param char $sep_new new seperator {default: "."}
- * @param int $precision numbers behind seperator {default: 0 }
- * (filling with 0; this function doesn't cut or round numbers)
- * @param string $group if set, this group seperator will be used
- * @return string converted string with number
- */
- function convnumSep($st, $sep_new=".", $precision=0, $group=null)
- {
- $rc="";
- if (!isvoid($st))
- {
- if ($this->checkNumber($st))
- {
- $sep_old = ".";
- $num_sep = substr_count($st,$sep_old);
- if (($num_sep==0) && ($precision>0)) // no old seperator
- {
- $tmp_st = $st.$sep_new;
- for ($ix=0;$ix<$precision;$ix++)
- $tmp_st .= "0";
- $rc = $tmp_st;
- }
- else // with old seperator
- {
- $ln = strlen($st);
- $pos = strrpos($st, $sep_old);
- $ln_ext = $ln-$pos-1;
- if ($ln_ext<$precision)
- {
- $ln_miss = $precision - $ln_ext;
- $tmp_st=$st;
- for ($ix=0;$ix<$ln_miss;$ix++)
- $tmp_st .= "0";
- $rc = str_replace($sep_old, $sep_new, $tmp_st);
- }
- else
- {
- $rc = str_replace($sep_old, $sep_new, $st);
- }
- }
- // fill group seperator, if defined
- if (isset($group))
- {
- if ($rc[0]=="-") $g_rc = substr($rc, 1);
- else $g_rc = $rc;
- $ln = strlen($g_rc); // get new length
- $pos = strrpos($g_rc, $sep_new);
- if ($pos>3)
- {
- $suffix_ln = $ln-$pos+1;
- $prefix_ln = $ln-$suffix_ln+1;
- if ($prefix_ln>3)
- {
- $tmp_rc = "";
- $prefix = strrev(substr($g_rc, 0, $prefix_ln));
- for ($ix=0; $ix<$prefix_ln; $ix++)
- {
- if (($ix>0) && ($ix%3==0)) $tmp_rc .= $group;
- $tmp_rc .= $prefix[$ix];
- }
- $g_rc = strrev($tmp_rc).substr($g_rc, $pos);
- }
- }
- if ($rc[0]=="-") $rc = "-".$g_rc;
- else $rc = $g_rc;
- }
- }
- }
- else
- $rc = $st;
- return $rc;
- }
- /**
- * validate time format and convert it into right format
- *
- * @param string $time time (or date) to convert, if empty NOW will be used
- * @param char $format if empty or time, e.g. 19:45:59
- * datetime, e.g. 2002-07-20 21:02:55
- * @return string converted time, if wrong input false
- */
- function convToTimestamp($time="",$format="")
- {
- $timestamp = "";
- if ((isvoid($format)) || ($format=="time")) // only time
- {
- if (isvoid($time)) $timestamp = strtotime("now");
- else
- {
- $t_hours = strtok(trim($time),":");
- $t_min = strtok(":");
- $t_sec = strtok(":");
- $t_day = date("d");
- $t_month = date("m");
- $t_year = date("Y");
- $tmp_stamp = mktime($t_hours,$t_min,$t_sec,$t_month,$t_day,$t_year);
- if ($tmp_stamp>0)
- $timestamp = $tmp_stamp;
- }
- }
- if (($format=="datetime") && (!isvoid($time))) // datetime
- {
- $tdate = trim(strtok(trim($time)," "));
- $ttime = trim(strtok(" "));
- $t_year = strtok($tdate,"-");
- $t_month = strtok("-");
- $t_day = strtok("-");
- $t_hours = strtok($ttime,":");
- $t_min = strtok(":");
- $t_sec = strtok(":");
- $tmp_stamp = mktime($t_hours,$t_min,$t_sec,$t_month,$t_day,$t_year);
- if ($tmp_stamp>0)
- $timestamp = $tmp_stamp;
- }
- return $timestamp;
- }
- /**
- * validate time format and convert it into right format
- *
- * @param string $time time to convert
- * @param char $time_format see member variable $this->time_format above
- * @param bool $with_seconds if false, don't return seconds {default: true}
- * @return string converted time, if wrong input false
- */
- function convTime($time, $time_format=null, $with_seconds=true)
- {
- $rc="";
- if ((!isset($time_format)) || (empty($time_format))) $time_format = $this->time_format;
- $ln = strlen($time);
- if ($ln == 5)
- {
- $part1 = strtok($time,":");
- $part2 = strtok(":");
- if ((strlen($part1)==2) && (strlen($part2)==2))
- {
- if (($part1>=0) && ($part1<25) && ($part2>=0) && ($part2<60))
- {
- if ($time_format=="N") // 12 hours
- {
- if ($part1>=12)
- {
- $part1 = $part1-12;
- $end = " pm";
- }
- else
- {
- $part1 += 0;
- $end = " am";
- }
- if ($part1==0)
- $part1 = 12;
- $rc = $part1 . ":" . $part2.$end;
- }
- else // 24 hours
- {
- $rc = $part1 . ":" . $part2;
- }
- }
- }
- }
- else if ($ln >= 8)
- {
- $part1 = strtok($time,":");
- $part2 = strtok(":");
- $part3 = strtok(":");
- if (strlen($part3)>2) $part3 = substr($part3, 0, 2);
- if ((strlen($part1)==2) && (strlen($part2)==2) && (strlen($part3)==2))
- {
- if (($part1>=0) && ($part1<25) && ($part2>=0) && ($part2<60) && ($part3>=0) && ($part3<60))
- {
- if ($time_format=="N") // 12 hours
- {
- if ($part1>12)
- {
- $part1 = $part1-12;
- $end = " pm";
- }
- else
- {
- $part1 += 0;
- $end = " am";
- }
- $rc = $part1 . ":" .$part2;
- if ($with_seconds) $rc .= ":".$part3;
- $rc .= $end;
- }
- else // 24 hours
- {
- $rc = $part1 . ":" .$part2;
- if ($with_seconds) $rc .= ":".$part3;
- }
- }
- }
- }
- return $rc;
- }
- /**
- * convert datetime format
- *
- * @param string $datetime db datetime field format
- * @param char $date_format see member variable m_date above
- * @param char $time_format see member variable m_time above
- * @param bool $with_seconds show seconds
- * @param bool $short_mode if today, yesterday or tomorrow
- * show string for date
- * @param string $at
- * @return string datetime in converted format
- */
- function convDateTime($datetime, $date_format="", $time_format="", $with_seconds=false, $short_mode=true, $at=null)
- {
- $rc="";
- if (!isvoid($datetime))
- {
- if ((!isset($date_format)) || (empty($date_format))) $date_format = $this->date_format;
- if ((!isset($time_format)) || (empty($time_format))) $time_format = $this->time_format;
- $tmp_date = strtok($datetime, " ");
- $tmp_time = strtok(" ");
- if (($short_mode) && (!isvoid($tmp_time)))
- $rc = $this->convDate($tmp_date, 'S', $date_format, array('short_mode'=>true));
- else
- $rc = $this->convDate($tmp_date, 'S', $date_format);
- if (!isvoid($tmp_time))
- {
- if (isset($at)) $tmp_at = $at;
- else $tmp_at = STR_AT;
- if ($tmp_at!=",") $rc .= " ";
- $rc .= $tmp_at." ";
- $rc .= $this->convTime($tmp_time, $time_format, $with_seconds);
- }
- }
- return $rc;
- }
- /**
- * Convert date format
- *
- * @param string $date_str date to convert
- * @param string $src_format see member variables $this->date_format above
- * @param string $dest_format see member variables $this->date_format above or 'short' or 'long'
- * @param array $customize year_format string = long : e.g. 2002 {default}
- * short: e.g. 02
- * void : e.g.
- * leading_zeros bool = true : e.g. 01 {default}
- * false: e.g. 1
- * with_weekday bool = true: with weekday
- * false: without weekdays
- * (only available if dest_format is short or long)
- * locale string = see member variables m_locale above
- * first_valid_year = first valid year, if specified date is before, it will be signed
- * as invalid {default: 1850}
- * short_mode = if today, yesterday or tomorrow
- * show string for date {default: false}
- * @return string date or {if wrong input) empty
- */
- function convDate($date_str, $src_format, $dest_format, $customize=null)
- {
- $rc = "";
- $sep_old = "";
- $sep_new = "";
- $date_package = false;
- // all years are possible, but year 0 cannot be selected (does anyone need it?)
- if ((!isset($customize['first_valid_year'])) || (intval($customize['first_valid_year'])==0))
- $customize['first_valid_year'] = 1850;
- if ($this->file_exists("Date.php"))
- {
- require_once("Date.php");
- $date_package = true;
- }
- if ((isset($customize['locale'])) && (!setlocale(LC_TIME,$customize['locale'])))
- {
- $this->show_error("convDate", "locale not readable from system!");
- }
- if (strtoupper($src_format)=="L") // DD.MM.YYYY
- {
- $sep_old = $this->m_sep_l;
- $day = intval(strtok($date_str,$sep_old));
- $month = intval(strtok($sep_old));
- $year = intval(strtok($sep_old));
- if ($year<20) $year += 2000;
- else if ($year<100) $year += 1900;
- }
- else if (strtoupper($src_format)=="I") // MM/DD/YYYY
- {
- $sep_old = $this->m_sep_i;
- $month = intval(strtok($date_str,$sep_old));
- $day = intval(strtok($sep_old));
- $year = intval(strtok($sep_old));
- if ($year<20) $year += 2000;
- else if ($year<100) $year += 1900;
- }
- else if (strtoupper($src_format)=="S") // YYYY-MM-DD
- {
- $sep_old = $this->m_sep_s;
- $year = intval(strtok($date_str,$sep_old));
- $month = intval(strtok($sep_old));
- $day = intval(strtok($sep_old));
- if ($year<20) $year += 2000;
- else if ($year<100) $year += 1900;
- }
- else if (strtoupper($src_format)=="C") // YYYYMMDD
- {
- if (strlen($date_str)==8)
- {
- $year = substr($date_str,0,4);
- $month = substr($date_str,4,2);
- $day = substr($date_str,6,2);
- }
- else
- {
- $year = substr($date_str,0,2);
- $month = substr($date_str,2,2);
- $day = substr($date_str,4,2);
- }
- if ($year<20) $year += 2000;
- else if ($year<100) $year += 1900;
- }
- if (strtoupper($dest_format)=="I") $sep_new = $this->m_sep_i;
- else if (strtoupper($dest_format)=="S") $sep_new = $this->m_sep_s;
- else if (strtoupper($dest_format)=="L") $sep_new = $this->m_sep_l;
- else if (strtoupper($dest_format)=="C") $sep_new = "";
- else $sep_new = $this->m_sep_s;
- if ((checkdate($month,$day,$year)) && ($customize['first_valid_year']<=$year))
- {
- $short_mode = false;
- if ((isset($customize['short_mode'])) && ($customize['short_mode']))
- {
- if (date("Y-n-j")=="$year-$month-$day")
- {
- $rc = STR_TODAY;
- $short_mode=true;
- }
- else if (date("Y-n-j", mktime(date('H'),date('i'), 0,date('m'), date('d')+1,date('Y')))=="$year-$month-$day")
- {
- $rc = STR_TOMORROW;
- $short_mode=true;
- }
- else if (date("Y-n-j", mktime(date('H'),date('i'), 0,date('m'), date('d')-1,date('Y')))=="$year-$month-$day")
- {
- $rc = STR_YESTERDAY;
- $short_mode=true;
- }
- }
- if ($short_mode==false)
- {
- if (isset($customize['year_format']))
- {
- $y_form = $customize['year_format'];
- if ($y_form=="short") $year = substr($year,strlen($year)-2,2);
- else if ($y_form=="void") $year = "";
- }
- $day = sprintf("%02d",$day);
- $month = sprintf("%02d",$month);
- if ((isset($customize['leading_zeros'])) && (!empty($sep_new)))
- {
- $l_zeros = $customize['leading_zeros'];
- if (!$l_zeros)
- {
- $day = intval($day);
- $month = intval($month);
- }
- }
- else if (empty($sep_new))
- {
- if (strlen($day)<2) $day .= "0";
- if (strlen($month)<2) $month .= "0";
- }
- if (($dest_format=="long") || ($dest_format=="short"))
- {
- if ($date_package)
- {
- $stamp = new Date();
- $stamp->setDate("$year-$month-$day",DATE_FORMAT_ISO);
- }
- $wday = "";
- if (isset($customize['with_weekday']))
- {
- $with_wday = $customize['with_weekday'];
- if ($with_wday)
- {
- if ($date_package)
- {
- if ($dest_format=="long") $wday = $stamp->format("%A").", ";
- else $wday = $stamp->format("%a").", ";
- }
- else
- {
- $this->show_error("convDate", "Pear \"Date Package\" required for specificed parameters.");
- }
- }
- }
- if ($date_package)
- {
- if ($dest_format=="long") $month = $stamp->format("%B");
- else $month = $stamp->format("%b");
- }
- else
- {
- $this->show_error("convDate", "Pear \"Date Package\" required for specificed parameters.");
- }
- if ($this->m_date=="I") $rc = $wday.$month."/".$day."/".$year;
- else $rc = $wday.$day.". ".$month." ".$year;
- }
- else
- {
- if ($sep_new==$this->m_sep_i)
- {
- $rc = $month.$this->m_sep_i.$day;
- if (!isvoid($year))
- $rc .= $this->m_sep_i.$year;
- }
- else if ($sep_new==$this->m_sep_s)
- {
- if (!isvoid($year))
- $rc .= $year.$this->m_sep_s;
- $rc .= $month.$this->m_sep_s.$day;
- }
- else if ($sep_new==$this->m_sep_l)
- …
Large files files are truncated, but you can click here to view the full file