| Server IP : 172.67.178.83 / Your IP : 216.73.217.141 Web Server : Apache System : Linux hosting01.arsenalhost.com 4.18.0-425.13.1.lve.el8.x86_64 #1 SMP Mon Feb 27 15:23:24 EST 2023 x86_64 User : corbizre ( 1013) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/corbizre/gotofindhomes.com3/components/User/ |
Upload File : |
<?php
/**
* Documentation
* @author
* @category
* @package
* @subpackage
* @copyright Copyright (c) 2005-2012 ITCrimea Ukraine Inc. (http://www.itcrimea.com)
* @license
*/
class User extends System_Db_Object
{
const FORMAT_DATE = 'Y-m-d';
const FORMAT_TIME = 'H:i';
const FORMAT_DATETIME = 'Y-m-d H:i';
const REGEXP_DATE = '(\d{2})\.(\d{2}).(\d{4})';
const REGEXP_TIME = '(\d{1,2}):(\d{2})';
const REGEXP_DATETIME = '(\d{2})\.(\d{2}).(\d{4}) (\d{1,2}):(\d{2})';
const ACCESS_STAFF_ADMIN = 1;
const ACCESS_STAFF_SALESMAN = 2;
const ACCESS_STAFF_STOCKMAN = 3;
const ACCESS_STAFF_TECHNICIAN = 4;
const STATUS_ACTIVE = 1;
const STATUS_BANNED = 2;
const EXTERNAL_TYPE_MONGO = 1;
/**
* returns list of all statuses
* @author Timur
* @return string
*/
public static function getStatusesList()
{
return array(
self::STATUS_ACTIVE => self::getStatusText(self::STATUS_ACTIVE),
self::STATUS_BANNED => self::getStatusText(self::STATUS_BANNED));
}
/**
* returns title of status type
* @author keeper
* @return string
*/
public static function getStatusText($AccessID)
{
switch ($AccessID) {
case self::STATUS_BANNED: return 'Banned';
case self::STATUS_ACTIVE: return 'Active';
}
return '';
}
/**
* returns title of access type
* @author keeper
* @return string
*/
public static function getAccessText($AccessID)
{
switch ($AccessID) {
case self::ACCESS_STAFF_ADMIN: return 'Administrator';
case self::ACCESS_STAFF_SALESMAN: return 'Salesman';
case self::ACCESS_STAFF_STOCKMAN: return 'Stockman';
case self::ACCESS_STAFF_TECHNICIAN: return 'Technician';
}
return '';
}
/**
* returns list of all access types
* @author keeper
* @return array
*/
public static function getAccessList()
{
return array(
self::ACCESS_STAFF_ADMIN => self::getAccessText(self::ACCESS_STAFF_ADMIN),
self::ACCESS_STAFF_SALESMAN => self::getAccessText(self::ACCESS_STAFF_SALESMAN),
self::ACCESS_STAFF_STOCKMAN => self::getAccessText(self::ACCESS_STAFF_STOCKMAN),
self::ACCESS_STAFF_TECHNICIAN => self::getAccessText(self::ACCESS_STAFF_TECHNICIAN));
}
/**
* implode array with access ids to string
* @author keeper
* @param array $arrAccess
* @return string
*/
public static function implodeAccess($arrAccess)
{
$str = '|' . implode('|', $arrAccess) . '|';
return $str;
}
/**
* explode string with access ids to array
* @author keeper
* @param string $strAccess
* @return array
*/
public static function explodeAccess($strAccess)
{
$strAccess = trim($strAccess, '|');
if (!$strAccess) return array();
$arr = explode('|', $strAccess);
return $arr;
}
/**
* return array of accesses for current user
* @author Ilya
* @return array
*/
public static function getAccess()
{
$strAccess = System_User::getUser()->Access;
return self::explodeAccess($strAccess);
}
/**
* answer is user has asked access
* @author keeper
* @param int|array $RequiredAccessID
* @param int $UserID
* @return boolean
*/
public static function hasAccess($CompanyID=null, $UserID=null)
{
if (System_User::getID() == 1) return true;
if ($UserID && $UserID != System_User::getID()) {
$tblUser = User_Table::getInstance();
$objUser = $tblUser->find($UserID)->current();
if (!is_object($objUser)) return false;
$arrAccess = unserialize($objUser->Access);
} else {
$arrAccess = unserialize(System_User::getUser()->Access);
}
if (!is_array($CompanyID)) $CompanyID = array($CompanyID);
foreach ($CompanyID as $AccessID) {
if (in_array($AccessID, $arrAccess)) return true;
}
return false;
}
/**
* check is logged user has asked access and show exception if not, does not apply to system admin
* @author keeper
* @param int|array $RequiredAccessID
* @param int $UserID
* @return boolean
*/
public static function checkAccess($CompanyID=null, $UserID=null)
{
if (System_User::getID() == 1) return;
if (!self::hasAccess($CompanyID, $UserID)) {
throw new Zend_Exception('Sorry you have no access to asked functionality');
}
}
//const ACCESS_ADMIN
/**
* return the timezones array
* @author keeper
* @return array
*/
public static function getTimeZones()
{
$arrTimeZones = array(
'-12' => '(UTC−12) Baker Island, Howland Island (both uninhabited)',
'-11' => '(UTC-11) Samoa, American Samoa',
'-10' => '(UTC−10) Hawaii, Papeete',
'-9.5' => '(UTC−09:30) Marquesas Islands',
'-9' => '(UTC−09) Anchorage, Fairbanks, Juneau',
'-8' => '(UTC−08) Vancouver, Washington (U.S. state), Portland, Las Vegas, California, Baja California',
'-7' => '(UTC−07) Alberta, Colorado, Arizona, Chihuahua, Sonora',
'-6' => '(UTC−06) Costa Rica, Dallas, El Salvador, Guatemala, Honduras, Houston, Illinois, Manitoba, Mexico City, Nicaragua, Saskatchewan',
'-5' => '(UTC−05) Ottawa, Toronto, Montreal, Boston, New York, North Carolina, Washington D.C., Georgia, Miami, Cuba, Jamaica, Haiti, Panama, Colombia, Continental Ecuador, Peru',
'-4.5' => '(UTC−04:30) Venezuela',
'-4' => '(UTC−04) Nova Scotia, Dominican Republic, Puerto Rico, Trinidad and Tobago, Amazonas, Bolivia, Continental Chile, Paraguay, San Luis Province',
'-3.5' => '(UTC−03:30) Newfoundland',
'-3' => '(UTC−03) Rio de Janeiro, São Paulo, Argentina (except San Luis Province), Uruguay, Nuuk',
'-2' => '(UTC−02) Fernando de Noronha, South Georgia and the South Sandwich Islands',
'-1' => '(UTC−01) Azores, Cape Verde',
'0' => '(UTC) Iceland, United Kingdom, Ireland, Continental Portugal, Morocco, Senegal, Ghana, Côte d\'Ivoire',
'1' => '(UTC+01) Albania, Slovenia, Macedonia, Norway, Sweden, Denmark, Germany, the Netherlands, Belgium, Metropolitan France, Switzerland, Austria, Poland, Czech Republic, Slovakia, Hungary, European Spain, Italy, Croatia, Serbia, Bosnia and Herzegovina, Tunisia, Algeria, Nigeria, Cameroon, Angola, Kinshasa',
'2' => '(UTC+02) Finland, Lithuania, Latvia, Estonia, Belarus, Ukraine, Romania, Bulgaria, Greece, Turkey, Cyprus, Syria, Lebanon, Jordan, Palestine, Israel, Egypt, Libya, Mozambique, Malawi, Zambia, Zimbabwe, South Africa',
'3' => '(UTC+03) Moscow, Saint Petersburg, Samara, Iraq, Saudi Arabia, Yemen, Sudan, Ethiopia, Somalia, Kenya, Uganda, Tanzania, Madagascar',
'3.5' => '(UTC+03:30) Iran',
'4' => '(UTC+04) Georgia, Armenia, Azerbaijan, United Arab Emirates, Oman, Seychelles, Mauritius',
'4.5' => '(UTC+04:30) Afghanistan',
'5' => '(UTC+05) Sverdlovsk, Uzbekistan, Pakistan, Maldives, Kazakhstan',
'5.5' => '(UTC+05:30) India, Sri Lanka',
'5.75' => '(UTC+05:45) Nepal',
'6' => '(UTC+06) Novosibirsk, Almaty, Bangladesh',
'6.5' => '(UTC+06:30) Myanmar, Cocos Islands',
'7' => '(UTC+07) Krasnoyarsk, Thailand, Vietnam, Jakarta',
'8' => '(UTC+08) Irkutsk, Ulan Bator, China, Taiwan, Hong Kong, Philippines, Malaysia, Singapore, Western Australia',
'9' => '(UTC+09) Zabaykalsky, Japan, North Korea, South Korea, East Timor',
'9.5' => '(UTC+09:30) Northern Territory, South Australia',
'10' => '(UTC+10) Victoria, Tasmania, Queensland, New South Wales, Primorsky',
'10.5' => '(UTC+10:30) Lord Howe Island',
'11' => '(UTC+11) Kamchatka, Solomon Islands, New Caledonia',
'11.5' => '(UTC+11:30) Norfolk Island',
'12' => '(UTC+12) Fiji, New Zealand',
'12.75' => '(UTC+12:45) Chatham Islands',
'13' => '(UTC+13) Tonga',
'14' => '(UTC+14) Line Islands');
return $arrTimeZones;
}
/**
* return the timezone text
* @author keeper
* @return string
*/
public static function getTimeZoneText($TimeZone, $TextForUnknown='undefined')
{
$arrTimeZones = self::getTimeZones();
return isset($arrTimeZones[$TimeZone]) ? $arrTimeZones[$TimeZone] : $TextForUnknown;
}
/**
* returns time shift between user time and server time in second
* @author keeper
* @param int|null $TimeZone
* @return string
*/
public static function getTimeShift($TimeZone=null)
{
if (is_null($TimeZone)) $TimeZone = System_User::getUser()->TimeZone;
return intval(3600*$TimeZone - date('Z'));
}
/**
* conver server time to user local
* @author keeper
* @param int|string $Date
* @param string $Format
* @param int|null $TimeZone
* @param boolean $ProtectReturn
* @return string
*/
public static function getUserTime($Date, $Format=null, $TimeZone=null, $ProtectReturn=true)
{
if (is_null($Format)) $Format = self::FORMAT_TIME;
if (is_null($TimeZone)) $TimeZone = System_User::getUser()->TimeZone;
if (!is_numeric($Date)) {
if (strlen($Date) < 7) $Date = '2005-05-05 '.$Date;
$Date = strtotime($Date);
}
if ($ProtectReturn) {
if ($Date < 946681200) return; // 2000-01-01 01:00:00
}
$TimeShift = 3600*$TimeZone - date('Z');
return date($Format, $Date + $TimeShift);
}
/**
* conver server date to user local
* @author keeper
* @param int|string $Date
* @param string $Format
* @param int|null $TimeZone
* @param boolean $ProtectReturn
* @return string
*/
public static function getUserDate($Date, $Format=null, $TimeZone=null, $ProtectReturn=true)
{
if (is_null($Format)) $Format = self::FORMAT_DATE;
if (is_null($TimeZone)) $TimeZone = System_User::getUser()->TimeZone;
if (!is_numeric($Date)) {
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $Date)) {
$Date .= ' 15:00:00';
}
$Date = strtotime($Date);
}
if ($ProtectReturn) {
if ($Date < 946681200) return; // 2000-01-01 01:00:00
}
$TimeShift = 3600*$TimeZone - date('Z');
return date($Format, $Date + $TimeShift);
}
/**
* conver server datetime to user local
* @author keeper
* @param int|string $Date
* @param string $Format
* @param int|null $TimeZone
* @param boolean $ProtectReturn
* @return string
*/
public static function getUserDatetime($Date, $Format=null, $TimeZone=null, $ProtectReturn=true)
{
if (is_null($Format)) $Format = self::FORMAT_DATETIME;
if (is_null($TimeZone)) $TimeZone = System_User::getUser()->TimeZone;
if (!is_numeric($Date)) $Date = strtotime($Date);
if ($ProtectReturn) {
if ($Date < 946681200) return; // 2000-01-01 01:00:00
}
$TimeShift = 3600*$TimeZone - date('Z');
return date($Format, $Date + $TimeShift);
}
/**
* conver user local date to system date
* @author keeper
* @param int|string $Date
* @return int
*/
public static function getSystemTimestamp($Date)
{
if (!is_numeric($Date)) $Date = strtotime($Date);
$TimeShift = 3600*(System_User::getUser()->TimeZone) - date('Z');
return $Date - $TimeShift;
}
/**
* return the user timezone text
* @author keeper
* @return string
*/
public static function getTimeZone($TimeZone=null)
{
if (is_null($TimeZone)) $TimeZone = System_User::getUser()->TimeZone;
$str = 'UTC';
if ($TimeZone === 0 || $TimeZone === '0') return $str;
$TimeZone = floatval($TimeZone);
if ($TimeZone>0) $str .= '+';
if ($TimeZone<0) $str .= '-';
$TimeZone = abs($TimeZone);
$str .= sprintf('%02d', floor($TimeZone)) . ':' . sprintf('%02d', 60*($TimeZone - floor($TimeZone)));
return $str;
}
/**
* return the timezones array
* @author keeper
* @return array
*/
/*public static function getTimeZones()
{
$arrTimeZones = array(
'-12' => '(GMT -12:00 hours) Eniwetok, Kwajalein',
'-11' => '(GMT -11:00 hours) Midway Island, Samoa',
'-10' => '(GMT -10:00 hours) Hawaii',
'-9' => '(GMT -9:00 hours) Alaska',
'-8' => '(GMT -8:00 hours) Pacific Time (US & Canada)',
'-7' => '(GMT -7:00 hours) Mountain Time (US & Canada)',
'-6' => '(GMT -6:00 hours) Central Time (US & Canada), Mexico City',
'-5' => '(GMT -5:00 hours) Eastern Time (US & Canada), Bogota, Lima, Quito',
'-4' => '(GMT -4:00 hours) Atlantic Time (Canada), Caracas, La Paz',
'-3' => '(GMT -3:00 hours) Brazil, Buenos Aires, Georgetown',
'-2' => '(GMT -2:00 hours) Mid-Atlantic',
'-1' => '(GMT -1:00 hours) Azores, Cape Verde Islands',
'0' => '(GMT) Western Europe Time, London, Lisbon, Casablanca, Monrovia',
'1' => '(GMT +1:00 hours) CET(Central Europe Time), Brussels, Copenhagen, Madrid, Paris',
'2' => '(GMT +2:00 hours) EET(Eastern Europe Time), Kaliningrad, South Africa',
'3' => '(GMT +3:00 hours) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg, Volgograd, Nairobi',
'4' => '(GMT +4:00 hours) Abu Dhabi, Muscat, Baku, Tbilisi',
'5' => '(GMT +5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent',
'6' => '(GMT +6:00 hours) Almaty, Dhaka, Colombo',
'7' => '(GMT +7:00 hours) Bangkok, Hanoi, Jakarta',
'8' => '(GMT +8:00 hours) Beijing, Perth, Singapore, Hong Kong, Chongqing, Urumqi, Taipei',
'9' => '(GMT +9:00 hours) Tokyo, Seoul, Osaka, Sapporo, Yakutsk',
'10' => '(GMT +10:00 hours) EAST(East Australian Standard), Guam, Papua New Guinea, Vladivostok',
'11' => '(GMT +11:00 hours) Magadan, Solomon Islands, New Caledonia',
'12' => '(GMT +12:00 hours) Auckland, Wellington, Fiji, Kamchatka, Marshall Island');
return $arrTimeZones;
}*/
/**
* encode password
* @author keeper
* @param string $strPassword
* @return string
*/
public static function encodePassword($strPassword)
{
// password encoding has been disabled because Kayako integration
//return md5($strPassword);
return $strPassword;
}
/**
* implode array with phones to string
* @author keeper
* @param array $arrPhones
* @return string
*/
public static function implodePhones($arrPhones)
{
$strPhones = '';
foreach ($arrPhones as $arrPhone) {
if (isset($arrPhone['Type']) && $arrPhone['Type'] && isset($arrPhone['Number']) && $arrPhone['Number'])
$strPhones .= trim($arrPhone['Type']).':'.trim($arrPhone['Number']).';';
}
//$strPhones = trim($strPhones, ';');
return $strPhones;
}
/**
* explode string with phones to array
* @author keeper
* @param string $strPhones
* @return array
*/
public static function explodePhones($strPhones)
{
if (!$strPhones) return array();
$arr = explode(';', $strPhones);
if (!$arr) return array();
$arrPhones = array();
foreach ($arr as $row) {
$row = explode(':', $row);
if (is_array($row) && count($row)==2) {
$arrPhones[] = array('Type'=>$row[0], 'Number'=>$row[1]);
}
}
return $arrPhones;
}
/**
* answer is user validation using pic code has been finished successfully
* @author keeper
* @return boolean
*/
public static function isPinValid($clearPinValidation=true)
{
$isValid = System_Session::getParam('PinValid') ? true : false;
if ($clearPinValidation) self::clearPinValidation();
return $isValid;
}
/**
* clear the previous pin code validation
* @author keeper
* @return null
*/
public static function clearPinValidation()
{
System_Session::setParam('PinValid', null);
}
public static function generatePassword()
{
$strPassChars = 'abdefhiknrstyzABDEFGHKNQRSTYZ23456789';
$intPassLength = 10;
$intNumChars = strlen($strPassChars);
$strPassword = '';
for ($I = 0; $I < $intPassLength; $I++) {
$strPassword .= substr($strPassChars, rand(1, $intNumChars) - 1, 1);
}
return $strPassword;
}
}