Index: branches/unlabeled/unlabeled-1.17.2/admin/index.php
===================================================================
diff -u -r4331 -r4354
--- branches/unlabeled/unlabeled-1.17.2/admin/index.php (.../index.php) (revision 4331)
+++ branches/unlabeled/unlabeled-1.17.2/admin/index.php (.../index.php) (revision 4354)
@@ -1,88 +1,88 @@
-Set('AdminDirectory', $admin, 0, true);
- $objConfig->Save();
-
- if (!admin_login() || GetVar('logout') || GetVar('expired') ) {
- if (!headers_sent()) {
- set_cookie(SESSION_COOKIE_NAME, '', adodb_mktime() - 3600);
- }
- $objSession->Logout();
- require_once FULL_PATH.'/admin/login.php';
- }
-
- $envar = 'env='.BuildEnv();
-
- require_once FULL_PATH.'/admin/include/elements.php';
- require_once FULL_PATH.'/kernel/admin/include/navmenu.php';
-
- $charset = GetRegionalOption('Charset');
-?>
-
-
-
-
-
-
-
- In-portal Administration
-
-
-
-
-
-
-
-
-
-
+Set('AdminDirectory', $admin, 0, true);
+ $objConfig->Save();
+
+ if (!admin_login() || GetVar('logout') || GetVar('expired') ) {
+ if (!headers_sent()) {
+ set_cookie(SESSION_COOKIE_NAME, '', adodb_mktime() - 3600);
+ }
+ $objSession->Logout();
+ require_once FULL_PATH.'/admin/login.php';
+ }
+
+ $envar = 'env='.BuildEnv();
+
+ require_once FULL_PATH.'/admin/include/elements.php';
+ require_once FULL_PATH.'/kernel/admin/include/navmenu.php';
+
+ $charset = GetRegionalOption('Charset');
+?>
+
+
+
+
+
+
+
+ In-portal Administration
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.4.20/themes/default/register/register_dob.tpl
===================================================================
diff -u -r3380 -r4354
--- branches/unlabeled/unlabeled-1.4.20/themes/default/register/register_dob.tpl (.../register_dob.tpl) (revision 3380)
+++ branches/unlabeled/unlabeled-1.4.20/themes/default/register/register_dob.tpl (.../register_dob.tpl) (revision 4354)
@@ -1,154 +1,154 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php
===================================================================
diff -u -r3924 -r4354
--- branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php (.../xml_helper.php) (revision 3924)
+++ branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php (.../xml_helper.php) (revision 4354)
@@ -75,7 +75,7 @@
function AddChild(&$a_child)
{
- $this->Children[$a_child->Name] =& $a_child;
+ $this->Children[] =& $a_child;
$a_child->SetParent($this);
}
@@ -108,11 +108,11 @@
{
$name = strtoupper($name);
if ($this->Name == $name) return $this;
- if (isset($this->Children[$name])) return $this->Children[$name];
- $children_names = array_keys($this->Children);
- foreach ($children_names as $a_name)
+// if (isset($this->Children[$name])) return $this->Children[$name];
+// $children = array_keys($this->Children);
+ foreach ($this->Children as $elem)
{
- $child =& $this->Children[$a_name]->FindChild($name);
+ $child =& $elem->FindChild($name);
if ($child !== false)
{
return $child;
Index: branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php
===================================================================
diff -u -r3924 -r4354
--- branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php (.../xml_helper.php) (revision 3924)
+++ branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php (.../xml_helper.php) (revision 4354)
@@ -75,7 +75,7 @@
function AddChild(&$a_child)
{
- $this->Children[$a_child->Name] =& $a_child;
+ $this->Children[] =& $a_child;
$a_child->SetParent($this);
}
@@ -108,11 +108,11 @@
{
$name = strtoupper($name);
if ($this->Name == $name) return $this;
- if (isset($this->Children[$name])) return $this->Children[$name];
- $children_names = array_keys($this->Children);
- foreach ($children_names as $a_name)
+// if (isset($this->Children[$name])) return $this->Children[$name];
+// $children = array_keys($this->Children);
+ foreach ($this->Children as $elem)
{
- $child =& $this->Children[$a_name]->FindChild($name);
+ $child =& $elem->FindChild($name);
if ($child !== false)
{
return $child;
Index: branches/unlabeled/unlabeled-1.37.2/core/kernel/processors/main_processor.php
===================================================================
diff -u -r4226 -r4354
--- branches/unlabeled/unlabeled-1.37.2/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 4226)
+++ branches/unlabeled/unlabeled-1.37.2/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 4354)
@@ -1,864 +1,876 @@
-Application->recallObject('kActions');
- $actions->Set('t', $this->Application->GetVar('t'));
- $actions->Set('sid', $this->Application->GetSID());
- $actions->Set('m_opener', $this->Application->GetVar('m_opener') );
-
- }
-
- /**
- * Used to handle calls where tag name
- * match with existing php function name
- *
- * @param Tag $tag
- * @return string
- */
- function ProcessTag(&$tag)
- {
- if ($tag->Tag=='include') $tag->Tag='MyInclude';
- return parent::ProcessTag($tag);
- }
-
- /**
- * Creates HTML tag for all templates
- * affects future css, js files and href params of links
- *
- * @return string
- * @access public
- */
- function Base_Ref()
- {
- $url = $this->Application->BaseURL().substr(THEMES_PATH,1).'/';
- return '';
- }
-
- /**
- * Returns base url for web-site
- *
- * @return string
- * @access public
- */
- function BaseURL()
- {
- return $this->Application->BaseURL();
- }
-
- function TemplatesBase($params)
- {
- return $this->Application->BaseURL().THEMES_PATH;
- }
-
- function ProjectBase($params)
- {
- return $this->Application->BaseURL();
- }
-
- /*function Base($params)
- {
- return $this->Application->BaseURL().$params['add'];
- }*/
-
- /**
- * Used to create link to any template.
- * use "pass" paramter if "t" tag to specify
- * prefix & special of object to be represented
- * in resulting url
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function T($params)
- {
- //by default link to current template
- $t = $this->SelectParam($params, 't,template');
- unset($params['t']);
- unset($params['template']);
- $prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']);
- $index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']);
-
- return $this->Application->HREF($t, $prefix, $params, $index_file);
- }
-
- function Link($params)
- {
- if (isset($params['template'])) {
- $params['t'] = $params['template'];
- unset($params['template']);
- }
- if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm';
- if (isset($params['no_pass'])) unset($params['no_pass']);
-
- if( $this->Application->GetVar('admin') ) $params['admin'] = 1;
-
- return $this->T($params);
- }
-
- function Env($params)
- {
- $t = $params['template'];
- unset($params['template']);
- return $this->Application->BuildEnv($t, $params, 'm', null, false);
- }
-
- function FormAction($params)
- {
- return $this->Application->ProcessParsedTag('m', 't', Array( 'pass'=>'all,m' ) );
- }
-
- /*// NEEDS TEST
- function Config($params)
- {
- return $this->Application->ConfigOption($params['var']);
- }
-
- function Object($params)
- {
- $name = $params['name'];
- $method = $params['method'];
-
- $tmp =& $this->Application->recallObject($name);
- if ($tmp != null) {
- if (method_exists($tmp, $method))
- return $tmp->$method($params);
- else
- echo "Method $method does not exist in object ".get_class($tmp)." named $name
";
- }
- else
- echo "Object $name does not exist in the appliaction
";
- }*/
-
- /**
- * Tag, that always returns true.
- * For parser testing purposes
- *
- * @param Array $params
- * @return bool
- * @access public
- */
- function True($params)
- {
- return true;
- }
-
- /**
- * Tag, that always returns false.
- * For parser testing purposes
- *
- * @param Array $params
- * @return bool
- * @access public
- */
- function False($params)
- {
- return false;
- }
-
- /**
- * Returns block parameter by name
- *
- * @param Array $params
- * @return stirng
- * @access public
- */
- function Param($params)
- {
- //$parser =& $this->Application->recallObject('TemplateParser');
- $res = $this->Application->Parser->GetParam($params['name']);
- if ($res === false) $res = '';
- if (isset($params['plus']))
- $res += $params['plus'];
- return $res;
- }
-
- /**
- * Gets value of specified field from specified prefix_special and set it as parser param
- *
- * @param Array $params
- */
- /*function SetParam($params)
- {
- //
- list($prefix_special, $field_name) = explode(':', $params['src']);
-
- $object =& $this->Application->recallObject($prefix_special);
- $name = $this->SelectParam($params, 'param,name,var');
-
- $this->Application->Parser->SetParam($name, $object->GetField($field_name) );
- }*/
-
- /**
- * Compares block parameter with value specified
- *
- * @param Array $params
- * @return bool
- * @access public
- */
- function ParamEquals($params)
- {
- //$parser =& $this->Application->recallObject('TemplateParser');
- $name = $this->SelectParam($params, 'name,var,param');
- $value = $params['value'];
- return ($this->Application->Parser->GetParam($name) == $value);
- }
-
- /*function PHP_Self($params)
- {
- return $HTTP_SERVER_VARS['PHP_SELF'];
- }
- */
-
- /**
- * Returns session variable value by name
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function Recall($params)
- {
- $ret = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
- $ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
- if( getArrayValue($params,'special') || getArrayValue($params,'htmlchars')) $ret = htmlspecialchars($ret);
-
- if ( getArrayValue($params, 'urlencode') ) $ret = urlencode($ret);
-
- return $ret;
- }
-
- // bad style to store something from template to session !!! (by Alex)
- // Used here only to test how session works, nothing more
- function Store($params)
- {
- //echo"Store $params[name]
";
- $name = $params['name'];
- $value = $params['value'];
- $this->Application->StoreVar($name,$value);
- }
-
- /**
- * Sets application variable value(-s)
- *
- * @param Array $params
- * @access public
- */
- function Set($params)
- {
- foreach ($params as $param => $value) {
- $this->Application->SetVar($param, $value);
- }
- }
-
- /**
- * Increment application variable
- * specified by number specified
- *
- * @param Array $params
- * @access public
- */
- function Inc($params)
- {
- $this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']);
- }
-
- /**
- * Retrieves application variable
- * value by name
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function Get($params)
- {
- $ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), '');
- return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
- }
-
- /**
- * Retrieves application constant
- * value by name
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function GetConst($params)
- {
- return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : '';
- }
-
- /**
- * Retrieves configuration variable value by name
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function GetConfig($params)
- {
- $config_name = $this->SelectParam($params, 'name,var');
- $ret = $this->Application->ConfigValue($config_name);
- if( getArrayValue($params, 'escape') ) $ret = addslashes($ret);
- return $ret;
- }
-
- function ConfigEquals($params)
- {
- $option = $this->SelectParam($params, 'name,option,var');
- return $this->Application->ConfigValue($option) == getArrayValue($params, 'value');
- }
-
- /**
- * Creates all hidden fields
- * needed for kernel_form
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function DumpSystemInfo($params)
- {
- $actions =& $this->Application->recallObject('kActions');
- $actions->Set('t', $this->Application->GetVar('t') );
-
- $params = $actions->GetParams();
- $o='';
- foreach ($params AS $name => $val)
- {
- $o .= "\n";
- }
- return $o;
- }
-
- function GetFormHiddens($params)
- {
- $sid = $this->Application->GetSID();
- $t = $this->SelectParam($params, 'template,t');
- unset($params['template']);
- $env = $this->Application->BuildEnv($t, $params, 'm', null, false);
- $o = '';
- if ( $this->Application->RewriteURLs() )
- {
- $session =& $this->Application->recallObject('Session');
- if ($session->NeedQueryString()) {
- $o .= "\n";
- }
- }
- else {
- $o .= "\n";
- }
- return $o;
- }
-
- function Odd_Even($params)
- {
- $odd = $params['odd'];
- $even = $params['even'];
- if (!isset($params['var'])) {
- $var = 'odd_even';
- }
- else {
- $var = $params['var'];
- }
-
- if ($this->Application->GetVar($var) == 'even') {
- if (!isset($params['readonly']) || !$params['readonly']) {
- $this->Application->SetVar($var, 'odd');
- }
- return $even;
- }
- else {
- if (!isset($params['readonly']) || !$params['readonly']) {
- $this->Application->SetVar($var, 'even');
- }
- return $odd;
- }
- }
-
- /**
- * Returns phrase translation by name
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function Phrase($params)
- {
- // m:phrase name="phrase_name" default="Tr-alala" updated="2004-01-29 12:49"
- if (array_key_exists('default', $params)) return $params['default']; //backward compatibility
- $translation = $this->Application->Phrase($this->SelectParam($params, 'label,name,title'));
- if (getArrayValue($params, 'escape')) {
- $translation = htmlspecialchars($translation);
- $translation = str_replace('\'', ''', $translation);
- $translation = addslashes($translation);
- }
- return $translation;
- }
-
- // for tabs
- function is_active($params)
- {
- $test_templ = $this->SelectParam($params, 'templ,template,t');
- if ( !getArrayValue($params,'allow_empty') )
- {
- $if_true=getArrayValue($params,'true') ? $params['true'] : 1;
- $if_false=getArrayValue($params,'false') ? $params['false'] : 0;
- }
- else
- {
- $if_true=$params['true'];
- $if_false=$params['false'];
- }
-
- if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/", $this->Application->GetVar('t'))) {
- return $if_true;
- }
- else {
- return $if_false;
- }
- }
-
- function IsNotActive($params)
- {
- return !$this->is_active($params);
- }
-
- function IsActive($params)
- {
- return $this->is_active($params);
- }
-
- function is_t_active($params)
- {
- return $this->is_active($params);
- }
-
- function CurrentTemplate($params)
- {
- return $this->is_active($params);
- }
-
- /**
- * Checks if session variable
- * specified by name value match
- * value passed as parameter
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function RecallEquals($params)
- {
- $name = $params['var'];
- $value = $params['value'];
- return ($this->Application->RecallVar($name) == $value);
- }
-
- /**
- * Checks if application variable
- * specified by name value match
- * value passed as parameter
- *
- * @param Array $params
- * @return bool
- * @access public
- */
- function GetEquals($params)
- {
- $name = $this->SelectParam($params, 'var,name,param');
- $value = $params['value'];
- if ($this->Application->GetVar($name) == $value) {
- return 1;
- }
- }
-
- /**
- * Includes template
- * and returns it's
- * parsed version
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function MyInclude($params)
- {
- $BlockParser =& $this->Application->makeClass('TemplateParser');
- $BlockParser->SetParams($params);
- $parser =& $this->Application->Parser;
- $this->Application->Parser =& $BlockParser;
-
- $t = $this->SelectParam($params, 't,template,block,name');
- $t = eregi_replace("\.tpl$", '', $t);
-
- $templates_cache =& $this->Application->recallObject('TemplatesCache');
-
- $res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t), $t );
-
- if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) {
- if ($block_no_data = getArrayValue($params, 'block_no_data')) {
- $res = $BlockParser->Parse(
- $templates_cache->GetTemplateBody($block_no_data, $silent),
- $t
- );
- }
- else {
- $res = '';
- }
- }
- $this->Application->Parser =& $parser;
- $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
- return $res;
- }
-
- /*function Kernel_Scripts($params)
- {
- return '';
- }*/
-
-
- /*function GetUserPermission($params)
- {
- // echo"GetUserPermission $params[name]";
- if ($this->Application->RecallVar('user_type') == 1)
- return 1;
- else {
- $perm_name = $params[name];
- $aPermissions = unserialize($this->Application->RecallVar('user_permissions'));
- if ($aPermissions)
- return $aPermissions[$perm_name];
- }
- }*/
-
-
- /**
- * Set's parser block param value
- *
- * @param Array $params
- * @access public
- */
- function AddParam($params)
- {
- $parser =& $this->Application->Parser; // recallObject('TemplateParser');
- foreach ($params as $param => $value) {
- $this->Application->SetVar($param, $value);
- $parser->SetParam($param, $value);
- $parser->AddParam('/\$'.$param.'/', $value);
- }
- }
-
- /*function ParseToVar($params)
- {
- $var = $params['var'];
- $tagdata = $params['tag'];
- $parser =& $this->Application->Parser; //recallObject('TemplateParser');
- $res = $this->Application->ProcessTag($tagdata);
-
- $parser->SetParam($var, $res);
- $parser->AddParam('/\$'.$var.'/', $res);
- return '';
- }*/
-
- /*function TagNotEmpty($params)
- {
- $tagdata = $params['tag'];
- $res = $this->Application->ProcessTag($tagdata);
- return $res != '';
- }*/
-
- /*function TagEmpty($params)
- {
- return !$this->TagNotEmpty($params);
- }*/
-
- /**
- * Parses block and returns result
- *
- * @param Array $params
- * @return string
- * @access public
- */
- function ParseBlock($params)
- {
- $parser =& $this->Application->Parser; // recallObject('TemplateParser');
- return $parser->ParseBlock($params);
- }
-
- function RenderElement($params)
- {
- return $this->ParseBlock($params);
- }
-
- /**
- * Checks if debug mode is on
- *
- * @return bool
- * @access public
- */
- function IsDebugMode()
- {
- return $this->Application->isDebugMode();
- }
-
- function MassParse($params)
- {
- $qty = $params['qty'];
- $block = $params['block'];
- $mode = $params['mode'];
-
- $o = '';
- if ($mode == 'func') {
- $func = create_function('$params', '
- $o = \'\';
- $o.= \'a\'.$params[\'param1\'].\' | \';
- $o.= \'a\'.$params[\'param2\'].\' | \';
- $o.= \'a\'.$params[\'param3\'].\' | \';
- $o.= \'a\'.$params[\'param4\'].\' | \';
- $o.= \'
\';
- return $o;
- ');
- for ($i=1; $i<$qty; $i++) {
- $block_params['param1'] = rand(1, 10000);
- $block_params['param2'] = rand(1, 10000);
- $block_params['param3'] = rand(1, 10000);
- $block_params['param4'] = rand(1, 10000);
- $o .= $func($block_params);
- }
- return $o;
- }
-
- $block_params['name'] = $block;
-
- for ($i=0; $i<$qty; $i++) {
- $block_params['param1'] = rand(1, 10000);
- $block_params['param2'] = rand(1, 10000);
- $block_params['param3'] = rand(1, 10000);
- $block_params['param4'] = rand(1, 10000);
- $block_params['passed'] = $params['passed'];
- $block_params['prefix'] = 'm';
-
- $o.= $this->Application->ParseBlock($block_params, 1);
- }
- return $o;
- }
-
- function AfterScript($params)
- {
- $after_script = $this->Application->GetVar('after_script');
- if ( $after_script ) {
- return '';
- }
- return '';
- }
-
- function LoggedIn($params)
- {
- return $this->Application->LoggedIn();
- }
-
- /**
- * Checks if user is logged in and if not redirects it to template passed
- *
- * @param Array $params
- */
- function RequireLogin($params)
- {
- if($permission_groups = getArrayValue($params, 'permissions'))
- {
- $permission_groups = explode('|', $permission_groups);
- $group_has_permission = false;
- foreach($permission_groups as $permission_group)
- {
- $permissions = explode(',', $permission_group);
- $has_permission = true;
- foreach($permissions as $permission)
- {
- $has_permission = $has_permission && $this->Application->CheckPermission($permission);
- }
- $group_has_permission = $group_has_permission || $has_permission;
-
- if($group_has_permission)
- {
- return;
- }
- }
-
- if( !$this->Application->LoggedIn() )
- {
- $t = $this->Application->GetVar('t');
- $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
- }
- else
- {
- $this->Application->Redirect( $params['no_permissions_template'] );
- }
- }
-
- $condition = getArrayValue($params,'condition');
- if(!$condition)
- {
- $condition = true;
- }
- else
- {
- if( substr($condition,0,1) == '!' )
- {
- $condition = !$this->Application->ConfigValue( substr($condition,1) );
- }
- else
- {
- $condition = $this->Application->ConfigValue($condition);
- }
- }
-
- $group = $this->SelectParam($params, 'group');
- $group_access = true;
- if ($group) {
- $conn =& $this->Application->DB;
- $group_id = $conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'PortalGroup WHERE Name = '.$conn->qstr($group));
- if ($group_id) {
- $groups = explode(',', $this->Application->RecallVar('UserGroups'));
- $group_access = in_array($group_id, $groups);
- }
- }
-
- if( (!$this->Application->LoggedIn() || !$group_access) && $condition )
- {
- $t = $this->Application->GetVar('t');
- $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
- }
- }
-
- /**
- * Checks if SSL is on and redirects to SSL URL if needed
- * If SSL_URL is not defined in config - the tag does not do anything
- * If for_logged_in_only="1" exits if user is not logged in.
- * If called without params forces https right away. If called with by_config="1" checks the
- * Require SSL setting from General Config and if it is ON forces https
- *
- * @param unknown_type $params
- */
- function CheckSSL($params)
- {
- $ssl = $this->Application->ConfigValue('SSL_URL');
- if (!$ssl) return; //SSL URL is not set - no way to require SSL
-
- $require = false;
-
- if ($params['mode'] == 'required') {
- $require = true;
- if (isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn()) {
- $require = false;
- }
-
- if (isset($params['condition'])) {
- if (!$this->Application->ConfigValue($params['condition'])) {
- $require = false;
- }
- }
- }
-
- $http_query =& $this->Application->recallObject('HTTPQuery');
- $pass = $http_query->getRedirectParams();
-
- if ($require) {
- if (PROTOCOL == 'https://') {
- $this->Application->SetVar('__KEEP_SSL__', 1);
- return;
- }
- $this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 1)));
- }
- else {
- if (PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required')) {
- if ($this->Application->GetVar('__KEEP_SSL__')) return;
- $this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 0)));
- }
- }
- }
-
- function SaveReturnScript($params)
- {
- // admin/save_redirect.php?do=
- $url = str_replace($this->Application->BaseURL(), '', $this->T($params) );
- $url = explode('?', $url, 2);
- $url = 'save_redirect.php?'.$url[1].'&do='.$url[0];
-
- $this->Application->StoreVar('ReturnScript', $url);
- }
-
- function ConstOn($params)
- {
- $name = $this->SelectParam($params,'name,const');
- return $this->Application->isDebugMode() && dbg_ConstOn($name);
- }
-
- function SetDefaultCategory($params)
- {
- $module_name = $params['module'];
- $module =& $this->Application->recallObject('mod.'.$module_name);
- $this->Application->SetVar('m_cat_id', $module->GetDBField('RootCat') );
- }
-
- function ImportRedirect($params)
- {
- $import_id = $this->Application->GetVar('import_id');
- if ($import_id) {
- // redirect forward to step3 (import parameters coosing)
- $this->Application->StoreVar('ImportScriptID', $import_id);
-
- $sql = 'SELECT *
- FROM '.TABLE_PREFIX.'ImportScripts
- WHERE is_id = '.$import_id;
-
- $db =& $this->Application->GetADODBConnection();
- $is_params = $db->GetRow($sql);
-
- if ($is_params['is_type'] == 'db') {
- $this->Application->Redirect('', null, '', 'import/step3.php');
- }
- elseif ($is_params['is_type'] == 'csv') {
- $module = strtolower($is_params['is_Module']);
- $template = $module.'/import';
- $sql = 'SELECT Var
- FROM '.TABLE_PREFIX.'Modules
- WHERE LOWER(Name) = '.$db->qstr($module);
- $item_prefix = $db->GetOne($sql);
- $pass_params = Array('m_opener' => 'd', $item_prefix.'.import_id' => 0, $item_prefix.'.import_event' => 'OnNew', 'pass' => 'm,'.$item_prefix.'.import');
- $this->Application->Redirect($template, $pass_params);
- }
- }
- else {
- // redirect back to step2 (import type choosing)
- $this->Application->Redirect('', null, '', 'import/step2.php');
- }
- }
-
- function GetSectionTitle($params)
- {
- $params['name'] = replaceModuleSection($params['phrase']);
- return $this->Phrase($params);
- }
-
- function GetSectionIcon($params)
- {
- return replaceModuleSection($params['icon']);
- }
-
- function StoreSystemVars($params)
- {
- // save theese variables to session, because they are useful for most configuration templates
- $this->Application->LinkVar('module');
- $this->Application->LinkVar('section');
- }
-}
-
-
-?>
+Application->recallObject('kActions');
+ $actions->Set('t', $this->Application->GetVar('t'));
+ $actions->Set('sid', $this->Application->GetSID());
+ $actions->Set('m_opener', $this->Application->GetVar('m_opener') );
+
+ }
+
+ /**
+ * Used to handle calls where tag name
+ * match with existing php function name
+ *
+ * @param Tag $tag
+ * @return string
+ */
+ function ProcessTag(&$tag)
+ {
+ if ($tag->Tag=='include') $tag->Tag='MyInclude';
+ return parent::ProcessTag($tag);
+ }
+
+ /**
+ * Creates HTML tag for all templates
+ * affects future css, js files and href params of links
+ *
+ * @return string
+ * @access public
+ */
+ function Base_Ref()
+ {
+ $url = $this->Application->BaseURL().substr(THEMES_PATH,1).'/';
+ return '';
+ }
+
+ /**
+ * Returns base url for web-site
+ *
+ * @return string
+ * @access public
+ */
+ function BaseURL()
+ {
+ return $this->Application->BaseURL();
+ }
+
+ function TemplatesBase($params)
+ {
+ return $this->Application->BaseURL().THEMES_PATH;
+ }
+
+ function ProjectBase($params)
+ {
+ return $this->Application->BaseURL();
+ }
+
+ /*function Base($params)
+ {
+ return $this->Application->BaseURL().$params['add'];
+ }*/
+
+ /**
+ * Used to create link to any template.
+ * use "pass" paramter if "t" tag to specify
+ * prefix & special of object to be represented
+ * in resulting url
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function T($params)
+ {
+ //by default link to current template
+ $t = $this->SelectParam($params, 't,template');
+ unset($params['t']);
+ unset($params['template']);
+ $prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']);
+ $index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']);
+
+ return $this->Application->HREF($t, $prefix, $params, $index_file);
+ }
+
+ function Link($params)
+ {
+ if (isset($params['template'])) {
+ $params['t'] = $params['template'];
+ unset($params['template']);
+ }
+ if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm';
+ if (isset($params['no_pass'])) unset($params['no_pass']);
+
+ if( $this->Application->GetVar('admin') ) $params['admin'] = 1;
+
+ return $this->T($params);
+ }
+
+ function Env($params)
+ {
+ $t = $params['template'];
+ unset($params['template']);
+ return $this->Application->BuildEnv($t, $params, 'm', null, false);
+ }
+
+ function FormAction($params)
+ {
+ return $this->Application->ProcessParsedTag('m', 't', Array( 'pass'=>'all,m' ) );
+ }
+
+ /*// NEEDS TEST
+ function Config($params)
+ {
+ return $this->Application->ConfigOption($params['var']);
+ }
+
+ function Object($params)
+ {
+ $name = $params['name'];
+ $method = $params['method'];
+
+ $tmp =& $this->Application->recallObject($name);
+ if ($tmp != null) {
+ if (method_exists($tmp, $method))
+ return $tmp->$method($params);
+ else
+ echo "Method $method does not exist in object ".get_class($tmp)." named $name
";
+ }
+ else
+ echo "Object $name does not exist in the appliaction
";
+ }*/
+
+ /**
+ * Tag, that always returns true.
+ * For parser testing purposes
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function True($params)
+ {
+ return true;
+ }
+
+ /**
+ * Tag, that always returns false.
+ * For parser testing purposes
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function False($params)
+ {
+ return false;
+ }
+
+ /**
+ * Returns block parameter by name
+ *
+ * @param Array $params
+ * @return stirng
+ * @access public
+ */
+ function Param($params)
+ {
+ //$parser =& $this->Application->recallObject('TemplateParser');
+ $res = $this->Application->Parser->GetParam($params['name']);
+ if ($res === false) $res = '';
+ if (isset($params['plus']))
+ $res += $params['plus'];
+ return $res;
+ }
+
+ /**
+ * Gets value of specified field from specified prefix_special and set it as parser param
+ *
+ * @param Array $params
+ */
+ /*function SetParam($params)
+ {
+ //
+ list($prefix_special, $field_name) = explode(':', $params['src']);
+
+ $object =& $this->Application->recallObject($prefix_special);
+ $name = $this->SelectParam($params, 'param,name,var');
+
+ $this->Application->Parser->SetParam($name, $object->GetField($field_name) );
+ }*/
+
+ /**
+ * Compares block parameter with value specified
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function ParamEquals($params)
+ {
+ //$parser =& $this->Application->recallObject('TemplateParser');
+ $name = $this->SelectParam($params, 'name,var,param');
+ $value = $params['value'];
+ return ($this->Application->Parser->GetParam($name) == $value);
+ }
+
+ /*function PHP_Self($params)
+ {
+ return $HTTP_SERVER_VARS['PHP_SELF'];
+ }
+ */
+
+ /**
+ * Returns session variable value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Recall($params)
+ {
+ $ret = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
+ $ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
+ if( getArrayValue($params,'special') || getArrayValue($params,'htmlchars')) $ret = htmlspecialchars($ret);
+
+ if ( getArrayValue($params, 'urlencode') ) $ret = urlencode($ret);
+
+ return $ret;
+ }
+
+ // bad style to store something from template to session !!! (by Alex)
+ // Used here only to test how session works, nothing more
+ function Store($params)
+ {
+ //echo"Store $params[name]
";
+ $name = $params['name'];
+ $value = $params['value'];
+ $this->Application->StoreVar($name,$value);
+ }
+
+ /**
+ * Sets application variable value(-s)
+ *
+ * @param Array $params
+ * @access public
+ */
+ function Set($params)
+ {
+ foreach ($params as $param => $value) {
+ $this->Application->SetVar($param, $value);
+ }
+ }
+
+ /**
+ * Increment application variable
+ * specified by number specified
+ *
+ * @param Array $params
+ * @access public
+ */
+ function Inc($params)
+ {
+ $this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']);
+ }
+
+ /**
+ * Retrieves application variable
+ * value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Get($params)
+ {
+ $ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), '');
+ return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
+ }
+
+ /**
+ * Retrieves application constant
+ * value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function GetConst($params)
+ {
+ return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : '';
+ }
+
+ /**
+ * Retrieves configuration variable value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function GetConfig($params)
+ {
+ $config_name = $this->SelectParam($params, 'name,var');
+ $ret = $this->Application->ConfigValue($config_name);
+ if( getArrayValue($params, 'escape') ) $ret = addslashes($ret);
+ return $ret;
+ }
+
+ function ConfigEquals($params)
+ {
+ $option = $this->SelectParam($params, 'name,option,var');
+ return $this->Application->ConfigValue($option) == getArrayValue($params, 'value');
+ }
+
+ /**
+ * Creates all hidden fields
+ * needed for kernel_form
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function DumpSystemInfo($params)
+ {
+ $actions =& $this->Application->recallObject('kActions');
+ $actions->Set('t', $this->Application->GetVar('t') );
+
+ $params = $actions->GetParams();
+ $o='';
+ foreach ($params AS $name => $val)
+ {
+ $o .= "\n";
+ }
+ return $o;
+ }
+
+ function GetFormHiddens($params)
+ {
+ $sid = $this->Application->GetSID();
+ $t = $this->SelectParam($params, 'template,t');
+ unset($params['template']);
+ $env = $this->Application->BuildEnv($t, $params, 'm', null, false);
+ $o = '';
+ if ( $this->Application->RewriteURLs() )
+ {
+ $session =& $this->Application->recallObject('Session');
+ if ($session->NeedQueryString()) {
+ $o .= "\n";
+ }
+ }
+ else {
+ $o .= "\n";
+ }
+ return $o;
+ }
+
+ function Odd_Even($params)
+ {
+ $odd = $params['odd'];
+ $even = $params['even'];
+ if (!isset($params['var'])) {
+ $var = 'odd_even';
+ }
+ else {
+ $var = $params['var'];
+ }
+
+ if ($this->Application->GetVar($var) == 'even') {
+ if (!isset($params['readonly']) || !$params['readonly']) {
+ $this->Application->SetVar($var, 'odd');
+ }
+ return $even;
+ }
+ else {
+ if (!isset($params['readonly']) || !$params['readonly']) {
+ $this->Application->SetVar($var, 'even');
+ }
+ return $odd;
+ }
+ }
+
+ /**
+ * Returns phrase translation by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Phrase($params)
+ {
+ // m:phrase name="phrase_name" default="Tr-alala" updated="2004-01-29 12:49"
+ if (array_key_exists('default', $params)) return $params['default']; //backward compatibility
+ $translation = $this->Application->Phrase($this->SelectParam($params, 'label,name,title'));
+ if (getArrayValue($params, 'escape')) {
+ $translation = htmlspecialchars($translation);
+ $translation = str_replace('\'', ''', $translation);
+ $translation = addslashes($translation);
+ }
+ return $translation;
+ }
+
+ // for tabs
+ function is_active($params)
+ {
+ $test_templ = $this->SelectParam($params, 'templ,template,t');
+ if ( !getArrayValue($params,'allow_empty') )
+ {
+ $if_true=getArrayValue($params,'true') ? $params['true'] : 1;
+ $if_false=getArrayValue($params,'false') ? $params['false'] : 0;
+ }
+ else
+ {
+ $if_true=$params['true'];
+ $if_false=$params['false'];
+ }
+
+ if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/", $this->Application->GetVar('t'))) {
+ return $if_true;
+ }
+ else {
+ return $if_false;
+ }
+ }
+
+ function IsNotActive($params)
+ {
+ return !$this->is_active($params);
+ }
+
+ function IsActive($params)
+ {
+ return $this->is_active($params);
+ }
+
+ function is_t_active($params)
+ {
+ return $this->is_active($params);
+ }
+
+ function CurrentTemplate($params)
+ {
+ return $this->is_active($params);
+ }
+
+ /**
+ * Checks if session variable
+ * specified by name value match
+ * value passed as parameter
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function RecallEquals($params)
+ {
+ $name = $params['var'];
+ $value = $params['value'];
+ return ($this->Application->RecallVar($name) == $value);
+ }
+
+ /**
+ * Checks if application variable
+ * specified by name value match
+ * value passed as parameter
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function GetEquals($params)
+ {
+ $name = $this->SelectParam($params, 'var,name,param');
+ $value = $params['value'];
+ if ($this->Application->GetVar($name) == $value) {
+ return 1;
+ }
+ }
+
+ /**
+ * Includes template
+ * and returns it's
+ * parsed version
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function MyInclude($params)
+ {
+ $BlockParser =& $this->Application->makeClass('TemplateParser');
+ $BlockParser->SetParams($params);
+ $parser =& $this->Application->Parser;
+ $this->Application->Parser =& $BlockParser;
+
+ $t = $this->SelectParam($params, 't,template,block,name');
+ $t = eregi_replace("\.tpl$", '', $t);
+
+ $templates_cache =& $this->Application->recallObject('TemplatesCache');
+
+ $res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t), $t );
+
+ if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) {
+ if ($block_no_data = getArrayValue($params, 'block_no_data')) {
+ $res = $BlockParser->Parse(
+ $templates_cache->GetTemplateBody($block_no_data, $silent),
+ $t
+ );
+ }
+ else {
+ $res = '';
+ }
+ }
+ $this->Application->Parser =& $parser;
+ $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
+ return $res;
+ }
+
+ /*function Kernel_Scripts($params)
+ {
+ return '';
+ }*/
+
+
+ /*function GetUserPermission($params)
+ {
+ // echo"GetUserPermission $params[name]";
+ if ($this->Application->RecallVar('user_type') == 1)
+ return 1;
+ else {
+ $perm_name = $params[name];
+ $aPermissions = unserialize($this->Application->RecallVar('user_permissions'));
+ if ($aPermissions)
+ return $aPermissions[$perm_name];
+ }
+ }*/
+
+
+ /**
+ * Set's parser block param value
+ *
+ * @param Array $params
+ * @access public
+ */
+ function AddParam($params)
+ {
+ $parser =& $this->Application->Parser; // recallObject('TemplateParser');
+ foreach ($params as $param => $value) {
+ $this->Application->SetVar($param, $value);
+ $parser->SetParam($param, $value);
+ $parser->AddParam('/\$'.$param.'/', $value);
+ }
+ }
+
+ /*function ParseToVar($params)
+ {
+ $var = $params['var'];
+ $tagdata = $params['tag'];
+ $parser =& $this->Application->Parser; //recallObject('TemplateParser');
+ $res = $this->Application->ProcessTag($tagdata);
+
+ $parser->SetParam($var, $res);
+ $parser->AddParam('/\$'.$var.'/', $res);
+ return '';
+ }*/
+
+ /*function TagNotEmpty($params)
+ {
+ $tagdata = $params['tag'];
+ $res = $this->Application->ProcessTag($tagdata);
+ return $res != '';
+ }*/
+
+ /*function TagEmpty($params)
+ {
+ return !$this->TagNotEmpty($params);
+ }*/
+
+ /**
+ * Parses block and returns result
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function ParseBlock($params)
+ {
+ $parser =& $this->Application->Parser; // recallObject('TemplateParser');
+ return $parser->ParseBlock($params);
+ }
+
+ function RenderElement($params)
+ {
+ return $this->ParseBlock($params);
+ }
+
+ /**
+ * Checks if debug mode is on
+ *
+ * @return bool
+ * @access public
+ */
+ function IsDebugMode()
+ {
+ return $this->Application->isDebugMode();
+ }
+
+ function MassParse($params)
+ {
+ $qty = $params['qty'];
+ $block = $params['block'];
+ $mode = $params['mode'];
+
+ $o = '';
+ if ($mode == 'func') {
+ $func = create_function('$params', '
+ $o = \'\';
+ $o.= \'a\'.$params[\'param1\'].\' | \';
+ $o.= \'a\'.$params[\'param2\'].\' | \';
+ $o.= \'a\'.$params[\'param3\'].\' | \';
+ $o.= \'a\'.$params[\'param4\'].\' | \';
+ $o.= \'
\';
+ return $o;
+ ');
+ for ($i=1; $i<$qty; $i++) {
+ $block_params['param1'] = rand(1, 10000);
+ $block_params['param2'] = rand(1, 10000);
+ $block_params['param3'] = rand(1, 10000);
+ $block_params['param4'] = rand(1, 10000);
+ $o .= $func($block_params);
+ }
+ return $o;
+ }
+
+ $block_params['name'] = $block;
+
+ for ($i=0; $i<$qty; $i++) {
+ $block_params['param1'] = rand(1, 10000);
+ $block_params['param2'] = rand(1, 10000);
+ $block_params['param3'] = rand(1, 10000);
+ $block_params['param4'] = rand(1, 10000);
+ $block_params['passed'] = $params['passed'];
+ $block_params['prefix'] = 'm';
+
+ $o.= $this->Application->ParseBlock($block_params, 1);
+ }
+ return $o;
+ }
+
+ function AfterScript($params)
+ {
+ $after_script = $this->Application->GetVar('after_script');
+ if ( $after_script ) {
+ return '';
+ }
+ return '';
+ }
+
+ function LoggedIn($params)
+ {
+ return $this->Application->LoggedIn();
+ }
+
+ /**
+ * Checks if user is logged in and if not redirects it to template passed
+ *
+ * @param Array $params
+ */
+ function RequireLogin($params)
+ {
+ $t = $this->Application->GetVar('t');
+ if ($next_t = getArrayValue($params, 'next_template')) {
+ $t = $next_t;
+ }
+
+ if($permission_groups = getArrayValue($params, 'permissions'))
+ {
+ $permission_groups = explode('|', $permission_groups);
+ $group_has_permission = false;
+ foreach($permission_groups as $permission_group)
+ {
+ $permissions = explode(',', $permission_group);
+ $has_permission = true;
+ foreach($permissions as $permission)
+ {
+ $has_permission = $has_permission && $this->Application->CheckPermission($permission);
+ }
+ $group_has_permission = $group_has_permission || $has_permission;
+
+ if($group_has_permission)
+ {
+ return;
+ }
+ }
+
+ if( !$this->Application->LoggedIn() )
+ {
+ $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
+ }
+ else
+ {
+ $this->Application->Redirect( $params['no_permissions_template'] );
+ }
+ }
+
+ $condition = getArrayValue($params,'condition');
+ if(!$condition)
+ {
+ $condition = true;
+ }
+ else
+ {
+ if( substr($condition,0,1) == '!' )
+ {
+ $condition = !$this->Application->ConfigValue( substr($condition,1) );
+ }
+ else
+ {
+ $condition = $this->Application->ConfigValue($condition);
+ }
+ }
+
+ $group = $this->SelectParam($params, 'group');
+ $group_access = true;
+ if ($group) {
+ $conn =& $this->Application->DB;
+ $group_id = $conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'PortalGroup WHERE Name = '.$conn->qstr($group));
+ if ($group_id) {
+ $groups = explode(',', $this->Application->RecallVar('UserGroups'));
+ $group_access = in_array($group_id, $groups);
+ }
+ }
+
+ if( (!$this->Application->LoggedIn() || !$group_access) && $condition )
+ {
+ if ( $this->Application->LoggedIn() && !$group_access) {
+ $this->Application->Redirect( $params['no_group_perm_template'], Array('next_template'=>$t) );
+ }
+ $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
+ }
+ }
+
+ /**
+ * Checks if SSL is on and redirects to SSL URL if needed
+ * If SSL_URL is not defined in config - the tag does not do anything
+ * If for_logged_in_only="1" exits if user is not logged in.
+ * If called without params forces https right away. If called with by_config="1" checks the
+ * Require SSL setting from General Config and if it is ON forces https
+ *
+ * @param unknown_type $params
+ */
+ function CheckSSL($params)
+ {
+ $ssl = $this->Application->ConfigValue('SSL_URL');
+ if (!$ssl) return; //SSL URL is not set - no way to require SSL
+
+ $require = false;
+
+ if ($params['mode'] == 'required') {
+ $require = true;
+ if (isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn()) {
+ $require = false;
+ }
+
+ if (isset($params['condition'])) {
+ if (!$this->Application->ConfigValue($params['condition'])) {
+ $require = false;
+ }
+ }
+ }
+
+ $http_query =& $this->Application->recallObject('HTTPQuery');
+ $pass = $http_query->getRedirectParams();
+
+ if ($require) {
+ if (PROTOCOL == 'https://') {
+ $this->Application->SetVar('__KEEP_SSL__', 1);
+ return;
+ }
+ $this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 1)));
+ }
+ else {
+ if (PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required')) {
+ if ($this->Application->GetVar('__KEEP_SSL__')) return;
+ $this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 0)));
+ }
+ }
+ }
+
+ function SaveReturnScript($params)
+ {
+ // admin/save_redirect.php?do=
+ $url = str_replace($this->Application->BaseURL(), '', $this->T($params) );
+ $url = explode('?', $url, 2);
+ $url = 'save_redirect.php?'.$url[1].'&do='.$url[0];
+
+ $this->Application->StoreVar('ReturnScript', $url);
+ }
+
+ function ConstOn($params)
+ {
+ $name = $this->SelectParam($params,'name,const');
+ return $this->Application->isDebugMode() && dbg_ConstOn($name);
+ }
+
+ function SetDefaultCategory($params)
+ {
+ $module_name = $params['module'];
+ $module =& $this->Application->recallObject('mod.'.$module_name);
+ $this->Application->SetVar('m_cat_id', $module->GetDBField('RootCat') );
+ }
+
+ function ImportRedirect($params)
+ {
+ $import_id = $this->Application->GetVar('import_id');
+ if ($import_id) {
+ // redirect forward to step3 (import parameters coosing)
+ $this->Application->StoreVar('ImportScriptID', $import_id);
+
+ $sql = 'SELECT *
+ FROM '.TABLE_PREFIX.'ImportScripts
+ WHERE is_id = '.$import_id;
+
+ $db =& $this->Application->GetADODBConnection();
+ $is_params = $db->GetRow($sql);
+
+ if ($is_params['is_type'] == 'db') {
+ $this->Application->Redirect('', null, '', 'import/step3.php');
+ }
+ elseif ($is_params['is_type'] == 'csv') {
+ $module = strtolower($is_params['is_Module']);
+ $template = $module.'/import';
+ $sql = 'SELECT Var
+ FROM '.TABLE_PREFIX.'Modules
+ WHERE LOWER(Name) = '.$db->qstr($module);
+ $item_prefix = $db->GetOne($sql);
+ $pass_params = Array('m_opener' => 'd', $item_prefix.'.import_id' => 0, $item_prefix.'.import_event' => 'OnNew', 'pass' => 'm,'.$item_prefix.'.import');
+ $this->Application->Redirect($template, $pass_params);
+ }
+ }
+ else {
+ // redirect back to step2 (import type choosing)
+ $this->Application->Redirect('', null, '', 'import/step2.php');
+ }
+ }
+
+ function GetSectionTitle($params)
+ {
+ $params['name'] = replaceModuleSection($params['phrase']);
+ return $this->Phrase($params);
+ }
+
+ function GetSectionIcon($params)
+ {
+ return replaceModuleSection($params['icon']);
+ }
+
+ function StoreSystemVars($params)
+ {
+ // save theese variables to session, because they are useful for most configuration templates
+ $this->Application->LinkVar('module');
+ $this->Application->LinkVar('section');
+ }
+
+ function XMLTemplate($params)
+ {
+ define('DBG_SKIP_REPORTING', 1);
+ header('Content-type: text/xml');
+ }
+}
+
+
+?>
Index: branches/unlabeled/unlabeled-1.50.2/kernel/units/users/users_event_handler.php
===================================================================
diff -u -r3865 -r4354
--- branches/unlabeled/unlabeled-1.50.2/kernel/units/users/users_event_handler.php (.../users_event_handler.php) (revision 3865)
+++ branches/unlabeled/unlabeled-1.50.2/kernel/units/users/users_event_handler.php (.../users_event_handler.php) (revision 4354)
@@ -1,844 +1,865 @@
-Application->IsAdmin() )
- {
- $location = $this->Application->BaseURL().ADMIN_DIR.'/index.php?expired=1';
- header('Location: '.$location);
- exit;
- }
- else
- {
- $http_query =& $this->Application->recallObject('HTTPQuery');
- $get = $http_query->getRedirectParams();
-
- $t = $this->Application->GetVar('t');
- $get['js_redirect'] = $this->Application->ConfigValue('UseJSRedirect');
- $this->Application->Redirect($t ? $t : 'index', $get);
- }
- }
-
- /**
- * Checks user data and logs it in if allowed
- *
- * @param kEvent $event
- */
- function OnLogin(&$event)
- {
- $this->Application->setUnitOption($event->Prefix, 'AutoLoad', false);
- $object =& $this->Application->recallObject('u');
-
- $password = $this->Application->GetVar('password');
- if(!$password)
- {
- $object->SetError('ValidateLogin', 'blank_password', 'lu_blank_password');
- $event->status = erFAIL;
- return false;
- }
-
- $email_as_login = $this->Application->ConfigValue('Email_As_Login');
- list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
- $login_value = $this->Application->GetVar($submit_field);
-
- /*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
- $user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
-
- $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
- $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
-
- if($user_id)
- {
- $object->Load($user_id);
- if( $object->GetDBField('Status') == STATUS_ACTIVE )
- {
- $groups = $object->getMembershipGroups(true);
- if(!$groups) $groups = Array();
- if ( !$this->Application->IsAdmin() ) array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
- $this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
-
- if( $this->Application->CheckPermission('LOGIN',0) )
- {
- $session =& $this->Application->recallObject('Session');
- $session->SetField('PortalUserId', $user_id);
- $session->SetField('GroupList', implode(',', $groups) );
- $this->Application->SetVar('u_id', $user_id);
- $this->Application->StoreVar('user_id', $user_id);
- $this->Application->setVisitField('PortalUserId', $user_id);
-
- $this_login = (int)$object->getPersistantVar('ThisLogin');
- $object->setPersistantVar('LastLogin', $this_login);
- $object->setPersistantVar('ThisLogin', adodb_mktime());
- }
- else
- {
- $object->Load(-2);
- $object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
- $event->status = erFAIL;
- }
-
- $next_template = $this->Application->GetVar('next_template');
- if($next_template) $event->redirect = $next_template;
- if ($this->Application->ConfigValue('UseJSRedirect')) {
- $event->SetRedirectParam('js_redirect', 1);
- }
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password);
- }
- else
- {
- $event->redirect = $this->Application->GetVar('pending_disabled_template');
- }
- }
- else
- {
- $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
- $event->status = erFAIL;
- }
- }
-
- /**
- * Called when user logs in using old in-portal
- *
- * @param kEvent $event
- */
- function OnInpLogin(&$event)
- {
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') );
- }
-
- /**
- * Called when user logs in using old in-portal
- *
- * @param kEvent $event
- */
- function OnInpLogout(&$event)
- {
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LogoutUser');
- }
-
- function OnLogout(&$event)
- {
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LogoutUser');
-
- $session =& $this->Application->recallObject('Session');
- $session->SetField('PortalUserId', -2);
- $this->Application->SetVar('u_id', -2);
- $this->Application->StoreVar('user_id', -2);
- $object =& $this->Application->recallObject('u');
- $object->Load(-2);
-
- $this->Application->DestroySession();
-
- $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
- $session->SetField('GroupList', $group_list);
- $this->Application->StoreVar('UserGroups', $group_list);
-
- if ($this->Application->ConfigValue('UseJSRedirect')) {
- $event->SetRedirectParam('js_redirect', 1);
- }
- }
-
- /**
- * Prefill states dropdown with correct values
- *
- * @param kEvent $event
- * @access public
- */
- function OnPrepareStates(&$event)
- {
- $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
- $cs_helper->PopulateStates($event, 'State', 'Country');
-
- $object =& $event->getObject();
-
- if( $object->isRequired('Country') && $cs_helper->CountryHasStates( $object->GetDBField('Country') ) ) $object->setRequired('State', true);
- $object->setLogin();
- }
-
- /**
- * Redirects user after succesfull registration to confirmation template (on Front only)
- *
- * @param kEvent $event
- */
- function OnAfterItemCreate(&$event)
- {
- $is_subscriber = $this->Application->GetVar('IsSubscriber');
- if(!$is_subscriber)
- {
- $object =& $event->getObject();
-
- $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
- SET PrimaryGroup = 0
- WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
- $this->Conn->Query($sql);
-
- $group_id = $this->Application->ConfigValue('User_NewGroup');
-
- $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
- $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
- }
- }
-
- /**
- * Login user if possible, if not then redirect to corresponding template
- *
- * @param kEvent $event
- */
- function autoLoginUser(&$event)
- {
- $object =& $event->getObject();
- $this->Application->SetVar('u_id', $object->GetID() );
-
- if($object->GetDBField('Status') == STATUS_ACTIVE)
- {
- $email_as_login = $this->Application->ConfigValue('Email_As_Login');
- list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
-
- $this->Application->SetVar($submit_field, $object->GetDBField($login_field) );
- $this->Application->SetVar('password', $object->GetDBField('Password_plain') );
-
- $event->CallSubEvent('OnLogin');
- }
- }
-
-
- /**
- * When creating user & user with such email exists then force to use OnUpdate insted of OnCreate
- *
- * @param kEvent $event
- */
- function OnSubstituteSubscriber(&$event)
- {
- $ret = false;
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
- list($id, $field_values) = each($items_info);
- $user_email = $field_values['Email'];
- if($user_email)
- {
- // check if is subscriber
- $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) );
- $verify_user->Load($user_email, 'Email');
- if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
- {
- $items_info = Array( $verify_user->GetDBField('PortalUserId') => $field_values );
- $this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
- $ret = true;
- }
- }
- }
-
- if( isset($event->MasterEvent) )
- {
- $event->MasterEvent->setEventParam('is_subscriber_only', $ret);
- }
- else
- {
- $event->setEventParam('is_subscriber_only', $ret);
- }
- }
-
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- * @return bool
- */
- function isSubscriberOnly(&$event)
- {
- $event->CallSubEvent('OnSubstituteSubscriber');
- $is_subscriber = false;
- if( $event->getEventParam('is_subscriber_only') )
- {
- $is_subscriber = true;
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $this->OnUpdate($event);
- if($event->status == erSUCCESS)
- {
- $this->OnAfterItemCreate($event);
- $object->SendEmailEvents();
- if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect) $this->autoLoginUser($event);
- }
- }
- return $is_subscriber;
- }
-
- /**
- * Creates new user
- *
- * @param kEvent $event
- */
- function OnCreate(&$event)
- {
- if( !$this->Application->IsAdmin() ) $this->setUserStatus($event);
-
- if( !$this->isSubscriberOnly($event) )
- {
- $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
- $cs_helper->CheckStateField($event, 'State', 'Country');
-
- parent::OnCreate($event);
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
-
- $this->Application->SetVar('u_id', $object->getID() );
- $this->Application->setUnitOption('u', 'AutoLoad', true);
-
- $this->setNextTemplate($event);
-
- if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect)
- {
- $object->SendEmailEvents();
- $this->autoLoginUser($event);
- }
- }
- }
-
- /**
- * Set's new user status based on config options
- *
- * @param kEvent $event
- */
- function setUserStatus(&$event)
- {
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object =& $event->getObject();
-
- $new_users_allowed = $this->Application->ConfigValue('User_Allow_New');
- // 1 - Instant, 2 - Not Allowed, 3 - Pending
-
- switch ($new_users_allowed)
- {
- case 1: // Instant
- $object->SetDBField('Status', 1);
- $next_template = $this->Application->GetVar('registration_confirm_template');
- if($next_template) $event->redirect = $next_template;
- break;
-
- case 3: // Pending
- $next_template = $this->Application->GetVar('registration_confirm_pending_template');
- if($next_template) $event->redirect = $next_template;
- $object->SetDBField('Status', 2);
- break;
-
- case 2: // Not Allowed
- $object->SetDBField('Status', 0);
- break;
- }
- }
-
-
-
-
- /**
- * Set's new unique resource id to user
- *
- * @param kEvent $event
- */
- function OnBeforeItemCreate(&$event)
- {
- $email_as_login = $this->Application->ConfigValue('Email_As_Login');
- $object =& $event->getObject();
- if ($email_as_login) {
- $object->Fields['Email']['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist');
- }
-
- }
-
- /**
- * Set's new unique resource id to user
- *
- * @param kEvent $event
- */
- function OnAfterItemValidate(&$event)
- {
- $object =& $event->getObject();
- $resource_id = $object->GetDBField('ResourceId');
- if (!$resource_id)
- {
- $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
- }
- }
-
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnRecommend(&$event){
-
- $friend_email = $this->Application->GetVar('friend_email');
- $friend_name = $this->Application->GetVar('friend_email');
-
- if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email))
- {
-
- $send_params = array();
- $send_params['to_email']=$friend_email;
- $send_params['to_name']=$friend_name;
-
- $user_id = $this->Application->GetVar('u_id');
- $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params);
-
- if ($email_event->status == erSUCCESS){
- $event->redirect_params = array('opener' => 's', 'pass' => 'all');
- $event->redirect = $this->Application->GetVar('template_success');
- }
- else {
-// $event->redirect_params = array('opener' => 's', 'pass' => 'all');
-// $event->redirect = $this->Application->GetVar('template_fail');
- $object =& $this->Application->recallObject('u');
- $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error');
- $object->FieldErrors['Email']['pseudo'] = 'send_error';
- $event->status = erFAIL;
-
- }
- }
- else {
- $object =& $this->Application->recallObject('u');
- $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
- $object->FieldErrors['Email']['pseudo'] = 'invalid_email';
- $event->status = erFAIL;
- }
-
-
- }
-
- /**
- * Saves address changes and mades no redirect
- *
- * @param kEvent $event
- */
- function OnUpdateAddress(&$event)
- {
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object =& $event->getObject();
-
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
- list($id,$field_values) = each($items_info);
- if($id > 0) $object->Load($id);
- $object->SetFieldsFromHash($field_values);
- $object->setID($id);
- $object->Validate();
- }
-
- $event->redirect = false;
- }
-
- function OnSubscribeQuery(&$event){
-
- $user_email = $this->Application->GetVar('subscriber_email');
- if ( preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email) ){
-
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
-
- $this->Application->StoreVar('SubscriberEmail', $user_email);
-
- if( $object->Load(array('Email'=>$user_email)) ){
- $group_info = $this->GetGroupInfo($object->GetID());
- if($group_info){
- $event->redirect = $this->Application->GetVar('unsubscribe_template');
- }
- else {
- $event->redirect = $this->Application->GetVar('subscribe_template');
- }
- }
- else {
- $event->redirect = $this->Application->GetVar('subscribe_template');
- $this->Application->StoreVar('SubscriberEmail', $user_email);
- }
-
- }
- else {
-
- $object =& $this->Application->recallObject('u');
- $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
- $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email';
- $event->status = erFAIL;
-
- }
-
-
- //subscribe_query_ok_template
- }
-
- function OnSubscribeUser(&$event){
-
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
-
- $user_email = $this->Application->RecallVar('SubscriberEmail');
-
- if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email)){
-
- if($object->Load(array('Email'=>$user_email))){
-
- $group_info = $this->GetGroupInfo($object->GetID());
-
- if ($group_info){
- if ($event->getEventParam('no_unsubscribe')) return;
-
- if ($group_info['PrimaryGroup']){
- // delete user
- $object->Delete();
- }
- else {
- $this->RemoveSubscriberGroup($object->GetID());
- }
-
- $event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
-
- }
- else {
- $this->AddSubscriberGroup($object->GetID(), 0);
- $event->redirect = $this->Application->GetVar('subscribe_ok_template');
- }
-
-
- }
- else {
-
- $object->SetField('Email', $user_email);
- $object->SetField('Login', $user_email);
- $object->SetDBField('dob', 1);
- $object->SetDBField('dob_date', 1);
- $object->SetDBField('dob_time', 1);
- $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
- $object->SetDBField('ip', $ip);
-
- $this->Application->SetVar('IsSubscriber', 1);
-
- if ($object->Create()) {
-
- $this->AddSubscriberGroup($object->GetID(), 1);
- $event->redirect = $this->Application->GetVar('subscribe_ok_template');
- }
-
- $this->Application->SetVar('IsSubscriber', 0);
- }
- }
- else {
- // error handling here
- $event->redirect = $this->Application->GetVar('subscribe_fail_template');
- }
-
-
- }
-
- function AddSubscriberGroup($user_id, $is_primary){
-
- $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'INSERT INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,'.$is_primary.')';
- $this->Conn->Query( sprintf($sql, $user_id, $group_id) );
- $this->Application->EmailEventAdmin('USER.SUBSCRIBE', $user_id);
- $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
-
- }
-
- function RemoveSubscriberGroup($user_id){
-
- $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup');
- $this->Conn->Query($sql);
- $this->Application->EmailEventAdmin('USER.UNSUBSCRIBE', $user_id);
- $this->Application->EmailEventUser('USER.UNSUBSCRIBE', $user_id);
-
- }
-
- function GetGroupInfo($user_id){
-
- $group_info = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'UserGroup
- WHERE PortalUserId='.$user_id.'
- AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup'));
- return $group_info;
-
- }
-
- function OnForgotPassword(&$event){
-
- $this->Application->setUnitOption('u', 'AutoLoad', false);
- $user_object = &$this->Application->recallObject('u.forgot');
- $user_current_object = &$this->Application->recallObject('u');
-
- $username = $this->Application->GetVar('username');
- $email = $this->Application->GetVar('email');
- $found = false;
- $allow_reset = true;
-
- if( strlen($username) )
- {
- if( $user_object->Load(array('Login'=>$username)) )
- $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
- }
- else if( strlen($email) )
- {
- if( $user_object->Load(array('Email'=>$email)) )
- $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
- }
-
- if( $user_object->isLoaded() )
- {
- $PwResetConfirm = $user_object->GetDBField('PwResetConfirm');
- $PwRequestTime = $user_object->GetDBField('PwRequestTime');
- $PassResetTime = $user_object->GetDBField('PassResetTime');
- //$MinPwResetDelay = $user_object->GetDBField('MinPwResetDelay');
- $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset');
-
- $allow_reset = (strlen($PwResetConfirm) ?
- adodb_mktime() > $PwRequestTime + $MinPwResetDelay :
- adodb_mktime() > $PassResetTime + $MinPwResetDelay);
- }
-
- if($found && $allow_reset)
- {
- $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId"));
- $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email"));
-
- //$this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
-
- $event->redirect = $this->Application->GetVar('template_success');
-
- }
- else
- {
- if(!strlen($username) && !strlen($email))
- {
- $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata');
- $user_current_object->FieldErrors['Login']['pseudo'] = 'lu_ferror_forgotpw_nodata';
- }
- else
- {
-
- if($allow_reset)
- {
- if( strlen($username) ){
- $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username');
- $user_current_object->FieldErrors['Login']['pseudo']='unknown_username';
- }
- if( strlen($email) ){
- $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email');
- $user_current_object->FieldErrors['Email']['pseudo']='unknown_email';
- }
- }
- else
- {
- $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied');
- if( strlen($username) ){
- $user_current_object->FieldErrors['Login']['pseudo']='reset_denied';
- }
- if( strlen($email) ){
- $user_current_object->FieldErrors['Email']['pseudo']='reset_denied';
- }
- }
-
- }
-
- if($user_current_object->FieldErrors){
- $event->redirect = false;
- }
- }
-
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnResetPassword(&$event){
-
- $user_object = &$this->Application->recallObject('u.forgot');
-
- if($user_object->Load($this->Application->RecallVar('tmp_user_id'))){
-
- $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
- $event->redirect = $this->Application->GetVar('template_success');
-
- $mod_object =& $this->Application->recallObject('mod.'.'In-Commerce');
- $m_cat_id = $mod_object->GetDBField('RootCat');
- $event->SetRedirectParam('pass', 'm');
- //$event->SetRedirectParam('m_cat_id', $m_cat_id);
- $this->Application->SetVar('m_cat_id', $m_cat_id);
-
-
- }
-
- }
-
- function OnResetPasswordConfirmed(&$event){
-
- $passed_key = $this->Application->GetVar('user_key');
-
- $user_object = &$this->Application->recallObject('u.forgot');
- $user_current_object = &$this->Application->recallObject('u');
-
- if (strlen(trim($passed_key)) == 0) {
- $event->redirect_params = array('opener' => 's', 'pass' => 'all');
- $event->redirect = false;
-
- $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
- $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
- }
-
-
- if($user_object->Load(array('PwResetConfirm'=>$passed_key)))
- {
- $exp_time = $user_object->GetDBField('PwRequestTime') + 3600;
- $user_object->SetDBField("PwResetConfirm", '');
- $user_object->SetDBField("PwRequestTime", 0);
- if ( $exp_time > adodb_mktime() )
- {
- //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text';
- $newpw = makepassword4();
-
- $this->Application->StoreVar('password', $newpw);
-
- $user_object->SetDBField("Password",$newpw);
- $user_object->SetDBField("PassResetTime", adodb_mktime());
- $user_object->SetDBField("PwResetConfirm", '');
- $user_object->SetDBField("PwRequestTime", 0);
- $user_object->Update();
-
- $this->Application->SetVar('ForgottenPassword', $newpw);
-
- $email_event_user = &$this->Application->EmailEventUser('INCOMMERCEUSER.PSWD', $user_object->GetDBField('PortalUserId'));
- $email_event_admin = &$this->Application->EmailEventAdmin('INCOMMERCEUSER.PSWD');
-
- $this->Application->DeleteVar('ForgottenPassword');
-
- if ($email_event_user->status == erSUCCESS){
- $event->redirect_params = array('opener' => 's', 'pass' => 'all');
- $event->redirect = $this->Application->GetVar('template_success');
- }
-
- $user_object->SetDBField("Password",md5($newpw));
- $user_object->Update();
-
- } else {
- $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired');
- $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired';
- $event->redirect = false;
-
- }
- } else {
- $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
- $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
- $event->redirect = false;
-
- }
- }
-
- function OnUpdate(&$event)
- {
- $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
- $cs_helper->CheckStateField($event, 'State', 'Country');
-
- parent::OnUpdate($event);
-
- $this->setNextTemplate($event);
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function setNextTemplate(&$event)
- {
- if( !$this->Application->IsAdmin() )
- {
- $event->redirect_params['opener'] = 's';
- $object =& $event->getObject();
- if($object->GetDBField('Status') == STATUS_ACTIVE)
- {
- $next_template = $this->Application->GetVar('next_template');
- if($next_template) $event->redirect = $next_template;
- }
- }
- }
-
-
-
- /**
- * Delete users from groups if their membership is expired
- *
- * @param kEvent $event
- */
- function OnCheckExpiredMembership(&$event)
- {
- // send pre-expiration reminders: begin
- $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
- $sql = 'SELECT PortalUserId, GroupId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE (MembershipExpires IS NOT NULL) AND (ExpirationReminderSent = 0) AND (MembershipExpires < '.$pre_expiration.')';
-
- $skip_clause = $event->getEventParam('skip_clause');
- if ($skip_clause) {
- $sql .= ' AND !('.implode(') AND !(', $skip_clause).')';
- }
-
- $records = $this->Conn->Query($sql);
- if ($records) {
- $conditions = Array();
- foreach ($records as $record) {
- $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRATION.NOTICE', $record['PortalUserId']);
- $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRATION.NOTICE');
- $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')';
- }
- $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
- SET ExpirationReminderSent = 1
- WHERE '.implode(' OR ', $conditions);
- $this->Conn->Query($sql);
- }
- // send pre-expiration reminders: end
-
- // remove users from groups with expired membership: begin
- $sql = 'SELECT PortalUserId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
- $user_ids = $this->Conn->GetCol($sql);
- if ($user_ids) {
- foreach ($user_ids as $id) {
- $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRED', $id);
- $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRED');
- }
- }
- $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup
- WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
- $this->Conn->Query($sql);
- // remove users from groups with expired membership: end
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnRefreshForm(&$event)
- {
- $event->redirect = false;
- $item_info = $this->Application->GetVar($event->Prefix_Special);
- list($id, $fields) = each($item_info);
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $object->setID($id);
- $object->IgnoreValidation = true;
- $object->SetFieldsFromHash($fields);
- }
- }
-
+Application->IsAdmin() )
+ {
+ $location = $this->Application->BaseURL().ADMIN_DIR.'/index.php?expired=1';
+ header('Location: '.$location);
+ exit;
+ }
+ else
+ {
+ $http_query =& $this->Application->recallObject('HTTPQuery');
+ $get = $http_query->getRedirectParams();
+
+ $t = $this->Application->GetVar('t');
+ $get['js_redirect'] = $this->Application->ConfigValue('UseJSRedirect');
+ $this->Application->Redirect($t ? $t : 'index', $get);
+ }
+ }
+
+ /**
+ * Checks user data and logs it in if allowed
+ *
+ * @param kEvent $event
+ */
+ function OnLogin(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix, 'AutoLoad', false);
+ $object =& $this->Application->recallObject('u');
+
+ $password = $this->Application->GetVar('password');
+ if(!$password)
+ {
+ $object->SetError('ValidateLogin', 'blank_password', 'lu_blank_password');
+ $event->status = erFAIL;
+ return false;
+ }
+
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
+ $login_value = $this->Application->GetVar($submit_field);
+
+ /*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
+
+ $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
+
+ if($user_id)
+ {
+ $object->Load($user_id);
+ if( $object->GetDBField('Status') == STATUS_ACTIVE )
+ {
+ $groups = $object->getMembershipGroups(true);
+ if(!$groups) $groups = Array();
+ if ( !$this->Application->IsAdmin() ) array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
+ $this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
+
+ if( $this->Application->CheckPermission('LOGIN',0) )
+ {
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', $user_id);
+ $session->SetField('GroupList', implode(',', $groups) );
+ $this->Application->SetVar('u_id', $user_id);
+ $this->Application->StoreVar('user_id', $user_id);
+ $this->Application->setVisitField('PortalUserId', $user_id);
+
+ $this_login = (int)$object->getPersistantVar('ThisLogin');
+ $object->setPersistantVar('LastLogin', $this_login);
+ $object->setPersistantVar('ThisLogin', adodb_mktime());
+ }
+ else
+ {
+ $object->Load(-2);
+ $object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
+ $event->status = erFAIL;
+ }
+
+ $next_template = $this->Application->GetVar('next_template');
+ if ($next_template == '_ses_redirect') {
+ $location = $this->Application->BaseURL().$this->Application->RecallVar($next_template);
+ if( $this->Application->isDebugMode() && dbg_ConstOn('DBG_REDIRECT') )
+ {
+ $this->Application->Debugger->appendTrace();
+ echo "Debug output above!!! Proceed to redirect: $a_location
";
+ }
+ else {
+ header('Location: '.$location);
+ }
+ $session =& $this->Application->recallObject('Session');
+ $session->SaveData();
+ exit();
+ }
+
+ if($next_template) $event->redirect = $next_template;
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password);
+ }
+ else
+ {
+ $event->redirect = $this->Application->GetVar('pending_disabled_template');
+ }
+ }
+ else
+ {
+ $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
+ $event->status = erFAIL;
+ }
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogin(&$event)
+ {
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') );
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+ }
+
+ function OnLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', -2);
+ $this->Application->SetVar('u_id', -2);
+ $this->Application->StoreVar('user_id', -2);
+ $object =& $this->Application->recallObject('u');
+ $object->Load(-2);
+
+ $this->Application->DestroySession();
+
+ $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
+ $session->SetField('GroupList', $group_list);
+ $this->Application->StoreVar('UserGroups', $group_list);
+
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+ }
+
+ /**
+ * Prefill states dropdown with correct values
+ *
+ * @param kEvent $event
+ * @access public
+ */
+ function OnPrepareStates(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->PopulateStates($event, 'State', 'Country');
+
+ $object =& $event->getObject();
+
+ if( $object->isRequired('Country') && $cs_helper->CountryHasStates( $object->GetDBField('Country') ) ) $object->setRequired('State', true);
+ $object->setLogin();
+ }
+
+ /**
+ * Redirects user after succesfull registration to confirmation template (on Front only)
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ $is_subscriber = $this->Application->GetVar('IsSubscriber');
+ if(!$is_subscriber)
+ {
+ $object =& $event->getObject();
+
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET PrimaryGroup = 0
+ WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
+ $this->Conn->Query($sql);
+
+ $group_id = $this->Application->ConfigValue('User_NewGroup');
+
+ $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
+ $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
+ }
+ }
+
+ /**
+ * Login user if possible, if not then redirect to corresponding template
+ *
+ * @param kEvent $event
+ */
+ function autoLoginUser(&$event)
+ {
+ $object =& $event->getObject();
+ $this->Application->SetVar('u_id', $object->GetID() );
+
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
+
+ $this->Application->SetVar($submit_field, $object->GetDBField($login_field) );
+ $this->Application->SetVar('password', $object->GetDBField('Password_plain') );
+
+ $event->CallSubEvent('OnLogin');
+ }
+ }
+
+
+ /**
+ * When creating user & user with such email exists then force to use OnUpdate insted of OnCreate
+ *
+ * @param kEvent $event
+ */
+ function OnSubstituteSubscriber(&$event)
+ {
+ $ret = false;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id, $field_values) = each($items_info);
+ $user_email = $field_values['Email'];
+ if($user_email)
+ {
+ // check if is subscriber
+ $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) );
+ $verify_user->Load($user_email, 'Email');
+ if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
+ {
+ $items_info = Array( $verify_user->GetDBField('PortalUserId') => $field_values );
+ $this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
+ $ret = true;
+ }
+ }
+ }
+
+ if( isset($event->MasterEvent) )
+ {
+ $event->MasterEvent->setEventParam('is_subscriber_only', $ret);
+ }
+ else
+ {
+ $event->setEventParam('is_subscriber_only', $ret);
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ * @return bool
+ */
+ function isSubscriberOnly(&$event)
+ {
+ $event->CallSubEvent('OnSubstituteSubscriber');
+ $is_subscriber = false;
+ if( $event->getEventParam('is_subscriber_only') )
+ {
+ $is_subscriber = true;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $this->OnUpdate($event);
+ if($event->status == erSUCCESS)
+ {
+ $this->OnAfterItemCreate($event);
+ $object->SendEmailEvents();
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect) $this->autoLoginUser($event);
+ }
+ }
+ return $is_subscriber;
+ }
+
+ /**
+ * Creates new user
+ *
+ * @param kEvent $event
+ */
+ function OnCreate(&$event)
+ {
+ if( !$this->Application->IsAdmin() ) $this->setUserStatus($event);
+
+ if( !$this->isSubscriberOnly($event) )
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnCreate($event);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $this->Application->SetVar('u_id', $object->getID() );
+ $this->Application->setUnitOption('u', 'AutoLoad', true);
+
+ $this->setNextTemplate($event);
+
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect)
+ {
+ $object->SendEmailEvents();
+ $this->autoLoginUser($event);
+ }
+ }
+ }
+
+ /**
+ * Set's new user status based on config options
+ *
+ * @param kEvent $event
+ */
+ function setUserStatus(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+
+ $new_users_allowed = $this->Application->ConfigValue('User_Allow_New');
+ // 1 - Instant, 2 - Not Allowed, 3 - Pending
+
+ switch ($new_users_allowed)
+ {
+ case 1: // Instant
+ $object->SetDBField('Status', 1);
+ $next_template = $this->Application->GetVar('registration_confirm_template');
+ if($next_template) $event->redirect = $next_template;
+ break;
+
+ case 3: // Pending
+ $next_template = $this->Application->GetVar('registration_confirm_pending_template');
+ if($next_template) $event->redirect = $next_template;
+ $object->SetDBField('Status', 2);
+ break;
+
+ case 2: // Not Allowed
+ $object->SetDBField('Status', 0);
+ break;
+ }
+
+ /*if ($object->GetDBField('PaidMember') == 1) {
+ $this->Application->HandleEvent($add_to_cart, 'ord:OnAddToCart');
+ $event->redirect = 'in-commerce/checkout/shop_cart';
+ } */
+
+ }
+
+
+
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ $object =& $event->getObject();
+ if ($email_as_login) {
+ $object->Fields['Email']['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist');
+ }
+
+ }
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemValidate(&$event)
+ {
+ $object =& $event->getObject();
+ $resource_id = $object->GetDBField('ResourceId');
+ if (!$resource_id)
+ {
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRecommend(&$event){
+
+ $friend_email = $this->Application->GetVar('friend_email');
+ $friend_name = $this->Application->GetVar('friend_email');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email))
+ {
+
+ $send_params = array();
+ $send_params['to_email']=$friend_email;
+ $send_params['to_name']=$friend_name;
+
+ $user_id = $this->Application->GetVar('u_id');
+ $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params);
+
+ if ($email_event->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+ else {
+// $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+// $event->redirect = $this->Application->GetVar('template_fail');
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error');
+ $object->FieldErrors['Email']['pseudo'] = 'send_error';
+ $event->status = erFAIL;
+
+ }
+ }
+ else {
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['Email']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+ }
+
+
+ }
+
+ /**
+ * Saves address changes and mades no redirect
+ *
+ * @param kEvent $event
+ */
+ function OnUpdateAddress(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ if($id > 0) $object->Load($id);
+ $object->SetFieldsFromHash($field_values);
+ $object->setID($id);
+ $object->Validate();
+ }
+
+ $event->redirect = false;
+ }
+
+ function OnSubscribeQuery(&$event){
+
+ $user_email = $this->Application->GetVar('subscriber_email');
+ if ( preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email) ){
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
+
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+
+ if( $object->Load(array('Email'=>$user_email)) ){
+ $group_info = $this->GetGroupInfo($object->GetID());
+ if($group_info){
+ $event->redirect = $this->Application->GetVar('unsubscribe_template');
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ }
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+ }
+
+ }
+ else {
+
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+
+ }
+
+
+ //subscribe_query_ok_template
+ }
+
+ function OnSubscribeUser(&$event){
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
+
+ $user_email = $this->Application->RecallVar('SubscriberEmail');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email)){
+
+ if($object->Load(array('Email'=>$user_email))){
+
+ $group_info = $this->GetGroupInfo($object->GetID());
+
+ if ($group_info){
+ if ($event->getEventParam('no_unsubscribe')) return;
+
+ if ($group_info['PrimaryGroup']){
+ // delete user
+ $object->Delete();
+ }
+ else {
+ $this->RemoveSubscriberGroup($object->GetID());
+ }
+
+ $event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
+
+ }
+ else {
+ $this->AddSubscriberGroup($object->GetID(), 0);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+
+ }
+ else {
+
+ $object->SetField('Email', $user_email);
+ $object->SetField('Login', $user_email);
+ $object->SetDBField('dob', 1);
+ $object->SetDBField('dob_date', 1);
+ $object->SetDBField('dob_time', 1);
+ $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
+ $object->SetDBField('ip', $ip);
+
+ $this->Application->SetVar('IsSubscriber', 1);
+
+ if ($object->Create()) {
+
+ $this->AddSubscriberGroup($object->GetID(), 1);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+ $this->Application->SetVar('IsSubscriber', 0);
+ }
+ }
+ else {
+ // error handling here
+ $event->redirect = $this->Application->GetVar('subscribe_fail_template');
+ }
+
+
+ }
+
+ function AddSubscriberGroup($user_id, $is_primary){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,'.$is_primary.')';
+ $this->Conn->Query( sprintf($sql, $user_id, $group_id) );
+ $this->Application->EmailEventAdmin('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+
+ }
+
+ function RemoveSubscriberGroup($user_id){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup');
+ $this->Conn->Query($sql);
+ $this->Application->EmailEventAdmin('USER.UNSUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.UNSUBSCRIBE', $user_id);
+
+ }
+
+ function GetGroupInfo($user_id){
+
+ $group_info = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'UserGroup
+ WHERE PortalUserId='.$user_id.'
+ AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup'));
+ return $group_info;
+
+ }
+
+ function OnForgotPassword(&$event){
+
+ $this->Application->setUnitOption('u', 'AutoLoad', false);
+ $user_object = &$this->Application->recallObject('u.forgot');
+ $user_current_object = &$this->Application->recallObject('u');
+
+ $username = $this->Application->GetVar('username');
+ $email = $this->Application->GetVar('email');
+ $found = false;
+ $allow_reset = true;
+
+ if( strlen($username) )
+ {
+ if( $user_object->Load(array('Login'=>$username)) )
+ $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+ else if( strlen($email) )
+ {
+ if( $user_object->Load(array('Email'=>$email)) )
+ $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+
+ if( $user_object->isLoaded() )
+ {
+ $PwResetConfirm = $user_object->GetDBField('PwResetConfirm');
+ $PwRequestTime = $user_object->GetDBField('PwRequestTime');
+ $PassResetTime = $user_object->GetDBField('PassResetTime');
+ //$MinPwResetDelay = $user_object->GetDBField('MinPwResetDelay');
+ $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset');
+
+ $allow_reset = (strlen($PwResetConfirm) ?
+ adodb_mktime() > $PwRequestTime + $MinPwResetDelay :
+ adodb_mktime() > $PassResetTime + $MinPwResetDelay);
+ }
+
+ if($found && $allow_reset)
+ {
+ $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId"));
+ $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email"));
+
+ //$this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+
+ $event->redirect = $this->Application->GetVar('template_success');
+
+ }
+ else
+ {
+ if(!strlen($username) && !strlen($email))
+ {
+ $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata');
+ $user_current_object->FieldErrors['Login']['pseudo'] = 'lu_ferror_forgotpw_nodata';
+ }
+ else
+ {
+
+ if($allow_reset)
+ {
+ if( strlen($username) ){
+ $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username');
+ $user_current_object->FieldErrors['Login']['pseudo']='unknown_username';
+ }
+ if( strlen($email) ){
+ $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email');
+ $user_current_object->FieldErrors['Email']['pseudo']='unknown_email';
+ }
+ }
+ else
+ {
+ $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied');
+ if( strlen($username) ){
+ $user_current_object->FieldErrors['Login']['pseudo']='reset_denied';
+ }
+ if( strlen($email) ){
+ $user_current_object->FieldErrors['Email']['pseudo']='reset_denied';
+ }
+ }
+
+ }
+
+ if($user_current_object->FieldErrors){
+ $event->redirect = false;
+ }
+ }
+
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnResetPassword(&$event){
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+
+ if($user_object->Load($this->Application->RecallVar('tmp_user_id'))){
+
+ $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+ $event->redirect = $this->Application->GetVar('template_success');
+
+ $mod_object =& $this->Application->recallObject('mod.'.'In-Commerce');
+ $m_cat_id = $mod_object->GetDBField('RootCat');
+ $event->SetRedirectParam('pass', 'm');
+ //$event->SetRedirectParam('m_cat_id', $m_cat_id);
+ $this->Application->SetVar('m_cat_id', $m_cat_id);
+
+
+ }
+
+ }
+
+ function OnResetPasswordConfirmed(&$event){
+
+ $passed_key = $this->Application->GetVar('user_key');
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+ $user_current_object = &$this->Application->recallObject('u');
+
+ if (strlen(trim($passed_key)) == 0) {
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = false;
+
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ }
+
+
+ if($user_object->Load(array('PwResetConfirm'=>$passed_key)))
+ {
+ $exp_time = $user_object->GetDBField('PwRequestTime') + 3600;
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ if ( $exp_time > adodb_mktime() )
+ {
+ //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text';
+ $newpw = makepassword4();
+
+ $this->Application->StoreVar('password', $newpw);
+
+ $user_object->SetDBField("Password",$newpw);
+ $user_object->SetDBField("PassResetTime", adodb_mktime());
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ $user_object->Update();
+
+ $this->Application->SetVar('ForgottenPassword', $newpw);
+
+ $email_event_user = &$this->Application->EmailEventUser('INCOMMERCEUSER.PSWD', $user_object->GetDBField('PortalUserId'));
+ $email_event_admin = &$this->Application->EmailEventAdmin('INCOMMERCEUSER.PSWD');
+
+ $this->Application->DeleteVar('ForgottenPassword');
+
+ if ($email_event_user->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+
+ $user_object->SetDBField("Password",md5($newpw));
+ $user_object->Update();
+
+ } else {
+ $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired';
+ $event->redirect = false;
+
+ }
+ } else {
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ $event->redirect = false;
+
+ }
+ }
+
+ function OnUpdate(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnUpdate($event);
+
+ $this->setNextTemplate($event);
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function setNextTemplate(&$event)
+ {
+ if( !$this->Application->IsAdmin() )
+ {
+ $event->redirect_params['opener'] = 's';
+ $object =& $event->getObject();
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $next_template = $this->Application->GetVar('next_template');
+ if($next_template) $event->redirect = $next_template;
+ }
+ }
+ }
+
+
+
+ /**
+ * Delete users from groups if their membership is expired
+ *
+ * @param kEvent $event
+ */
+ function OnCheckExpiredMembership(&$event)
+ {
+ // send pre-expiration reminders: begin
+ $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
+ $sql = 'SELECT PortalUserId, GroupId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (ExpirationReminderSent = 0) AND (MembershipExpires < '.$pre_expiration.')';
+
+ $skip_clause = $event->getEventParam('skip_clause');
+ if ($skip_clause) {
+ $sql .= ' AND !('.implode(') AND !(', $skip_clause).')';
+ }
+
+ $records = $this->Conn->Query($sql);
+ if ($records) {
+ $conditions = Array();
+ foreach ($records as $record) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRATION.NOTICE', $record['PortalUserId']);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRATION.NOTICE');
+ $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')';
+ }
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET ExpirationReminderSent = 1
+ WHERE '.implode(' OR ', $conditions);
+ $this->Conn->Query($sql);
+ }
+ // send pre-expiration reminders: end
+
+ // remove users from groups with expired membership: begin
+ $sql = 'SELECT PortalUserId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $user_ids = $this->Conn->GetCol($sql);
+ if ($user_ids) {
+ foreach ($user_ids as $id) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRED', $id);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRED');
+ }
+ }
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $this->Conn->Query($sql);
+ // remove users from groups with expired membership: end
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRefreshForm(&$event)
+ {
+ $event->redirect = false;
+ $item_info = $this->Application->GetVar($event->Prefix_Special);
+ list($id, $fields) = each($item_info);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->setID($id);
+ $object->IgnoreValidation = true;
+ $object->SetFieldsFromHash($fields);
+ }
+ }
+
?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.108.2/kernel/action.php
===================================================================
diff -u -r4321 -r4354
--- branches/unlabeled/unlabeled-1.108.2/kernel/action.php (.../action.php) (revision 4321)
+++ branches/unlabeled/unlabeled-1.108.2/kernel/action.php (.../action.php) (revision 4354)
@@ -124,7 +124,7 @@
'CreatedOn' => $CreatedOn,
'dob' => $dob
);
-
+
$u =& $objEditItems->Add_User_NEW($fields_hash);
saveCustomFields('u', $u->Get('ResourceId'), 6);
}
@@ -146,7 +146,7 @@
if (!GetVar('user_login')) {
$dob = 0;
}
-
+
$fields_hash = Array( 'Login' => $_POST['user_login'],
'Password' => GetVar('password') ? md5(GetVar('password')) : '',
'FirstName' => $_POST['user_firstname'],
@@ -2380,12 +2380,12 @@
{
$objUserGroupsList = new clsUserGroupList();
$objUserGroupsList->CopyFromEditTable("GroupId");
-
+
$group_ids = $objGroups->CopyFromEditTable("GroupId");
if ($group_ids) {
// $objCustomDataList->CopyFromEditTable('g');
}
-
+
$objGroups->Clear();
}
if( GetVar('GroupEditStatus') == 2 )
Index: branches/unlabeled/unlabeled-1.3.2/themes/default/register/register_form.tpl
===================================================================
diff -u -r4030 -r4354
--- branches/unlabeled/unlabeled-1.3.2/themes/default/register/register_form.tpl (.../register_form.tpl) (revision 4030)
+++ branches/unlabeled/unlabeled-1.3.2/themes/default/register/register_form.tpl (.../register_form.tpl) (revision 4354)
@@ -1,178 +1,178 @@
-
- ">
-
-
+
+ ">
+
+
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.50.2/core/units/users/users_event_handler.php
===================================================================
diff -u -r3865 -r4354
--- branches/unlabeled/unlabeled-1.50.2/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 3865)
+++ branches/unlabeled/unlabeled-1.50.2/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 4354)
@@ -1,844 +1,865 @@
-Application->IsAdmin() )
- {
- $location = $this->Application->BaseURL().ADMIN_DIR.'/index.php?expired=1';
- header('Location: '.$location);
- exit;
- }
- else
- {
- $http_query =& $this->Application->recallObject('HTTPQuery');
- $get = $http_query->getRedirectParams();
-
- $t = $this->Application->GetVar('t');
- $get['js_redirect'] = $this->Application->ConfigValue('UseJSRedirect');
- $this->Application->Redirect($t ? $t : 'index', $get);
- }
- }
-
- /**
- * Checks user data and logs it in if allowed
- *
- * @param kEvent $event
- */
- function OnLogin(&$event)
- {
- $this->Application->setUnitOption($event->Prefix, 'AutoLoad', false);
- $object =& $this->Application->recallObject('u');
-
- $password = $this->Application->GetVar('password');
- if(!$password)
- {
- $object->SetError('ValidateLogin', 'blank_password', 'lu_blank_password');
- $event->status = erFAIL;
- return false;
- }
-
- $email_as_login = $this->Application->ConfigValue('Email_As_Login');
- list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
- $login_value = $this->Application->GetVar($submit_field);
-
- /*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
- $user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
-
- $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
- $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
-
- if($user_id)
- {
- $object->Load($user_id);
- if( $object->GetDBField('Status') == STATUS_ACTIVE )
- {
- $groups = $object->getMembershipGroups(true);
- if(!$groups) $groups = Array();
- if ( !$this->Application->IsAdmin() ) array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
- $this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
-
- if( $this->Application->CheckPermission('LOGIN',0) )
- {
- $session =& $this->Application->recallObject('Session');
- $session->SetField('PortalUserId', $user_id);
- $session->SetField('GroupList', implode(',', $groups) );
- $this->Application->SetVar('u_id', $user_id);
- $this->Application->StoreVar('user_id', $user_id);
- $this->Application->setVisitField('PortalUserId', $user_id);
-
- $this_login = (int)$object->getPersistantVar('ThisLogin');
- $object->setPersistantVar('LastLogin', $this_login);
- $object->setPersistantVar('ThisLogin', adodb_mktime());
- }
- else
- {
- $object->Load(-2);
- $object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
- $event->status = erFAIL;
- }
-
- $next_template = $this->Application->GetVar('next_template');
- if($next_template) $event->redirect = $next_template;
- if ($this->Application->ConfigValue('UseJSRedirect')) {
- $event->SetRedirectParam('js_redirect', 1);
- }
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password);
- }
- else
- {
- $event->redirect = $this->Application->GetVar('pending_disabled_template');
- }
- }
- else
- {
- $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
- $event->status = erFAIL;
- }
- }
-
- /**
- * Called when user logs in using old in-portal
- *
- * @param kEvent $event
- */
- function OnInpLogin(&$event)
- {
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') );
- }
-
- /**
- * Called when user logs in using old in-portal
- *
- * @param kEvent $event
- */
- function OnInpLogout(&$event)
- {
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LogoutUser');
- }
-
- function OnLogout(&$event)
- {
- $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
- $sync_manager->performAction('LogoutUser');
-
- $session =& $this->Application->recallObject('Session');
- $session->SetField('PortalUserId', -2);
- $this->Application->SetVar('u_id', -2);
- $this->Application->StoreVar('user_id', -2);
- $object =& $this->Application->recallObject('u');
- $object->Load(-2);
-
- $this->Application->DestroySession();
-
- $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
- $session->SetField('GroupList', $group_list);
- $this->Application->StoreVar('UserGroups', $group_list);
-
- if ($this->Application->ConfigValue('UseJSRedirect')) {
- $event->SetRedirectParam('js_redirect', 1);
- }
- }
-
- /**
- * Prefill states dropdown with correct values
- *
- * @param kEvent $event
- * @access public
- */
- function OnPrepareStates(&$event)
- {
- $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
- $cs_helper->PopulateStates($event, 'State', 'Country');
-
- $object =& $event->getObject();
-
- if( $object->isRequired('Country') && $cs_helper->CountryHasStates( $object->GetDBField('Country') ) ) $object->setRequired('State', true);
- $object->setLogin();
- }
-
- /**
- * Redirects user after succesfull registration to confirmation template (on Front only)
- *
- * @param kEvent $event
- */
- function OnAfterItemCreate(&$event)
- {
- $is_subscriber = $this->Application->GetVar('IsSubscriber');
- if(!$is_subscriber)
- {
- $object =& $event->getObject();
-
- $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
- SET PrimaryGroup = 0
- WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
- $this->Conn->Query($sql);
-
- $group_id = $this->Application->ConfigValue('User_NewGroup');
-
- $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
- $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
- }
- }
-
- /**
- * Login user if possible, if not then redirect to corresponding template
- *
- * @param kEvent $event
- */
- function autoLoginUser(&$event)
- {
- $object =& $event->getObject();
- $this->Application->SetVar('u_id', $object->GetID() );
-
- if($object->GetDBField('Status') == STATUS_ACTIVE)
- {
- $email_as_login = $this->Application->ConfigValue('Email_As_Login');
- list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
-
- $this->Application->SetVar($submit_field, $object->GetDBField($login_field) );
- $this->Application->SetVar('password', $object->GetDBField('Password_plain') );
-
- $event->CallSubEvent('OnLogin');
- }
- }
-
-
- /**
- * When creating user & user with such email exists then force to use OnUpdate insted of OnCreate
- *
- * @param kEvent $event
- */
- function OnSubstituteSubscriber(&$event)
- {
- $ret = false;
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
- list($id, $field_values) = each($items_info);
- $user_email = $field_values['Email'];
- if($user_email)
- {
- // check if is subscriber
- $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) );
- $verify_user->Load($user_email, 'Email');
- if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
- {
- $items_info = Array( $verify_user->GetDBField('PortalUserId') => $field_values );
- $this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
- $ret = true;
- }
- }
- }
-
- if( isset($event->MasterEvent) )
- {
- $event->MasterEvent->setEventParam('is_subscriber_only', $ret);
- }
- else
- {
- $event->setEventParam('is_subscriber_only', $ret);
- }
- }
-
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- * @return bool
- */
- function isSubscriberOnly(&$event)
- {
- $event->CallSubEvent('OnSubstituteSubscriber');
- $is_subscriber = false;
- if( $event->getEventParam('is_subscriber_only') )
- {
- $is_subscriber = true;
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $this->OnUpdate($event);
- if($event->status == erSUCCESS)
- {
- $this->OnAfterItemCreate($event);
- $object->SendEmailEvents();
- if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect) $this->autoLoginUser($event);
- }
- }
- return $is_subscriber;
- }
-
- /**
- * Creates new user
- *
- * @param kEvent $event
- */
- function OnCreate(&$event)
- {
- if( !$this->Application->IsAdmin() ) $this->setUserStatus($event);
-
- if( !$this->isSubscriberOnly($event) )
- {
- $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
- $cs_helper->CheckStateField($event, 'State', 'Country');
-
- parent::OnCreate($event);
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
-
- $this->Application->SetVar('u_id', $object->getID() );
- $this->Application->setUnitOption('u', 'AutoLoad', true);
-
- $this->setNextTemplate($event);
-
- if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect)
- {
- $object->SendEmailEvents();
- $this->autoLoginUser($event);
- }
- }
- }
-
- /**
- * Set's new user status based on config options
- *
- * @param kEvent $event
- */
- function setUserStatus(&$event)
- {
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object =& $event->getObject();
-
- $new_users_allowed = $this->Application->ConfigValue('User_Allow_New');
- // 1 - Instant, 2 - Not Allowed, 3 - Pending
-
- switch ($new_users_allowed)
- {
- case 1: // Instant
- $object->SetDBField('Status', 1);
- $next_template = $this->Application->GetVar('registration_confirm_template');
- if($next_template) $event->redirect = $next_template;
- break;
-
- case 3: // Pending
- $next_template = $this->Application->GetVar('registration_confirm_pending_template');
- if($next_template) $event->redirect = $next_template;
- $object->SetDBField('Status', 2);
- break;
-
- case 2: // Not Allowed
- $object->SetDBField('Status', 0);
- break;
- }
- }
-
-
-
-
- /**
- * Set's new unique resource id to user
- *
- * @param kEvent $event
- */
- function OnBeforeItemCreate(&$event)
- {
- $email_as_login = $this->Application->ConfigValue('Email_As_Login');
- $object =& $event->getObject();
- if ($email_as_login) {
- $object->Fields['Email']['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist');
- }
-
- }
-
- /**
- * Set's new unique resource id to user
- *
- * @param kEvent $event
- */
- function OnAfterItemValidate(&$event)
- {
- $object =& $event->getObject();
- $resource_id = $object->GetDBField('ResourceId');
- if (!$resource_id)
- {
- $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
- }
- }
-
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnRecommend(&$event){
-
- $friend_email = $this->Application->GetVar('friend_email');
- $friend_name = $this->Application->GetVar('friend_email');
-
- if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email))
- {
-
- $send_params = array();
- $send_params['to_email']=$friend_email;
- $send_params['to_name']=$friend_name;
-
- $user_id = $this->Application->GetVar('u_id');
- $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params);
-
- if ($email_event->status == erSUCCESS){
- $event->redirect_params = array('opener' => 's', 'pass' => 'all');
- $event->redirect = $this->Application->GetVar('template_success');
- }
- else {
-// $event->redirect_params = array('opener' => 's', 'pass' => 'all');
-// $event->redirect = $this->Application->GetVar('template_fail');
- $object =& $this->Application->recallObject('u');
- $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error');
- $object->FieldErrors['Email']['pseudo'] = 'send_error';
- $event->status = erFAIL;
-
- }
- }
- else {
- $object =& $this->Application->recallObject('u');
- $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
- $object->FieldErrors['Email']['pseudo'] = 'invalid_email';
- $event->status = erFAIL;
- }
-
-
- }
-
- /**
- * Saves address changes and mades no redirect
- *
- * @param kEvent $event
- */
- function OnUpdateAddress(&$event)
- {
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object =& $event->getObject();
-
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
- list($id,$field_values) = each($items_info);
- if($id > 0) $object->Load($id);
- $object->SetFieldsFromHash($field_values);
- $object->setID($id);
- $object->Validate();
- }
-
- $event->redirect = false;
- }
-
- function OnSubscribeQuery(&$event){
-
- $user_email = $this->Application->GetVar('subscriber_email');
- if ( preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email) ){
-
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
-
- $this->Application->StoreVar('SubscriberEmail', $user_email);
-
- if( $object->Load(array('Email'=>$user_email)) ){
- $group_info = $this->GetGroupInfo($object->GetID());
- if($group_info){
- $event->redirect = $this->Application->GetVar('unsubscribe_template');
- }
- else {
- $event->redirect = $this->Application->GetVar('subscribe_template');
- }
- }
- else {
- $event->redirect = $this->Application->GetVar('subscribe_template');
- $this->Application->StoreVar('SubscriberEmail', $user_email);
- }
-
- }
- else {
-
- $object =& $this->Application->recallObject('u');
- $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
- $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email';
- $event->status = erFAIL;
-
- }
-
-
- //subscribe_query_ok_template
- }
-
- function OnSubscribeUser(&$event){
-
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
-
- $user_email = $this->Application->RecallVar('SubscriberEmail');
-
- if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email)){
-
- if($object->Load(array('Email'=>$user_email))){
-
- $group_info = $this->GetGroupInfo($object->GetID());
-
- if ($group_info){
- if ($event->getEventParam('no_unsubscribe')) return;
-
- if ($group_info['PrimaryGroup']){
- // delete user
- $object->Delete();
- }
- else {
- $this->RemoveSubscriberGroup($object->GetID());
- }
-
- $event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
-
- }
- else {
- $this->AddSubscriberGroup($object->GetID(), 0);
- $event->redirect = $this->Application->GetVar('subscribe_ok_template');
- }
-
-
- }
- else {
-
- $object->SetField('Email', $user_email);
- $object->SetField('Login', $user_email);
- $object->SetDBField('dob', 1);
- $object->SetDBField('dob_date', 1);
- $object->SetDBField('dob_time', 1);
- $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
- $object->SetDBField('ip', $ip);
-
- $this->Application->SetVar('IsSubscriber', 1);
-
- if ($object->Create()) {
-
- $this->AddSubscriberGroup($object->GetID(), 1);
- $event->redirect = $this->Application->GetVar('subscribe_ok_template');
- }
-
- $this->Application->SetVar('IsSubscriber', 0);
- }
- }
- else {
- // error handling here
- $event->redirect = $this->Application->GetVar('subscribe_fail_template');
- }
-
-
- }
-
- function AddSubscriberGroup($user_id, $is_primary){
-
- $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'INSERT INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,'.$is_primary.')';
- $this->Conn->Query( sprintf($sql, $user_id, $group_id) );
- $this->Application->EmailEventAdmin('USER.SUBSCRIBE', $user_id);
- $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
-
- }
-
- function RemoveSubscriberGroup($user_id){
-
- $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup');
- $this->Conn->Query($sql);
- $this->Application->EmailEventAdmin('USER.UNSUBSCRIBE', $user_id);
- $this->Application->EmailEventUser('USER.UNSUBSCRIBE', $user_id);
-
- }
-
- function GetGroupInfo($user_id){
-
- $group_info = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'UserGroup
- WHERE PortalUserId='.$user_id.'
- AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup'));
- return $group_info;
-
- }
-
- function OnForgotPassword(&$event){
-
- $this->Application->setUnitOption('u', 'AutoLoad', false);
- $user_object = &$this->Application->recallObject('u.forgot');
- $user_current_object = &$this->Application->recallObject('u');
-
- $username = $this->Application->GetVar('username');
- $email = $this->Application->GetVar('email');
- $found = false;
- $allow_reset = true;
-
- if( strlen($username) )
- {
- if( $user_object->Load(array('Login'=>$username)) )
- $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
- }
- else if( strlen($email) )
- {
- if( $user_object->Load(array('Email'=>$email)) )
- $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
- }
-
- if( $user_object->isLoaded() )
- {
- $PwResetConfirm = $user_object->GetDBField('PwResetConfirm');
- $PwRequestTime = $user_object->GetDBField('PwRequestTime');
- $PassResetTime = $user_object->GetDBField('PassResetTime');
- //$MinPwResetDelay = $user_object->GetDBField('MinPwResetDelay');
- $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset');
-
- $allow_reset = (strlen($PwResetConfirm) ?
- adodb_mktime() > $PwRequestTime + $MinPwResetDelay :
- adodb_mktime() > $PassResetTime + $MinPwResetDelay);
- }
-
- if($found && $allow_reset)
- {
- $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId"));
- $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email"));
-
- //$this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
-
- $event->redirect = $this->Application->GetVar('template_success');
-
- }
- else
- {
- if(!strlen($username) && !strlen($email))
- {
- $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata');
- $user_current_object->FieldErrors['Login']['pseudo'] = 'lu_ferror_forgotpw_nodata';
- }
- else
- {
-
- if($allow_reset)
- {
- if( strlen($username) ){
- $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username');
- $user_current_object->FieldErrors['Login']['pseudo']='unknown_username';
- }
- if( strlen($email) ){
- $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email');
- $user_current_object->FieldErrors['Email']['pseudo']='unknown_email';
- }
- }
- else
- {
- $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied');
- if( strlen($username) ){
- $user_current_object->FieldErrors['Login']['pseudo']='reset_denied';
- }
- if( strlen($email) ){
- $user_current_object->FieldErrors['Email']['pseudo']='reset_denied';
- }
- }
-
- }
-
- if($user_current_object->FieldErrors){
- $event->redirect = false;
- }
- }
-
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnResetPassword(&$event){
-
- $user_object = &$this->Application->recallObject('u.forgot');
-
- if($user_object->Load($this->Application->RecallVar('tmp_user_id'))){
-
- $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
- $event->redirect = $this->Application->GetVar('template_success');
-
- $mod_object =& $this->Application->recallObject('mod.'.'In-Commerce');
- $m_cat_id = $mod_object->GetDBField('RootCat');
- $event->SetRedirectParam('pass', 'm');
- //$event->SetRedirectParam('m_cat_id', $m_cat_id);
- $this->Application->SetVar('m_cat_id', $m_cat_id);
-
-
- }
-
- }
-
- function OnResetPasswordConfirmed(&$event){
-
- $passed_key = $this->Application->GetVar('user_key');
-
- $user_object = &$this->Application->recallObject('u.forgot');
- $user_current_object = &$this->Application->recallObject('u');
-
- if (strlen(trim($passed_key)) == 0) {
- $event->redirect_params = array('opener' => 's', 'pass' => 'all');
- $event->redirect = false;
-
- $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
- $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
- }
-
-
- if($user_object->Load(array('PwResetConfirm'=>$passed_key)))
- {
- $exp_time = $user_object->GetDBField('PwRequestTime') + 3600;
- $user_object->SetDBField("PwResetConfirm", '');
- $user_object->SetDBField("PwRequestTime", 0);
- if ( $exp_time > adodb_mktime() )
- {
- //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text';
- $newpw = makepassword4();
-
- $this->Application->StoreVar('password', $newpw);
-
- $user_object->SetDBField("Password",$newpw);
- $user_object->SetDBField("PassResetTime", adodb_mktime());
- $user_object->SetDBField("PwResetConfirm", '');
- $user_object->SetDBField("PwRequestTime", 0);
- $user_object->Update();
-
- $this->Application->SetVar('ForgottenPassword', $newpw);
-
- $email_event_user = &$this->Application->EmailEventUser('INCOMMERCEUSER.PSWD', $user_object->GetDBField('PortalUserId'));
- $email_event_admin = &$this->Application->EmailEventAdmin('INCOMMERCEUSER.PSWD');
-
- $this->Application->DeleteVar('ForgottenPassword');
-
- if ($email_event_user->status == erSUCCESS){
- $event->redirect_params = array('opener' => 's', 'pass' => 'all');
- $event->redirect = $this->Application->GetVar('template_success');
- }
-
- $user_object->SetDBField("Password",md5($newpw));
- $user_object->Update();
-
- } else {
- $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired');
- $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired';
- $event->redirect = false;
-
- }
- } else {
- $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
- $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
- $event->redirect = false;
-
- }
- }
-
- function OnUpdate(&$event)
- {
- $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
- $cs_helper->CheckStateField($event, 'State', 'Country');
-
- parent::OnUpdate($event);
-
- $this->setNextTemplate($event);
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function setNextTemplate(&$event)
- {
- if( !$this->Application->IsAdmin() )
- {
- $event->redirect_params['opener'] = 's';
- $object =& $event->getObject();
- if($object->GetDBField('Status') == STATUS_ACTIVE)
- {
- $next_template = $this->Application->GetVar('next_template');
- if($next_template) $event->redirect = $next_template;
- }
- }
- }
-
-
-
- /**
- * Delete users from groups if their membership is expired
- *
- * @param kEvent $event
- */
- function OnCheckExpiredMembership(&$event)
- {
- // send pre-expiration reminders: begin
- $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
- $sql = 'SELECT PortalUserId, GroupId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE (MembershipExpires IS NOT NULL) AND (ExpirationReminderSent = 0) AND (MembershipExpires < '.$pre_expiration.')';
-
- $skip_clause = $event->getEventParam('skip_clause');
- if ($skip_clause) {
- $sql .= ' AND !('.implode(') AND !(', $skip_clause).')';
- }
-
- $records = $this->Conn->Query($sql);
- if ($records) {
- $conditions = Array();
- foreach ($records as $record) {
- $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRATION.NOTICE', $record['PortalUserId']);
- $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRATION.NOTICE');
- $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')';
- }
- $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
- SET ExpirationReminderSent = 1
- WHERE '.implode(' OR ', $conditions);
- $this->Conn->Query($sql);
- }
- // send pre-expiration reminders: end
-
- // remove users from groups with expired membership: begin
- $sql = 'SELECT PortalUserId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
- $user_ids = $this->Conn->GetCol($sql);
- if ($user_ids) {
- foreach ($user_ids as $id) {
- $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRED', $id);
- $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRED');
- }
- }
- $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup
- WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
- $this->Conn->Query($sql);
- // remove users from groups with expired membership: end
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnRefreshForm(&$event)
- {
- $event->redirect = false;
- $item_info = $this->Application->GetVar($event->Prefix_Special);
- list($id, $fields) = each($item_info);
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $object->setID($id);
- $object->IgnoreValidation = true;
- $object->SetFieldsFromHash($fields);
- }
- }
-
+Application->IsAdmin() )
+ {
+ $location = $this->Application->BaseURL().ADMIN_DIR.'/index.php?expired=1';
+ header('Location: '.$location);
+ exit;
+ }
+ else
+ {
+ $http_query =& $this->Application->recallObject('HTTPQuery');
+ $get = $http_query->getRedirectParams();
+
+ $t = $this->Application->GetVar('t');
+ $get['js_redirect'] = $this->Application->ConfigValue('UseJSRedirect');
+ $this->Application->Redirect($t ? $t : 'index', $get);
+ }
+ }
+
+ /**
+ * Checks user data and logs it in if allowed
+ *
+ * @param kEvent $event
+ */
+ function OnLogin(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix, 'AutoLoad', false);
+ $object =& $this->Application->recallObject('u');
+
+ $password = $this->Application->GetVar('password');
+ if(!$password)
+ {
+ $object->SetError('ValidateLogin', 'blank_password', 'lu_blank_password');
+ $event->status = erFAIL;
+ return false;
+ }
+
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
+ $login_value = $this->Application->GetVar($submit_field);
+
+ /*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
+
+ $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
+
+ if($user_id)
+ {
+ $object->Load($user_id);
+ if( $object->GetDBField('Status') == STATUS_ACTIVE )
+ {
+ $groups = $object->getMembershipGroups(true);
+ if(!$groups) $groups = Array();
+ if ( !$this->Application->IsAdmin() ) array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
+ $this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
+
+ if( $this->Application->CheckPermission('LOGIN',0) )
+ {
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', $user_id);
+ $session->SetField('GroupList', implode(',', $groups) );
+ $this->Application->SetVar('u_id', $user_id);
+ $this->Application->StoreVar('user_id', $user_id);
+ $this->Application->setVisitField('PortalUserId', $user_id);
+
+ $this_login = (int)$object->getPersistantVar('ThisLogin');
+ $object->setPersistantVar('LastLogin', $this_login);
+ $object->setPersistantVar('ThisLogin', adodb_mktime());
+ }
+ else
+ {
+ $object->Load(-2);
+ $object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
+ $event->status = erFAIL;
+ }
+
+ $next_template = $this->Application->GetVar('next_template');
+ if ($next_template == '_ses_redirect') {
+ $location = $this->Application->BaseURL().$this->Application->RecallVar($next_template);
+ if( $this->Application->isDebugMode() && dbg_ConstOn('DBG_REDIRECT') )
+ {
+ $this->Application->Debugger->appendTrace();
+ echo "Debug output above!!! Proceed to redirect: $a_location
";
+ }
+ else {
+ header('Location: '.$location);
+ }
+ $session =& $this->Application->recallObject('Session');
+ $session->SaveData();
+ exit();
+ }
+
+ if($next_template) $event->redirect = $next_template;
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password);
+ }
+ else
+ {
+ $event->redirect = $this->Application->GetVar('pending_disabled_template');
+ }
+ }
+ else
+ {
+ $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
+ $event->status = erFAIL;
+ }
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogin(&$event)
+ {
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') );
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+ }
+
+ function OnLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', -2);
+ $this->Application->SetVar('u_id', -2);
+ $this->Application->StoreVar('user_id', -2);
+ $object =& $this->Application->recallObject('u');
+ $object->Load(-2);
+
+ $this->Application->DestroySession();
+
+ $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
+ $session->SetField('GroupList', $group_list);
+ $this->Application->StoreVar('UserGroups', $group_list);
+
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+ }
+
+ /**
+ * Prefill states dropdown with correct values
+ *
+ * @param kEvent $event
+ * @access public
+ */
+ function OnPrepareStates(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->PopulateStates($event, 'State', 'Country');
+
+ $object =& $event->getObject();
+
+ if( $object->isRequired('Country') && $cs_helper->CountryHasStates( $object->GetDBField('Country') ) ) $object->setRequired('State', true);
+ $object->setLogin();
+ }
+
+ /**
+ * Redirects user after succesfull registration to confirmation template (on Front only)
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ $is_subscriber = $this->Application->GetVar('IsSubscriber');
+ if(!$is_subscriber)
+ {
+ $object =& $event->getObject();
+
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET PrimaryGroup = 0
+ WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
+ $this->Conn->Query($sql);
+
+ $group_id = $this->Application->ConfigValue('User_NewGroup');
+
+ $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
+ $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
+ }
+ }
+
+ /**
+ * Login user if possible, if not then redirect to corresponding template
+ *
+ * @param kEvent $event
+ */
+ function autoLoginUser(&$event)
+ {
+ $object =& $event->getObject();
+ $this->Application->SetVar('u_id', $object->GetID() );
+
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
+
+ $this->Application->SetVar($submit_field, $object->GetDBField($login_field) );
+ $this->Application->SetVar('password', $object->GetDBField('Password_plain') );
+
+ $event->CallSubEvent('OnLogin');
+ }
+ }
+
+
+ /**
+ * When creating user & user with such email exists then force to use OnUpdate insted of OnCreate
+ *
+ * @param kEvent $event
+ */
+ function OnSubstituteSubscriber(&$event)
+ {
+ $ret = false;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id, $field_values) = each($items_info);
+ $user_email = $field_values['Email'];
+ if($user_email)
+ {
+ // check if is subscriber
+ $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) );
+ $verify_user->Load($user_email, 'Email');
+ if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
+ {
+ $items_info = Array( $verify_user->GetDBField('PortalUserId') => $field_values );
+ $this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
+ $ret = true;
+ }
+ }
+ }
+
+ if( isset($event->MasterEvent) )
+ {
+ $event->MasterEvent->setEventParam('is_subscriber_only', $ret);
+ }
+ else
+ {
+ $event->setEventParam('is_subscriber_only', $ret);
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ * @return bool
+ */
+ function isSubscriberOnly(&$event)
+ {
+ $event->CallSubEvent('OnSubstituteSubscriber');
+ $is_subscriber = false;
+ if( $event->getEventParam('is_subscriber_only') )
+ {
+ $is_subscriber = true;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $this->OnUpdate($event);
+ if($event->status == erSUCCESS)
+ {
+ $this->OnAfterItemCreate($event);
+ $object->SendEmailEvents();
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect) $this->autoLoginUser($event);
+ }
+ }
+ return $is_subscriber;
+ }
+
+ /**
+ * Creates new user
+ *
+ * @param kEvent $event
+ */
+ function OnCreate(&$event)
+ {
+ if( !$this->Application->IsAdmin() ) $this->setUserStatus($event);
+
+ if( !$this->isSubscriberOnly($event) )
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnCreate($event);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $this->Application->SetVar('u_id', $object->getID() );
+ $this->Application->setUnitOption('u', 'AutoLoad', true);
+
+ $this->setNextTemplate($event);
+
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect)
+ {
+ $object->SendEmailEvents();
+ $this->autoLoginUser($event);
+ }
+ }
+ }
+
+ /**
+ * Set's new user status based on config options
+ *
+ * @param kEvent $event
+ */
+ function setUserStatus(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+
+ $new_users_allowed = $this->Application->ConfigValue('User_Allow_New');
+ // 1 - Instant, 2 - Not Allowed, 3 - Pending
+
+ switch ($new_users_allowed)
+ {
+ case 1: // Instant
+ $object->SetDBField('Status', 1);
+ $next_template = $this->Application->GetVar('registration_confirm_template');
+ if($next_template) $event->redirect = $next_template;
+ break;
+
+ case 3: // Pending
+ $next_template = $this->Application->GetVar('registration_confirm_pending_template');
+ if($next_template) $event->redirect = $next_template;
+ $object->SetDBField('Status', 2);
+ break;
+
+ case 2: // Not Allowed
+ $object->SetDBField('Status', 0);
+ break;
+ }
+
+ /*if ($object->GetDBField('PaidMember') == 1) {
+ $this->Application->HandleEvent($add_to_cart, 'ord:OnAddToCart');
+ $event->redirect = 'in-commerce/checkout/shop_cart';
+ } */
+
+ }
+
+
+
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ $object =& $event->getObject();
+ if ($email_as_login) {
+ $object->Fields['Email']['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist');
+ }
+
+ }
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemValidate(&$event)
+ {
+ $object =& $event->getObject();
+ $resource_id = $object->GetDBField('ResourceId');
+ if (!$resource_id)
+ {
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRecommend(&$event){
+
+ $friend_email = $this->Application->GetVar('friend_email');
+ $friend_name = $this->Application->GetVar('friend_email');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email))
+ {
+
+ $send_params = array();
+ $send_params['to_email']=$friend_email;
+ $send_params['to_name']=$friend_name;
+
+ $user_id = $this->Application->GetVar('u_id');
+ $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params);
+
+ if ($email_event->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+ else {
+// $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+// $event->redirect = $this->Application->GetVar('template_fail');
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error');
+ $object->FieldErrors['Email']['pseudo'] = 'send_error';
+ $event->status = erFAIL;
+
+ }
+ }
+ else {
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['Email']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+ }
+
+
+ }
+
+ /**
+ * Saves address changes and mades no redirect
+ *
+ * @param kEvent $event
+ */
+ function OnUpdateAddress(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ if($id > 0) $object->Load($id);
+ $object->SetFieldsFromHash($field_values);
+ $object->setID($id);
+ $object->Validate();
+ }
+
+ $event->redirect = false;
+ }
+
+ function OnSubscribeQuery(&$event){
+
+ $user_email = $this->Application->GetVar('subscriber_email');
+ if ( preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email) ){
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
+
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+
+ if( $object->Load(array('Email'=>$user_email)) ){
+ $group_info = $this->GetGroupInfo($object->GetID());
+ if($group_info){
+ $event->redirect = $this->Application->GetVar('unsubscribe_template');
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ }
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+ }
+
+ }
+ else {
+
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+
+ }
+
+
+ //subscribe_query_ok_template
+ }
+
+ function OnSubscribeUser(&$event){
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber');
+
+ $user_email = $this->Application->RecallVar('SubscriberEmail');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email)){
+
+ if($object->Load(array('Email'=>$user_email))){
+
+ $group_info = $this->GetGroupInfo($object->GetID());
+
+ if ($group_info){
+ if ($event->getEventParam('no_unsubscribe')) return;
+
+ if ($group_info['PrimaryGroup']){
+ // delete user
+ $object->Delete();
+ }
+ else {
+ $this->RemoveSubscriberGroup($object->GetID());
+ }
+
+ $event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
+
+ }
+ else {
+ $this->AddSubscriberGroup($object->GetID(), 0);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+
+ }
+ else {
+
+ $object->SetField('Email', $user_email);
+ $object->SetField('Login', $user_email);
+ $object->SetDBField('dob', 1);
+ $object->SetDBField('dob_date', 1);
+ $object->SetDBField('dob_time', 1);
+ $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
+ $object->SetDBField('ip', $ip);
+
+ $this->Application->SetVar('IsSubscriber', 1);
+
+ if ($object->Create()) {
+
+ $this->AddSubscriberGroup($object->GetID(), 1);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+ $this->Application->SetVar('IsSubscriber', 0);
+ }
+ }
+ else {
+ // error handling here
+ $event->redirect = $this->Application->GetVar('subscribe_fail_template');
+ }
+
+
+ }
+
+ function AddSubscriberGroup($user_id, $is_primary){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,'.$is_primary.')';
+ $this->Conn->Query( sprintf($sql, $user_id, $group_id) );
+ $this->Application->EmailEventAdmin('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+
+ }
+
+ function RemoveSubscriberGroup($user_id){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup');
+ $this->Conn->Query($sql);
+ $this->Application->EmailEventAdmin('USER.UNSUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.UNSUBSCRIBE', $user_id);
+
+ }
+
+ function GetGroupInfo($user_id){
+
+ $group_info = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'UserGroup
+ WHERE PortalUserId='.$user_id.'
+ AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup'));
+ return $group_info;
+
+ }
+
+ function OnForgotPassword(&$event){
+
+ $this->Application->setUnitOption('u', 'AutoLoad', false);
+ $user_object = &$this->Application->recallObject('u.forgot');
+ $user_current_object = &$this->Application->recallObject('u');
+
+ $username = $this->Application->GetVar('username');
+ $email = $this->Application->GetVar('email');
+ $found = false;
+ $allow_reset = true;
+
+ if( strlen($username) )
+ {
+ if( $user_object->Load(array('Login'=>$username)) )
+ $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+ else if( strlen($email) )
+ {
+ if( $user_object->Load(array('Email'=>$email)) )
+ $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+
+ if( $user_object->isLoaded() )
+ {
+ $PwResetConfirm = $user_object->GetDBField('PwResetConfirm');
+ $PwRequestTime = $user_object->GetDBField('PwRequestTime');
+ $PassResetTime = $user_object->GetDBField('PassResetTime');
+ //$MinPwResetDelay = $user_object->GetDBField('MinPwResetDelay');
+ $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset');
+
+ $allow_reset = (strlen($PwResetConfirm) ?
+ adodb_mktime() > $PwRequestTime + $MinPwResetDelay :
+ adodb_mktime() > $PassResetTime + $MinPwResetDelay);
+ }
+
+ if($found && $allow_reset)
+ {
+ $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId"));
+ $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email"));
+
+ //$this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+
+ $event->redirect = $this->Application->GetVar('template_success');
+
+ }
+ else
+ {
+ if(!strlen($username) && !strlen($email))
+ {
+ $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata');
+ $user_current_object->FieldErrors['Login']['pseudo'] = 'lu_ferror_forgotpw_nodata';
+ }
+ else
+ {
+
+ if($allow_reset)
+ {
+ if( strlen($username) ){
+ $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username');
+ $user_current_object->FieldErrors['Login']['pseudo']='unknown_username';
+ }
+ if( strlen($email) ){
+ $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email');
+ $user_current_object->FieldErrors['Email']['pseudo']='unknown_email';
+ }
+ }
+ else
+ {
+ $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied');
+ if( strlen($username) ){
+ $user_current_object->FieldErrors['Login']['pseudo']='reset_denied';
+ }
+ if( strlen($email) ){
+ $user_current_object->FieldErrors['Email']['pseudo']='reset_denied';
+ }
+ }
+
+ }
+
+ if($user_current_object->FieldErrors){
+ $event->redirect = false;
+ }
+ }
+
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnResetPassword(&$event){
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+
+ if($user_object->Load($this->Application->RecallVar('tmp_user_id'))){
+
+ $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+ $event->redirect = $this->Application->GetVar('template_success');
+
+ $mod_object =& $this->Application->recallObject('mod.'.'In-Commerce');
+ $m_cat_id = $mod_object->GetDBField('RootCat');
+ $event->SetRedirectParam('pass', 'm');
+ //$event->SetRedirectParam('m_cat_id', $m_cat_id);
+ $this->Application->SetVar('m_cat_id', $m_cat_id);
+
+
+ }
+
+ }
+
+ function OnResetPasswordConfirmed(&$event){
+
+ $passed_key = $this->Application->GetVar('user_key');
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+ $user_current_object = &$this->Application->recallObject('u');
+
+ if (strlen(trim($passed_key)) == 0) {
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = false;
+
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ }
+
+
+ if($user_object->Load(array('PwResetConfirm'=>$passed_key)))
+ {
+ $exp_time = $user_object->GetDBField('PwRequestTime') + 3600;
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ if ( $exp_time > adodb_mktime() )
+ {
+ //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text';
+ $newpw = makepassword4();
+
+ $this->Application->StoreVar('password', $newpw);
+
+ $user_object->SetDBField("Password",$newpw);
+ $user_object->SetDBField("PassResetTime", adodb_mktime());
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ $user_object->Update();
+
+ $this->Application->SetVar('ForgottenPassword', $newpw);
+
+ $email_event_user = &$this->Application->EmailEventUser('INCOMMERCEUSER.PSWD', $user_object->GetDBField('PortalUserId'));
+ $email_event_admin = &$this->Application->EmailEventAdmin('INCOMMERCEUSER.PSWD');
+
+ $this->Application->DeleteVar('ForgottenPassword');
+
+ if ($email_event_user->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+
+ $user_object->SetDBField("Password",md5($newpw));
+ $user_object->Update();
+
+ } else {
+ $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired';
+ $event->redirect = false;
+
+ }
+ } else {
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ $event->redirect = false;
+
+ }
+ }
+
+ function OnUpdate(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnUpdate($event);
+
+ $this->setNextTemplate($event);
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function setNextTemplate(&$event)
+ {
+ if( !$this->Application->IsAdmin() )
+ {
+ $event->redirect_params['opener'] = 's';
+ $object =& $event->getObject();
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $next_template = $this->Application->GetVar('next_template');
+ if($next_template) $event->redirect = $next_template;
+ }
+ }
+ }
+
+
+
+ /**
+ * Delete users from groups if their membership is expired
+ *
+ * @param kEvent $event
+ */
+ function OnCheckExpiredMembership(&$event)
+ {
+ // send pre-expiration reminders: begin
+ $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
+ $sql = 'SELECT PortalUserId, GroupId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (ExpirationReminderSent = 0) AND (MembershipExpires < '.$pre_expiration.')';
+
+ $skip_clause = $event->getEventParam('skip_clause');
+ if ($skip_clause) {
+ $sql .= ' AND !('.implode(') AND !(', $skip_clause).')';
+ }
+
+ $records = $this->Conn->Query($sql);
+ if ($records) {
+ $conditions = Array();
+ foreach ($records as $record) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRATION.NOTICE', $record['PortalUserId']);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRATION.NOTICE');
+ $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')';
+ }
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET ExpirationReminderSent = 1
+ WHERE '.implode(' OR ', $conditions);
+ $this->Conn->Query($sql);
+ }
+ // send pre-expiration reminders: end
+
+ // remove users from groups with expired membership: begin
+ $sql = 'SELECT PortalUserId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $user_ids = $this->Conn->GetCol($sql);
+ if ($user_ids) {
+ foreach ($user_ids as $id) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRED', $id);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRED');
+ }
+ }
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $this->Conn->Query($sql);
+ // remove users from groups with expired membership: end
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRefreshForm(&$event)
+ {
+ $event->redirect = false;
+ $item_info = $this->Application->GetVar($event->Prefix_Special);
+ list($id, $fields) = each($item_info);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->setID($id);
+ $object->IgnoreValidation = true;
+ $object->SetFieldsFromHash($fields);
+ }
+ }
+
?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.13.2/admin/tree/tree.php
===================================================================
diff -u -r4200 -r4354
--- branches/unlabeled/unlabeled-1.13.2/admin/tree/tree.php (.../tree.php) (revision 4200)
+++ branches/unlabeled/unlabeled-1.13.2/admin/tree/tree.php (.../tree.php) (revision 4354)
@@ -1,121 +1,121 @@
-Get('Site_Name');
- $rootLink = $adminURL."/subitems.php?env=".BuildEnv()."§ion=in-portal:root";
- $charset = GetRegionalOption('Charset');
-
- $main_tag_processor =& $application->recallTagProcessor('m');
- $phrase_EditingInProgress = $main_tag_processor->Phrase( Array('name' => 'la_EditingInProgress', 'escape' => 1) );
-
- $phrase_EditingInProgress = str_replace(Array('<', '>', 'br/', 'br /', "\n", "\r"), Array('<', '>', 'br', 'br', '', ''), $phrase_EditingInProgress);
-?>
-
-
-">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+Get('Site_Name');
+ $rootLink = $adminURL."/subitems.php?env=".BuildEnv()."§ion=in-portal:root";
+ $charset = GetRegionalOption('Charset');
+
+ $main_tag_processor =& $application->recallTagProcessor('m');
+ $phrase_EditingInProgress = $main_tag_processor->Phrase( Array('name' => 'la_EditingInProgress', 'escape' => 1) );
+
+ $phrase_EditingInProgress = str_replace(Array('<', '>', 'br/', 'br /', "\n", "\r"), Array('<', '>', 'br', 'br', '', ''), $phrase_EditingInProgress);
+?>
+
+
+">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: branches/unlabeled/unlabeled-1.5.52/core/units/general/inp_db_event_handler.php
===================================================================
diff -u -r1838 -r4354
--- branches/unlabeled/unlabeled-1.5.52/core/units/general/inp_db_event_handler.php (.../inp_db_event_handler.php) (revision 1838)
+++ branches/unlabeled/unlabeled-1.5.52/core/units/general/inp_db_event_handler.php (.../inp_db_event_handler.php) (revision 4354)
@@ -1,115 +1,122 @@
-'iterateItems',
- 'OnMassDecline'=>'iterateItems',
- 'OnMassMoveUp'=>'iterateItems',
- 'OnMassMoveDown'=>'iterateItems',
- );
-
- $this->eventMethods = array_merge($this->eventMethods, $common_events);
- }
-
- /**
- * Apply same processing to each item beeing selected in grid
- *
- * @param kEvent $event
- * @access private
- */
- function iterateItems(&$event)
- {
- if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
- return;
- }
-
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object =& $event->getObject();
- $this->StoreSelectedIDs($event);
- $ids=$this->getSelectedIDs($event);
-
- if($ids)
- {
- $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') );
-
- foreach($ids as $id)
- {
- $object->Load($id);
-
- switch ($event->Name)
- {
- case 'OnMassApprove':
- $object->SetDBField($status_field, 1);
- break;
-
- case 'OnMassDecline':
- $object->SetDBField($status_field, 0);
- break;
-
- case 'OnMassMoveUp':
- $object->SetDBField('Priority', $object->GetDBField('Priority') + 1);
- break;
-
- case 'OnMassMoveDown':
- $object->SetDBField('Priority', $object->GetDBField('Priority') - 1);
- break;
- }
-
- if( $object->Update() )
- {
- $event->status=erSUCCESS;
- $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
- }
- else
- {
- $event->status=erFAIL;
- $event->redirect=false;
- break;
- }
- }
- }
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnMassClone(&$event)
- {
- if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
- return;
- }
-
- $event->status=erSUCCESS;
-
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
-
- $this->StoreSelectedIDs($event);
- $ids=$this->getSelectedIDs($event);
-
- if($ids)
- {
- $temp->CloneItems($event->Prefix, $event->Special, $ids);
- }
- }
-
- function check_array($records, $field, $value)
- {
- foreach ($records as $record)
- {
- if ($record[$field] == $value)
- {
- return true;
- }
- }
- return false;
- }
- }
-
-
+'iterateItems',
+ 'OnMassDecline'=>'iterateItems',
+ 'OnMassMoveUp'=>'iterateItems',
+ 'OnMassMoveDown'=>'iterateItems',
+ );
+
+ $this->eventMethods = array_merge($this->eventMethods, $common_events);
+ }
+
+ /**
+ * Apply same processing to each item beeing selected in grid
+ *
+ * @param kEvent $event
+ * @access private
+ */
+ function iterateItems(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+
+ if($ids)
+ {
+ $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') );
+
+ foreach($ids as $id)
+ {
+ $object->Load($id);
+
+ switch ($event->Name)
+ {
+ case 'OnMassApprove':
+ $object->SetDBField($status_field, 1);
+ break;
+
+ case 'OnMassDecline':
+ $object->SetDBField($status_field, 0);
+ break;
+
+ case 'OnMassMoveUp':
+ $object->SetDBField('Priority', $object->GetDBField('Priority') + 1);
+ break;
+
+ case 'OnMassMoveDown':
+ $object->SetDBField('Priority', $object->GetDBField('Priority') - 1);
+ break;
+ }
+
+ if( $object->Update() )
+ {
+ $event->status=erSUCCESS;
+ $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
+ }
+ else
+ {
+ $event->status=erFAIL;
+ $event->redirect=false;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnMassClone(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
+ $event->status=erSUCCESS;
+
+ $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+
+ if($ids)
+ {
+ $temp->CloneItems($event->Prefix, $event->Special, $ids);
+ }
+ }
+
+ function check_array($records, $field, $value)
+ {
+ foreach ($records as $record)
+ {
+ if ($record[$field] == $value)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function OnPreSavePopup(&$event)
+ {
+ $event->CallSubEvent('OnPreSave');
+ $this->Application->StoreVar('PermCache_UpdateRequired', 1);
+ $event->redirect = 'incs/just_close';
+ }
+ }
+
+
?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.5.52/kernel/units/general/inp_db_event_handler.php
===================================================================
diff -u -r1838 -r4354
--- branches/unlabeled/unlabeled-1.5.52/kernel/units/general/inp_db_event_handler.php (.../inp_db_event_handler.php) (revision 1838)
+++ branches/unlabeled/unlabeled-1.5.52/kernel/units/general/inp_db_event_handler.php (.../inp_db_event_handler.php) (revision 4354)
@@ -1,115 +1,122 @@
-'iterateItems',
- 'OnMassDecline'=>'iterateItems',
- 'OnMassMoveUp'=>'iterateItems',
- 'OnMassMoveDown'=>'iterateItems',
- );
-
- $this->eventMethods = array_merge($this->eventMethods, $common_events);
- }
-
- /**
- * Apply same processing to each item beeing selected in grid
- *
- * @param kEvent $event
- * @access private
- */
- function iterateItems(&$event)
- {
- if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
- return;
- }
-
- $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
- $object =& $event->getObject();
- $this->StoreSelectedIDs($event);
- $ids=$this->getSelectedIDs($event);
-
- if($ids)
- {
- $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') );
-
- foreach($ids as $id)
- {
- $object->Load($id);
-
- switch ($event->Name)
- {
- case 'OnMassApprove':
- $object->SetDBField($status_field, 1);
- break;
-
- case 'OnMassDecline':
- $object->SetDBField($status_field, 0);
- break;
-
- case 'OnMassMoveUp':
- $object->SetDBField('Priority', $object->GetDBField('Priority') + 1);
- break;
-
- case 'OnMassMoveDown':
- $object->SetDBField('Priority', $object->GetDBField('Priority') - 1);
- break;
- }
-
- if( $object->Update() )
- {
- $event->status=erSUCCESS;
- $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
- }
- else
- {
- $event->status=erFAIL;
- $event->redirect=false;
- break;
- }
- }
- }
- }
-
- /**
- * Enter description here...
- *
- * @param kEvent $event
- */
- function OnMassClone(&$event)
- {
- if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
- return;
- }
-
- $event->status=erSUCCESS;
-
- $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
-
- $this->StoreSelectedIDs($event);
- $ids=$this->getSelectedIDs($event);
-
- if($ids)
- {
- $temp->CloneItems($event->Prefix, $event->Special, $ids);
- }
- }
-
- function check_array($records, $field, $value)
- {
- foreach ($records as $record)
- {
- if ($record[$field] == $value)
- {
- return true;
- }
- }
- return false;
- }
- }
-
-
+'iterateItems',
+ 'OnMassDecline'=>'iterateItems',
+ 'OnMassMoveUp'=>'iterateItems',
+ 'OnMassMoveDown'=>'iterateItems',
+ );
+
+ $this->eventMethods = array_merge($this->eventMethods, $common_events);
+ }
+
+ /**
+ * Apply same processing to each item beeing selected in grid
+ *
+ * @param kEvent $event
+ * @access private
+ */
+ function iterateItems(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+
+ if($ids)
+ {
+ $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') );
+
+ foreach($ids as $id)
+ {
+ $object->Load($id);
+
+ switch ($event->Name)
+ {
+ case 'OnMassApprove':
+ $object->SetDBField($status_field, 1);
+ break;
+
+ case 'OnMassDecline':
+ $object->SetDBField($status_field, 0);
+ break;
+
+ case 'OnMassMoveUp':
+ $object->SetDBField('Priority', $object->GetDBField('Priority') + 1);
+ break;
+
+ case 'OnMassMoveDown':
+ $object->SetDBField('Priority', $object->GetDBField('Priority') - 1);
+ break;
+ }
+
+ if( $object->Update() )
+ {
+ $event->status=erSUCCESS;
+ $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
+ }
+ else
+ {
+ $event->status=erFAIL;
+ $event->redirect=false;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnMassClone(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 0)) {
+ return;
+ }
+
+ $event->status=erSUCCESS;
+
+ $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+
+ if($ids)
+ {
+ $temp->CloneItems($event->Prefix, $event->Special, $ids);
+ }
+ }
+
+ function check_array($records, $field, $value)
+ {
+ foreach ($records as $record)
+ {
+ if ($record[$field] == $value)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function OnPreSavePopup(&$event)
+ {
+ $event->CallSubEvent('OnPreSave');
+ $this->Application->StoreVar('PermCache_UpdateRequired', 1);
+ $event->redirect = 'incs/just_close';
+ }
+ }
+
+
?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.2.2/kernel/admin_templates/incs/export.js
===================================================================
diff -u -r4332 -r4354
--- branches/unlabeled/unlabeled-1.2.2/kernel/admin_templates/incs/export.js (.../export.js) (revision 4332)
+++ branches/unlabeled/unlabeled-1.2.2/kernel/admin_templates/incs/export.js (.../export.js) (revision 4354)
@@ -1,85 +1,80 @@
-var $http_request = getXMLHTTPObject();
-var $last_responce = new Date();
-
-function formatNumber($number, $digits_count)
-{
- return parseInt($number) < Math.pow(10, $digits_count - 1) ? str_repeat('0', $digits_count - 1) + $number : $number;
-}
-
-function formatDate($date)
-{
- var $hour = formatNumber($date.getHours(), 2);
- var $minute = formatNumber($date.getMinutes(), 2);
- var $second = formatNumber($date.getSeconds(), 2);
- return $hour + ':' + $minute + ':' + $second;
-}
-
-function getSeconds($from_date, $to_date)
-{
- var $from_seconds = $from_date.getSeconds() + $from_date.getMinutes() * 60 + $from_date.getHours() * 3600;
- var $to_seconds = $to_date.getSeconds() + $to_date.getMinutes() * 60 + $to_date.getHours() * 3600;
- return $to_seconds - $from_seconds;
-}
-
-var $aborting = false;
-function queryProgress($url, $responce_func)
-{
-// alert('queryProgress');
- if ($http_request && $http_request.readyState != 0) {
-// alert('aborting');
- $aborting = true;
- $http_request.abort();
-// alert('After Abort: readyState: '+$http_request.readyState+' status: '+$http_request.status);
- $aborting = false;
- }
-
-// alert('opening');
- $http_request.open('POST', $url, true);
- $http_request.setRequestHeader("referer", $url);
- $http_request.onreadystatechange = function() { processExportResponce($url, $responce_func); };
-// alert('sending new req');
- $http_request.send('is_xml=1');
- $last_responce = new Date();
-}
-
-function setProgress($percent)
-{
- $percent = parseInt($percent);
- document.getElementById('percent_done').style.width = $percent + '%';
- document.getElementById('percent_left').style.width = (100 - $percent) + '%';
- document.getElementById('progress_display').innerHTML = $percent;
- document.getElementById('progress_time').innerHTML = '[' + $phrase_LastResponce + ': ' + formatDate($last_responce) + ']';
-}
-
-function processExportResponce($url, $responce_func)
-{
-// alert('processExportResponce ready: '+$http_request.readyState);
- if ($aborting) return;
- if ($http_request.readyState == 4) {
- if ($http_request.status == 200) {
-// alert('readyState: '+$http_request.readyState+' status: '+$http_request.status);
- var $progress = parseFloat($http_request.responseText);
- if ($progress) {
- setProgress($progress);
- if ($progress < 100) {
- // proceed to next import step
- //alert('ANOTHER abort');
- //$http_request.abort();
- //alert('After ANOTHER Abort: readyState: '+$http_request.readyState+' status: '+$http_request.status);
- setTimeout( function() {
-// alert('quering after timeout');
- queryProgress($url, $responce_func);
- }, 500)
- }
- else {
- // proceed to finish screen
- window.location.href = $finish_template;
- }
- }
- else {
-// alert('progress: '+$progress+' ('+$http_request.responseText+')');
- alert($phrase_ResponceError);
- }
- }
- }
+var $http_request = getXMLHTTPObject();
+var $last_responce = new Date();
+
+function formatNumber($number, $digits_count)
+{
+ return parseInt($number) < Math.pow(10, $digits_count - 1) ? str_repeat('0', $digits_count - 1) + $number : $number;
+}
+
+function formatDate($date)
+{
+ var $hour = formatNumber($date.getHours(), 2);
+ var $minute = formatNumber($date.getMinutes(), 2);
+ var $second = formatNumber($date.getSeconds(), 2);
+ return $hour + ':' + $minute + ':' + $second;
+}
+
+function getSeconds($from_date, $to_date)
+{
+ var $from_seconds = $from_date.getSeconds() + $from_date.getMinutes() * 60 + $from_date.getHours() * 3600;
+ var $to_seconds = $to_date.getSeconds() + $to_date.getMinutes() * 60 + $to_date.getHours() * 3600;
+ return $to_seconds - $from_seconds;
+}
+
+var $aborting = false;
+function queryProgress($url, $responce_func)
+{
+ if ($http_request && $http_request.readyState != 0) {
+ $aborting = true;
+ $http_request.abort();
+ $aborting = false;
+ }
+
+ $http_request.open('POST', $url, true);
+ $http_request.setRequestHeader("referer", $url);
+ $http_request.onreadystatechange = function() { processExportResponce($url, $responce_func); };
+ $http_request.send('is_xml=1');
+ $last_responce = new Date();
+}
+
+function setProgress($percent)
+{
+ $percent = parseInt($percent);
+ document.getElementById('percent_done').style.width = $percent + '%';
+ document.getElementById('percent_left').style.width = (100 - $percent) + '%';
+ document.getElementById('progress_display').innerHTML = $percent;
+ document.getElementById('progress_time').innerHTML = '[' + $phrase_LastResponce + ': ' + formatDate($last_responce) + ']';
+}
+
+function processExportResponce($url, $responce_func)
+{
+// alert('processExportResponce ready: '+$http_request.readyState);
+ if ($aborting) return;
+ if ($http_request.readyState == 4) {
+ if ($http_request.status == 200) {
+// alert('readyState: '+$http_request.readyState+' status: '+$http_request.status);
+ var $progress = parseFloat($http_request.responseText);
+ if ($progress) {
+ setProgress($progress);
+ if ($progress < 100) {
+ // proceed to next import step
+ //alert('ANOTHER abort');
+ //$http_request.abort();
+ //alert('After ANOTHER Abort: readyState: '+$http_request.readyState+' status: '+$http_request.status);
+ setTimeout( function() {
+// alert('quering after timeout');
+ queryProgress($url, $responce_func);
+ }, 500)
+ }
+ else {
+ // proceed to finish screen
+ window.location.href = $finish_template;
+ }
+ }
+ else {
+// alert('progress: '+$progress+' ('+$http_request.responseText+')');
+ alert($phrase_ResponceError);
+ }
+ }
+ }
}
\ No newline at end of file