<?php

use Drupal\node\Entity\Node;
use Drupal\Core\Url;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Language\LanguageDefault;


function boutique_data_rebuild_json_en() {

    $boutiqueGeoJson = '{"type":"FeatureCollection","generator":"overpass-turbo","copyright":"The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.","timestamp":"2016-09-12T19:22:48Z","features":[';
    $query = \Drupal::entityQuery('node')
        ->condition('status', 1)
        ->condition('type', 'boutique');
    $result = array_values($query->execute());
    $count = count($result);
    for ($i = 0; $i < $count; $i++) {
        $entity = entity_load('node', $result[$i])->toArray();
        $sectorName = '';
        if (!empty($entity['field_zone_code'])) {
            $zEntityQuery = \Drupal::entityQuery('node')
                ->condition('type', 'zone')
                ->condition('field_zone_code', $entity['field_zone_code'][0])
                ->condition('status', 1)->execute();
            if (count($zEntityQuery) > 0) {
                $mZone = entity_load('node', array_values($zEntityQuery)[0])->toArray();
                if (count($mZone) > 0) {
                    $sectorName = trim(str_replace('&nbsp;', ' ', (db_query('SELECT description__value FROM taxonomy_term_field_data WHERE tid = :tid', array(
                        ':tid' => $mZone['field_sector_code'][0]['target_id']
                    ))->fetchField())));
                }
            }
        }
        $nid = $entity['nid'][0]['value'];
        $rawUrl = '/node/' . $entity['nid'][0]['value'];
        $aliasUrl = db_query('SELECT alias FROM url_alias WHERE source = :source', array(':source' => $rawUrl))->fetchField();
        $sTypes = null;
        if (!empty($entity['field_boutique_logo'])) {
            $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => $entity['field_boutique_logo'][0]['target_id']))->fetchField());
        } else {
            $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => 105))->fetchField());
        }
        $aliasUrl = !$aliasUrl ? $rawUrl : $aliasUrl;
        $hoursMarkup = '<div class="boutique-map-hours">';
        $todayHours = '<p class="hours-day"><span>Open Today</span>';
        $todayFound = false;
        if (!empty($entity['field_boutique_hours'])) {
            $daysArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
            $today = date('l');
            //ICON REMOVED => <img class="icon" src="/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-hours.svg" alt="Icon of a clock to display with the hours">
            foreach ($entity['field_boutique_hours'] as $day) {
//                $hours .= '<p class="hours-day"><span>' . $daysArray[$day['day']] . '</span> <span>' . $day['starthours'] . ' to ' . $day['endhours'] . '</span></p>';
                if ($today == $daysArray[$day['day']]) {
                    $todayHours .= '<span>' . $day['starthours'] . ' to ' . $day['endhours'] . '</span></p>';
                    $todayFound = true;
                }
            }
        }

        if (!$todayFound) {
            $todayHours = '<p class="hours-day"><span>Closed Today</span></p>';
        }
        $hoursMarkup .= $todayHours;
        $boutiqueTitle = isset($entity['title'][0]['value']) ? $entity['title'][0]['value'] : 'QD30' . $i;

        $description = trim("<div class='boutique-infobox' id='boutique-" . $boutiqueTitle . "'><div id='marker-img'></div><div id='sector'>" . str_replace(array('"', 'è'), array('\"', 'È'), preg_replace('/[\n\r]/', '', strtoupper(strip_tags($sectorName)))) . "</div><h2>". $boutiqueTitle . "</h2><a target='_parent' href='". $aliasUrl . "'><img src='" . $imgUrl . "'></img></a><div id='business-details'>". str_replace('"', '\"', preg_replace('/[\n\r]/', '<br>', $hoursMarkup)) . "</div></div>");


        if (!empty($entity['field_store_type'])) {
            $storeTypes = array();
            foreach ($entity['field_store_type'] as $storeType) {
                $typeQ = db_query('SELECT name FROM taxonomy_term_field_data WHERE tid = :tid', array(
                    ':tid' => $storeType['target_id']
                ))->fetchField();
                if (strlen($typeQ) > 0) {
                    $storeTypes[] = $typeQ;
                }
            }
            if (count($storeTypes) > 0) {
                $sTypes = '"storetypes":"';
                foreach ($storeTypes as $tag) {
                    $sTypes .= $tag . ',';
                }
                $sTypes = rtrim($sTypes, ',');
                $sTypes .= '",';
            }
        }

        $boutiqueGeoJson .= '{"type":"Feature",';
        $boutiqueGeoJson .= '"id":"way/' . $i . '",';
        $boutiqueGeoJson .= '"properties":{';
