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; }