function execute($action, $parameters = null) { $this->result = ''; if (is_array($action)) { foreach ($action as $act_name => $act_param) { $this->{$act_name}($act_param); } if ($this->result['error']) { $this->result['errortext'] = implode(' ', $this->result['errortext']); } $this->result = XCODE::win2utf($this->result); } else { return $this->actions($action, $parameters); } }
function start_subscribe($params) { global $TDB, $TMS, $_CONFIG; if ($params['first']) { unset($_SESSION['emails'], $_SESSION['slist'], $_SESSION['sended'], $_SESSION['total'], $_SESSION['subcur']); } if (!isset($_SESSION['slist']) && !isset($_SESSION['emails'])) { if ($subs = $TDB->get_results("SELECT * FROM subscribe WHERE status = 'incoming' ORDER BY cat_id, id")) { $i = 0; $ucount = 0; $scount = count($subs); // сохраняем список рассылки сессию foreach ($subs as $sub) { $_SESSION['slist'][$i] = $sub; $users = $TDB->get_results(' SELECT subscribers_params.user_id AS user_id, subscribers_list.email AS email FROM subscribers_params LEFT JOIN subscribers_list ON subscribers_params.user_id = subscribers_list.id WHERE subscribers_params.subscribe_id = ' . $sub['cat_id'] . ' AND subscribers_list.status = \'active\' '); $ucount += count($users); $_SESSION['emails'][$i] = array_values($users); $i++; } $_SESSION['sended'] = 0; $_SESSION['total'] = $ucount; } else { // рассылок, ожидающих отправки нет $this->result['ready'] = false; $this->result['error'] = true; return $this->result; } // возвращаем для повторного входа $this->result['ready'] = true; $this->result['error'] = false; $this->result['scount'] = $scount; $this->result['ucount'] = $ucount; return $this->result; } if (isset($_SESSION['emails']) && is_array($_SESSION['emails']) && isset($_SESSION['slist']) && is_array($_SESSION['slist'])) { $list = $_SESSION['slist']; $arr = $_SESSION['emails']; $last_sub = end(array_keys($list)); reset($list); reset($arr); $sended = array(); while (list($key, $item) = each($list)) { if (isset($arr[$key])) { $cat_params = $this->_tree->getNodeParam($item['cat_id']); $fields = $this->parseMessageFields($item, $cat_params); $theme = $cat_params['theme']; if (!empty($item['theme'])) { $theme = $item['theme']; } $theme = XCODE::win2utf($theme); $m = Common::inc_module_factory('Mail'); $m->From($cat_params['from']); $m->Subject($theme); $m->Content_type($fields['content-type']); $m->Body($fields['message'], $fields['encoding']); if (!empty($item['files'])) { if (is_string($item['files'])) { $item['files'] = split(',', $item['files']); } if (is_array($item['files'])) { foreach ($item['files'] as $f) { $type = pathinfo($f, PATHINFO_EXTENSION); $f = DOCUMENT_ROOT . $f; if (isset($this->mtype[$type])) { $m->Attach($f, $this->mtype[$type]); } else { $m->Attach($f); } } } } $start = Common::getmicrotime(); $last_key = end(array_keys($arr[$key])); foreach ($arr[$key] as $k => $i) { $m->sendto = array(); $m->To($i['email']); if ($m->Send()) { $sended = array_shift($_SESSION['emails'][$key]); $_SESSION['sended']++; if ($last_key == $k) { // если последний адрес $this->markSent($item['cat_id']); // array_shift($_SESSION['slist'][$key]); unset($_SESSION['slist'][$key]); } if (Common::getmicrotime() - $start > $_CONFIG['subscribe']['update_interval']) { $this->result['next'] = true; $this->result['sub'] = $item; // инфо о рассылке $this->result['sended'] = $sended; } } } if ($last_sub == $key) { $this->result['next'] = false; $this->result['complete'] = true; $this->result['sub'] = $item; $this->result['sended'] = $sended; } } else { // подписчики отсутствуют у данной рассылки unset($_SESSION['slist'][$key]); $this->result['next'] = true; $this->result['sended'] = NULL; } } } }
function importXLS($params) { if (!$params['cron']) { $this->setSessionHandler($_SESSION); } $this->session = $this->sessionhandler['sdata']; if ($params['data']['clearbase'] && $params['step'] == 'parse') { //$this->_tree->DelNode($params['id'],true); } if ($params['step'] == 'parse') { $this->importXLS_prepare($params); $this->session['step'] = 'load'; $this->sessionhandler['sdata'] = $this->session; return; } else { $obj_fields_ancestors = array(); $start = $this->session['currentstep']; $lev = $this->session['curlev']; if ($this->session['currentstep'] == 0) { $start = 1; } $ex = unserialize(Common::cacheRead($this->_module_name, $this->session['xlscache'])); $ex = array_slice($ex, $start, $this->session['step_l']); $HL = $this->session['HL']; $k = $start; if (!$ex) { $this->result['dataWriteEnd'] = 1; return; } $group_keys = array(); foreach ($HL as $key => $hline) { if ($hline["flag"] == "#") { $group_keys[] = $key; } } while (list($line, $record) = each($ex)) { $k++; $vf = null; $pf = null; if (($recount = count($HL) - count($record)) > 0) { for ($i = count($HL) - $recount; $i < count($HL); $i++) { $record[$i] = ''; } } $connected = null; $sf = null; $qf = null; $required = array(); foreach ($record as $fnum => $fieldval) { $fieldval = str_replace('°', '', $fieldval); if ($fieldval[0] == '#') { $lev = 0; while ($fieldval[$lev] == '#') { $lev++; } $this->session['curlev'] = $lev; $group_data['Name'] = substr($fieldval, $lev); $group_data['Disable'] = ''; $group_data['Property_set'] = $params['data']['categoryType']; if ($group_keys) { foreach ($group_keys as $key) { $group_data[$HL[$key]["key"]] = $HL[$key]["operation"] . $record[$key]; } } if ($params['data']['encoding'] != 'utf8') { $group_data = XCODE::win2utf($group_data, $params['data']['encoding']); } if (!($res = $this->_tree->JoinSearch(array(0 => array('Name', $group_data['Name'])), array(0 => array('ancestor', $this->session[$lev - 1]['ctgid']))))) { if ($group_data['basic']) { $this->session[$lev]['ctgid'] = $this->init_group($this->session[$lev - 1]['ctgid'], $group_data, $group_data['basic']); } else { $this->session[$lev]['ctgid'] = $this->init_group($this->session[$lev - 1]['ctgid'], $group_data); } } else { $res = array_shift($res); $this->session[$lev]['ctgid'] = $res['id']; } break 1; } if ($HL[$fnum]['flag']) { switch ($HL[$fnum]['flag']) { case 'C': if ($params['data']['encoding'] != 'utf8') { $fieldval = XCODE::win2utf($fieldval, $params['data']['encoding']); } $connected = explode(',', $fieldval); if (strrchr($fieldval, '.')) { $connected = explode('.', $fieldval); } $t_childs[$HL[$fnum]['key']] = $connected[0]; break; case 'R': $required[] = $fieldval; $required_enabled = true; break; case 'P': $pf[] = array($HL[$fnum]['key'], $fieldval); break; // ?????? ? ???? ?? ??????? // ?????? ? ???? ?? ??????? case 'T': $va = null; $ra = null; if ($sf) { $_df = $sf; $_df[$HL[$fnum]['key']] = $fieldval; foreach ($_df as $ka => $v) { $ra[] = '{' . $ka . '}'; if ($t_childs[$ka]) { $va[] = $t_childs[$ka]; } else { $va[] = $v; } } } $sf[$HL[$fnum]['key']] = str_replace($ra, $va, $HL[$fnum]['operation']); break; case 'S': $va = null; $ra = null; if ($sf) { $_df = $sf; $_df[$HL[$fnum]['key']] = $fieldval; foreach ($_df as $ka => $v) { $ra[] = '{' . $ka . '}'; if ($t_childs[$ka]) { $va[] = str_replace(array(" ", ",", ", ", "\"", "'", "!", '(', ')', '/'), array("_", "", "", "", "", "", "_", "_", ''), $t_childs[$ka]); } else { $va[] = str_replace(array(" ", ",", ", ", "\"", "'", "!", '(', ')', '/'), array("_", "", "", "", "", "", "_", "_", ''), $v); } } } $sf[$HL[$fnum]['key']] = XCODE::translit(str_replace($ra, $va, $HL[$fnum]['operation'])); break; case 'L': $qf[$HL[$fnum]['key']] = XCODE::translit($fieldval); break; case 'Q': $qf[$HL[$fnum]['key']] = $fieldval; break; case 'Y': list($cat_id, $yparam) = explode('=', $HL[$fnum]['operation']); if ($FOM = $this->_tree->DeepSearch($cat_id, array('_CATGROUP', '_CATOBJ'), 0, array($yparam => trim($fieldval)))) { $sf[$HL[$fnum]['key']] = $FOM[0]; $sf['__' . $HL[$fnum]['key']] = $fieldval; } break; case 'V': $vf[$HL[$fnum]['key']] = 0; break; case 'N': $sf[$HL[$fnum]['key']] = $sf['Name']; break; } } if (!in_array($HL[$fnum]['flag'], array('N', 'T', 'S', 'Y'))) { $sf[$HL[$fnum]['key']] = $fieldval; } } $t_childs = null; if (!$sf['Name']) { continue; } $required_count = array_filter($required, 'strlen'); if ($required_enabled && count($required_count) < count($required) or $required_enabled && !$required) { continue; } //unset($sf['']); if ($sf) { if ($params['data']['encoding'] != 'utf8') { $sf = XCODE::win2utf($sf, $params['data']['encoding']); } if (is_array($pf) && ($res = $this->_tree->JoinSearch($pf, array(0 => array('ancestor', $this->session[$lev]['ctgid']))))) { $res = array_shift($res); if ($vf) { $sf = XARRAY::array_diff_key($sf, $vf); } if (!$sf['basic']) { $basic = '%SAME%'; } else { $basic = $sf['basic']; } $this->reinit_catobj($res['id'], $basic, $sf); if ($connected) { foreach ($connected as $co) { if ($r = $this->_tree->DeepSearch($params['data']['showGroupId'], array('_CATGROUP'), 0, array('Name' => $co))) { $r = current($r); $qf_update = array('id' => $r); if ($qf) { $qf_update = $qf_update + $qf; } if ($cos = $this->_tree->JoinSearch(array(0 => array('id', $r)), array(0 => array('ancestor', $res['id'])))) { $cos = current($cos); $this->_tree->DelNode($cos['id']); } $this->init_catconnobj($res['id'], $qf_update); } } } } else { if (!$sf['Property_set']) { $sf['Property_set'] = $params['data']['objectType']; } $sf['Disable'] = ''; if (!$sf['basic']) { $sf['basic'] = '%SAMEASID%'; } $_id = $this->init_catobj($this->session[$lev]['ctgid'], $sf, $sf['basic']); if ($connected) { foreach ($connected as $co) { if ($r = $this->_tree->JoinSearch(array(0 => array('Name', $co)), array(0 => array('ancestor', $params['data']['showGroupId'])))) { $r = current($r); $qf_update = array('id' => $r['id']); if ($qf) { $qf_update = $qf_update + $qf; } $this->init_catconnobj($_id, $qf_update); } } } } } } if ($this->session['currentstep'] < $this->session['xls_length'] + $this->session['step_l']) { $this->session['currentstep'] += $this->session['step_l']; $this->result['dataWriteEnd'] = 0; $this->result['loadedCount'] = $k; } else { $this->result['dataWriteEnd'] = 1; Common::cacheClear($this->_module_name, $this->session['xlscache']); } } $this->sessionhandler['sdata'] = $this->session; }