//        if (!empty($entity['field_levels'])) {
        if (!empty($entity['title'])) {
            $boutiqueGeoJson .= '"name":"' . trim($entity['title'][0]['value']) . '",';
        }
        if ($nid != null && strlen($nid) > 0) {
          $boutiqueGeoJson .= '"nid":"' . $nid . '",';
        }
        if (!empty($entity['field_zone_code']) && !empty($entity['field_levels'])) {
            $boutiqueGeoJson .= '"level":"' . trim($entity['field_levels'][0]['value']) . '",';
        } else {
            $boutiqueGeoJson .= '"level":"1",';
        }
//        if (!empty($entity['field_boutique_address'])) {
//            $boutiqueAddress = trim($entity['field_boutique_address'][0]['value']);
//            $boutiqueGeoJson .= '"addr":"'. $boutiqueAddress . '",';
//            $description .= "<div class='boutique-info-address'><img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_mappointer-b.svg' alt='icon'><span>". $boutiqueAddress . "</span></div>";
//        }
        if (!empty($entity['field_boutique_phone_number'])) {
            $phoneNum = trim($entity['field_boutique_phone_number'][0]['value']);
            $boutiqueGeoJson .= '"phone":"' . $phoneNum . '",';
            //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-phone.svg' alt='icon'>
            $description .= "<div class='boutique-info-phone'><span>". $phoneNum . "</span></div>";
        }
        if (!empty($entity['field_boutique_website'])) {
            $website = trim($entity['field_boutique_website'][0]['value']);
            $boutiqueGeoJson .= '"website":"' . $website . '",';
            //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-cursor.svg' alt='icon'>
            $description .= "<div class='boutique-info-website'><a target='_parent' href='". $website . "'>" . $website . "</a></div>";
        }
        if ($aliasUrl) {
            $description .= "<div class='boutique-view-full'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>View full listing →</a></div></div>";
        }
        //This includes a logo property
//        if ($imgUrl) {
//            $boutiqueGeoJson .= '"logo":"' . $imgUrl .'",';
//        }
        if (!empty($entity['field_boutique_events'])) {
            $boutiqueGeoJson .= '"event":"true",';
            //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_calendar-w.svg' alt='icon'>
            $description .= "<div id='event-before'></div><div class='event'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>Event happening now →</a></div></div>";
        }
        if ($sTypes) {
            $boutiqueGeoJson .= $sTypes;
        }
        if ($description) {
            $boutiqueGeoJson .= '"description":"' . $description . '"';
        }
        if (!empty($entity['field_zone_code'])) {
            $zQuery = array_values(\Drupal::entityQuery('node')
                ->condition('status', 1)
                ->condition('type', 'zone')
                ->condition('field_zone_code', $entity['field_zone_code'][0])
                ->execute());
            if (count($zQuery) > 0) {
                $tQuery = db_query("SELECT name FROM taxonomy_term_field_data WHERE tid = :tid", array(
                    ':tid' => $entity['field_zone_code'][0]['target_id']
                ))
                    ->fetchField();

                if (strlen($tQuery) > 0) {
                    $zoneEntity = entity_load('node', $zQuery[0])->toArray();
                    if ($zoneEntity != null) {
                        $sectorQuery = db_query("SELECT field_sector_code_target_id FROM node__field_sector_code 
                                                     WHERE bundle = :bundle AND entity_id = :nid", array(
                            ':bundle' => 'zone',
                            ':nid' => $zoneEntity['nid'][0]['value'],
                        ))->fetchField();

                        if (strlen($sectorQuery) > 0) {
                            $sectorTaxVerify = array_values(\Drupal::entityQuery('taxonomy_term')
                                ->condition('vid', 'sector')
                                ->condition('tid', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
                                ->execute());

                            if (count($sectorTaxVerify) > 0) {
                                $sectorEntityQuery = db_query("SELECT entity_id FROM node__field_sector_code 
                                                     WHERE bundle = :bundle AND field_sector_code_target_id = :tid", array(
                                    ':bundle' => 'sector',
                                    ':tid' => is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery,
                                ))->fetchField();

                                if (!empty($sectorEntityQuery)) {
                                    $sectorEntity = entity_load('node', is_array($sectorEntityQuery) ? $sectorEntityQuery[0] : $sectorEntityQuery)->toArray();
                                    if (null != $sectorEntity && !empty($sectorEntity['field_zone_colour'])) {
                                        $boutiqueGeoJson .= ',';
                                        $boutiqueGeoJson .= '"colour":"' . $sectorEntity['field_zone_colour'][0]['value'] . '"}';
                                    } else {
                                        $boutiqueGeoJson .= ',';
                                        $boutiqueGeoJson .= '"colour":"' . '#000000' . '"}';
                                    }
                                }
                            }
                        }

                        if (!empty($zoneEntity['field_feature_data'])) {
                            $boutiqueGeoJson .= ',';
                            $boutiqueGeoJson .= '"geometry":' . $zoneEntity['field_feature_data'][0]['value'];
                        } else {
                            //Purposely don't set the geometry property so we can choose the default camera view in its absence
                            $boutiqueGeoJson .= ',';
                            $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
                        }
                    }
                }
            }
        } else {
            $boutiqueGeoJson .= '},';
            $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
        }

