function saveShopPriceType($price_types, $xml, $db) { $isChanged = $xml->ПакетПредложений->attributes()->СодержитТолькоИзменения; $old_type_remote_ids = $new_type_remote_ids = array(); if (count($price_types) > 0) { foreach ($price_types as $type) { $old_type_remote_ids[] = $type['remote_id']; } } foreach ($xml->ПакетПредложений->ТипыЦен->ТипЦены as $typePrice) { $new_type_remote_ids[] = trim($typePrice->Ид); if (!in_array(trim($typePrice->Ид), $old_type_remote_ids)) { $data = array('remote_id' => trim($typePrice->Ид), 'title' => addslashes(trim($typePrice->Наименование)), 'currency' => addslashes(trim($typePrice->Валюта)), 'tax_title' => addslashes(trim($typePrice->Налог->Наименование)), 'tax_value' => addslashes(trim($typePrice->Налог->УчтеноВСумме))); $result = makeRecord('shop_price_type', $db, $data); $price_types[] = $result; unset($result, $data); } else { if (count($price_types) > 0) { foreach ($price_types as $type) { $data = array(); if ($type['remote_id'] == trim($typePrice->Ид)) { if ($type['title'] != addslashes(trim($typePrice->Наименование))) { $data['title'] = addslashes(trim($typePrice->Наименование)); } if ($type['currency'] != addslashes(trim($typePrice->Валюта))) { $data['currency'] = addslashes(trim($typePrice->Валюта)); } if ($type['tax_title'] != addslashes(trim($typePrice->Налог->Наименование))) { $data['tax_title'] = addslashes(trim($typePrice->Налог->Наименование)); } if ($type['tax_value'] != addslashes(trim($typePrice->Наименование))) { $data['tax_value'] = addslashes(trim($typePrice->Наименование)); } } if (count($data) > 0) { $db->update('shop_price_type', $data, array('id' => $type['id'])); unset($data); } } } } } /*if (!$isChanged && count($price_types) > 0) { foreach ($price_types as $k => $p) { if (!in_array($p['remote_id'], $new_type_remote_ids)) { $db->delete('shop_price_type', array('id' => $p['id'])); unset($price_types[$k]); } } }*/ return $price_types; }
} reset($topdomains); /** * now ,check all records. * if not exists,create it for you automaticlly; * */ foreach ($domains as $domain) { $domain = makeRecord($domain, $ip); $recd = $dnspod->getRecordIDByName($domain["domain"], $domain["old_sub_domain"], $domain["record_line"]); if (!($recd > 0)) { my_error_log("get record failed:" . $domain["old_sub_domain"] . "." . $domain["domain"] . ",line:" . $domain["record_line"] . " failed,will create it for you."); $retCreate = $dnspod->RecordCreate($domain, $domain["domain"], $domain["record_line"]); if (isError($retCreate)) { my_error_log("create record " . $domain["old_sub_domain"] . "." . $domain["domain"] . ",line:" . $domain["record_line"] . " failed,will create it for you."); print_r($retCreate); } else { my_error_log("we create record:" . $domain["old_sub_domain"] . "." . $domain["domain"] . ",line:" . $domain["record_line"] . " for you."); } } } reset($domains); foreach ($domains as $domain) { $domain = makeRecord($domain, $ip); $return = $dnspod->ModifyRecord($domain, $domain["domain"], $domain["old_sub_domain"]); if (isError($return)) { my_error_log("can't modifyRecord:" . $domain["domain"] . ",prefix:" . $domain["old_sub_domain"] . ",ip/value:" . $ip); print_r($return); } else { print phpcl_str("{$domain} update success.\n", PHPCL_UNDERLINE, PHPCL_GREEN, PHPCL_BLACK); } }