public static function addTsFromPost($post = null) { try { if (is_null($post)) { throw new Exception\ArgumentNullException('_POST'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } $arAdd = array(); if (!isset($post['my_car']) || intval($post['my_car']) <= 0) { $arAdd['MY_CAR_ID'] = MyCar::getDefaultCarID(); } else { $arAdd['MY_CAR_ID'] = intval($post['my_car']); } if (!isset($post['ts_num'])) { return false; } else { $arAdd['TS_NUM'] = intval($post['ts_num']); } if (!isset($post['date']) || !CoreLib\DateHelper::checkDate($post['date'])) { return false; } else { if (!($arAdd['DATE'] = CoreLib\DateHelper::validateDate($post['date']))) { return false; } } if (!isset($post['executor']) || intval($post['executor']) <= 0) { return false; } else { $arAdd['EXECUTORS_ID'] = intval($post['executor']); } if (!isset($post['cost'])) { return false; } else { $post['cost'] = str_replace(" ", "", $post['cost']); $post['cost'] = str_replace(",", ".", $post['cost']); $post['cost'] = floatval($post['cost']); $arAdd['COST'] = $post['cost']; } if (!isset($post['odo'])) { return false; } else { $post['odo'] = str_replace(" ", "", $post['odo']); $post['odo'] = str_replace(",", ".", $post['odo']); $post['odo'] = floatval($post['odo']); $arAdd['ODO'] = $post['odo']; } if (isset($post['ts_point']) && intval($post['ts_point']) > 0) { $arAdd['POINTS_ID'] = intval($post['ts_point']); } else { if (isset($post['newpoint_address']) || isset($post['newpoint_lat']) && isset($post['newpoint_lon'])) { $arPoint = array(); if (isset($post['newpoint_name']) && strlen($post['newpoint_name']) > 3) { $arPoint['NAME'] = $post['newpoint_name']; } else { $arPoint['NAME'] = '[auto] Сервис'; } if (isset($post['newpoint_address']) && strlen($post['newpoint_address']) > 5) { $arPoint['ADDRESS'] = $post['newpoint_address']; } if (isset($post['newpoint_lat']) && strlen($post['newpoint_lat']) > 2 && (isset($post['newpoint_lon']) && strlen($post['newpoint_lon']) > 2)) { $arPoint['LON'] = $post['newpoint_lon']; $arPoint['LAT'] = $post['newpoint_lat']; } $arPoint['TYPE'] = Points::getPointTypeIdByCode('service'); $arAdd['POINTS_ID'] = Points::createNewPoint($arPoint); } else { return false; } } if (isset($post['comment']) && strlen($post['comment']) > 0) { $arAdd['DESCRIPTION'] = trim(htmlspecialchars($post['comment'])); } if ($addTsID = static::addTs($arAdd)) { CoreLib\Options::setOption('icar_last_ts_' . intval($arAdd['MY_CAR_ID']), $arAdd['TS_NUM']); CoreLib\Options::setOption('icar_last_executor_' . intval($arAdd['MY_CAR_ID']), $arAdd['EXECUTORS_ID']); CoreLib\Options::setOption('icar_last_executor_' . intval($arAdd['MY_CAR_ID']) . '_point', $arAdd['POINTS_ID']); return $addTsID; } else { return false; } }
MSergeev\Core\Lib\Loader::IncludePackage("finances"); use MSergeev\Core\Exception; use MSergeev\Core\Lib; $arParams = $arReturn = array(); $arReturn['status'] = 'ok'; $bStatus = true; //Проверка переданных полей if (true) { try { if (isset($_REQUEST['category'])) { $arParams['CATEGORY'] = trim(htmlspecialchars($_REQUEST['category'])); } else { throw new Exception\ArgumentNullException('category'); } if (isset($_REQUEST['status'])) { $arParams['STATUS'] = intval($_REQUEST['status']); } else { throw new Exception\ArgumentNullException('status'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); $arReturn['status'] = 'error'; $bStatus = false; } } if ($bStatus) { Lib\Options::setOption('FINANCES_DEPLOY_' . $arParams['CATEGORY'], $arParams['STATUS']); //$arReturn = array_merge($arReturn,$arParams); } header('Content-Type: application/json'); echo json_encode($arReturn);
/** * Сохраняет последнюю использованную марку топлива для автомобиля * * @param int $fuelMark ID марки топлива * @param int $carID ID автомобиля * * @return bool */ protected static function setLastUseFuelMark($fuelMark = null, $carID = null) { try { if (is_null($fuelMark)) { throw new Exception\ArgumentNullException('fuelMark'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } if (is_null($carID)) { $carID = MyCar::getDefaultCarID(); } if (!CoreLib\Options::setOption('icar_last_fuelmark_' . $carID, $fuelMark)) { return false; } else { return true; } }