//            $boutiqueGeoJson .= '},';
//            $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
        $boutiqueGeoJson .= $i == ($count -1) ? '}' : '},';
    }
    $boutiqueGeoJson .= ']}';
//    print '<pre>'; print_r($boutiqueGeoJson); print '</pre>';
    $file = file_save_data($boutiqueGeoJson, "public://geojson/quartier_en.json", FILE_EXISTS_REPLACE);

    if ($file != false) {
        return $file->id();
    } else {
        return false;
    }
}


function boutique_data_rebuild_json_fr() {
    setlocale(LC_TIME, "fr_FR");

    $boutiqueGeoJson = '{"type":"FeatureCollection","generator":"overpass-turbo","copyright":"The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.","timestamp":"2016-09-12T19:22:48Z","features":[';
    $query = \Drupal::entityQuery('node')
        ->condition('status', 1)
        ->condition('langcode', 'fr')
        ->condition('type', 'boutique');
    $result = array_values($query->execute());
    $count = count($result);
    for ($i = 0; $i < $count; $i++) {
        $entity = entity_load('node', $result[$i])->toArray();
        $sectorName = '';
        if (!empty($entity['field_zone_code'])) {
            $zEntityQuery = \Drupal::entityQuery('node')
                ->condition('type', 'zone')
                ->condition('field_zone_code', $entity['field_zone_code'][0])
                ->condition('status', 1)->execute();
            if (count($zEntityQuery) > 0) {
                $mZone = entity_load('node', array_values($zEntityQuery)[0])->toArray();
                if (count($mZone) > 0) {
                    $sectorName = trim(str_replace('&nbsp;', ' ', (db_query('SELECT description__value FROM taxonomy_term_field_data WHERE tid = :tid', array(
                        ':tid' => $mZone['field_sector_code'][0]['target_id']
                    ))->fetchField())));
                }
            }
        }
        $nid = $entity['nid'][0]['value'];
        $rawUrl = '/node/' . $entity['nid'][0]['value'];
        $aliasUrl = db_query('SELECT alias FROM url_alias WHERE source = :source', array(':source' => $rawUrl))->fetchField();
        $sTypes = null;
        if (!empty($entity['field_boutique_logo'])) {
            $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => $entity['field_boutique_logo'][0]['target_id']))->fetchField());
        } else {
            $imgUrl = str_replace('public://', '/sites/quartierdix30/files/', db_query("SELECT uri FROM file_managed WHERE fid = :fid", array(':fid' => 105))->fetchField());
        }
        $aliasUrl = !$aliasUrl ? $rawUrl : $aliasUrl;
        $hoursMarkup = '<div class="boutique-map-hours">';
        $todayFound = false;
        $todayHours = '<p class="hours-day"><span>Ouvert aujourd\'hui</span>';

        if (!empty($entity['field_boutique_hours'])) {
            $daysArrayEn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
            $daysArray = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');

            $today = date('l');

            //ICON REMOVED => <img class="icon" src="/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-hours.svg" alt="Icon of a clock to display with the hours">
            foreach ($entity['field_boutique_hours'] as $day) {

                if ($today == $daysArrayEn[$day['day']]) {
                    $todayHours .= '<span>' . $day['starthours'] . ' à ' . $day['endhours'] . '</span></p>';
                    $todayFound = true;
                }
            }
        }

        $boutiqueTitle = isset($entity['title'][0]['value']) ? $entity['title'][0]['value'] : 'QD30' . $i;

        if (!$todayFound) {
            $todayHours = '<p class="hours-day"><span>Fermé aujourd\'hui</span></p>';
        }
        $hoursMarkup .= $todayHours;

        $description = trim("<div class='boutique-infobox' id='boutique-" . $boutiqueTitle . "'><div id='marker-img'></div><div id='sector'>" . str_replace(array('"', 'è'), array('\"', 'È'), preg_replace('/[\n\r]/', '', strtoupper(strip_tags($sectorName)))) . "</div><h2>". $boutiqueTitle . "</h2><a target='_parent' href='". $aliasUrl . "'><img src='" . $imgUrl . "'></img></a><div id='business-details'>". str_replace('"', '\"', preg_replace('/[\n\r]/', '<br>', $hoursMarkup)) . "</div></div>");

        if (!empty($entity['field_store_type'])) {
            $storeTypes = array();
            foreach ($entity['field_store_type'] as $storeType) {
                $typeQ = db_query('SELECT name FROM taxonomy_term_field_data WHERE tid = :tid', array(
                    ':tid' => $storeType['target_id']
                ))->fetchField();
                if (strlen($typeQ) > 0) {
                    $storeTypes[] = $typeQ;
                }
            }
            if (count($storeTypes) > 0) {
                $sTypes = '"storetypes":"';
                foreach ($storeTypes as $tag) {
                    $sTypes .= $tag . ',';
                }
                $sTypes = rtrim($sTypes, ',');
                $sTypes .= '",';
            }
        }

        $boutiqueGeoJson .= '{"type":"Feature",';
        $boutiqueGeoJson .= '"id":"way/' . $i . '",';
        $boutiqueGeoJson .= '"properties":{';
//        if (!empty($entity['field_levels'])) {
        if (!empty($entity['title'])) {
            $boutiqueGeoJson .= '"name":"' . trim($entity['title'][0]['value']) . '",';
        }
      if ($nid != null && strlen($nid) > 0) {
        $boutiqueGeoJson .= '"nid":"' . $nid . '",';
      }

      if (!empty($entity['field_zone_code']) && !empty($entity['field_levels'])) {
            $boutiqueGeoJson .= '"level":"' . trim($entity['field_levels'][0]['value']) . '",';
        } else {
            $boutiqueGeoJson .= '"level":"1",';
        }
//        if (!empty($entity['field_boutique_address'])) {
//            $boutiqueAddress = trim($entity['field_boutique_address'][0]['value']);
//            $boutiqueGeoJson .= '"addr":"'. $boutiqueAddress . '",';
//            $description .= "<div class='boutique-info-address'><img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_mappointer-b.svg' alt='icon'><span>". $boutiqueAddress . "</span></div>";
//        }
        if (!empty($entity['field_boutique_phone_number'])) {
            $phoneNum = trim($entity['field_boutique_phone_number'][0]['value']);
            $boutiqueGeoJson .= '"phone":"' . $phoneNum . '",';
            //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-phone.svg' alt='icon'>
            $description .= "<div class='boutique-info-phone'><span>". $phoneNum . "</span></div>";
        }
        if (!empty($entity['field_boutique_website'])) {
            $website = trim($entity['field_boutique_website'][0]['value']);
            $boutiqueGeoJson .= '"website":"' . $website . '",';
            //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/themes/quartierdix30/images/icons/icon_b-cursor.svg' alt='icon'>
            $description .= "<div class='boutique-info-website'><a target='_parent' href='". $website . "'>" . $website . "</a></div>";
        }
        if ($aliasUrl) {
            $description .= "<div class='boutique-view-full'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>View full listing →</a></div></div>";
        }
        if ($imgUrl) {
            $boutiqueGeoJson .= '"logo":"' . $imgUrl .'",';
        }
        if (!empty($entity['field_boutique_events'])) {
            $boutiqueGeoJson .= '"event":"true",';
            //ICON REMOVED => <img class='icon' src='/sites/quartierdix30/modules/custom/qd30map/gfx/icon_calendar-w.svg' alt='icon'>
            $description .= "<div class='event'><div class='readmore'><a target='_parent' href='". $aliasUrl . "'>Event happening now →</a></div></div>";
        }
        if ($sTypes) {
            $boutiqueGeoJson .= $sTypes;
        }
        if ($description) {
            $boutiqueGeoJson .= '"description":"' . $description . '"';
        }
        if (!empty($entity['field_zone_code'])) {
            $zQuery = array_values(\Drupal::entityQuery('node')
                ->condition('status', 1)
                ->condition('type', 'zone')
                ->condition('field_zone_code', $entity['field_zone_code'][0])
                ->execute());
            if (count($zQuery) > 0) {
                $tQuery = db_query("SELECT name FROM taxonomy_term_field_data WHERE tid = :tid", array(
                    ':tid' => $entity['field_zone_code'][0]['target_id']
                ))
                    ->fetchField();

                if (strlen($tQuery) > 0) {
                    $zoneEntity = entity_load('node', $zQuery[0])->toArray();
                    if ($zoneEntity != null) {
                        $sectorQuery = db_query("SELECT field_sector_code_target_id FROM node__field_sector_code 
                                                     WHERE bundle = :bundle AND entity_id = :nid", array(
                            ':bundle' => 'zone',
                            ':nid' => $zoneEntity['nid'][0]['value'],
                        ))->fetchField();
                        if (strlen($sectorQuery) > 0) {
                            $sectorTaxVerify = array_values(\Drupal::entityQuery('taxonomy_term')
                                ->condition('vid', 'sector')
                                ->condition('tid', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
                                ->execute());
                            $test = 'test';
                            if (count($sectorTaxVerify) > 0) {
                                $sectorEntityQuery = db_query("SELECT entity_id FROM node__field_sector_code 
                                                     WHERE bundle = :bundle AND field_sector_code_target_id = :tid", array(
                                    ':bundle' => 'sector',
                                    ':tid' => is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery,
                                ))->fetchField();
//                                $sectorEntityQuery = \Drupal::entityQuery('node')
//                                    ->condition('type', 'sector')
//                                    ->condition('field_sector_code', is_array($sectorQuery) ? $sectorQuery[0] : $sectorQuery)
//                                    ->execute();
                                if (!empty($sectorEntityQuery)) {
                                    $sectorEntity = entity_load('node', is_array($sectorEntityQuery) ? $sectorEntityQuery[0] : $sectorEntityQuery)->toArray();
                                    if (null != $sectorEntity && !empty($sectorEntity['field_zone_colour'])) {
                                        $boutiqueGeoJson .= ',';
                                        $boutiqueGeoJson .= '"colour":"' . $sectorEntity['field_zone_colour'][0]['value'] . '"}';
                                    } else {
                                        $boutiqueGeoJson .= ',';
                                        $boutiqueGeoJson .= '"colour":"' . '#000000' . '"}';
                                    }
                                }
                            }
                        }
                        if (!empty($zoneEntity['field_feature_data'])) {
                            $boutiqueGeoJson .= ',';
                            $boutiqueGeoJson .= '"geometry":' . $zoneEntity['field_feature_data'][0]['value'];
                        } else {
                            //Purposely don't set the geometry property so we can choose the default camera view in its absence
                            $boutiqueGeoJson .= ',';
                            $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
                        }
                    }
                }
            }
        } else {
            $boutiqueGeoJson .= '},';
            $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
        }

//            $boutiqueGeoJson .= '},';
//            $boutiqueGeoJson .= '"geometry":' . '{"type":"Polygon","coordinates":[[[1,1]]]}';
        $boutiqueGeoJson .= $i == ($count -1) ? '}' : '},';
    }
    $boutiqueGeoJson .= ']}';
//    print '<pre>'; print_r($boutiqueGeoJson); print '</pre>';
    $file = file_save_data($boutiqueGeoJson, "public://geojson/quartier_fr.json", FILE_EXISTS_REPLACE);

    if ($file != false) {
        return $file->id();
    } else {
        return false;
    }
}


function boutique_data_node_clear()  {
    $nodeTest = null;
//
//    $NboutiqueNode = Drupal\node\Entity\Node::load(216);
//    $MboutiqueNode = \Drupal::entityTypeManager()->getStorage('node')->load(216);
//    $EboutiqueNode = entity_load('node', 216);

    $nResult = \Drupal::entityQuery('node')
        ->condition('type', 'zone')
        ->execute();
    $delAttempt = entity_delete_multiple('node', $nResult);

    $tResult = \Drupal::entityQuery('taxonomy_term')
        ->condition('vid', 'zone')
        ->execute();
    $delAttempt = entity_delete_multiple('taxonomy_term', $tResult);


    $myvar = 'variability';

    return $delAttempt;
}

function boutique_data_boutique_levels_update() {
//    $bEntities = \Drupal::entityQuery('node')
//        ->condition('type', 'boutique')
//        ->condition('status', 1)
//        ->execute();
    $bEntities = db_query('SELECT nid FROM node_field_data WHERE type = :type AND status = :status AND nid > :min', array(
        ':type' => 'boutique',
        ':status' => 1,
        ':min' => 212,
    ));

    foreach ($bEntities as $nid) {
        $node = Node::load($nid->nid);
        $node->field_levels = 1;
        $node->save();
    }
}
